[Trigger] Specific Unit Event help

Status
Not open for further replies.
Level 1
Joined
Apr 12, 2020
Messages
3
I've registered EVENT_UNIT_SELECTED on the trigger, and how to get the selecting/clicking player? I've already known that GetTrigerredUnit() to get the selected unit. I've tried GetTriggerPlayer() but the result is not right...

Here is the code
vJASS:
function myaction takes nothing returns nothing
    unit u = GetTriggerUnit()
    player p = GetTriggerPlayer() // WRONG!!!
    ...
end
function trigger takes nothing returns nothing
    trigger t = CreateTrigger()
    unit u = CreateUnit(...)
    call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_SELECTED )
    call TriggerAddAction(t, function myaction)
    set t = null
end
 
Last edited:
It's like @SinisterLuffy said, GetTriggerPlayer() works for playerunitevent, but not for unitevent.
JASS:
type playerunitevent   extends    eventid
type unitevent         extends    eventid
And the used event is of the type unitevent:
JASS:
constant unitevent EVENT_UNIT_SELECTED                             = ConvertUnitEvent(57)
And the "A unit starts the effect of an ability" is of type playerunitevent, that's why GetTriggerPlayer() works there.
JASS:
constant playerunitevent   EVENT_PLAYER_UNIT_SPELL_EFFECT         = ConvertPlayerUnitEvent(274)
There's an alternative, though not specifically for one unit. But there, GetTriggerPlayer() and GetTriggerUnit(), both work.
JASS:
call TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_DESELECTED, null)
 
Last edited:
Level 1
Joined
Apr 12, 2020
Messages
3
It's like @SinisterLuffy said, GetTriggerPlayer() works for playerunitevent, but not for unitevent.
JASS:
type playerunitevent   extends    eventid
type unitevent         extends    eventid
And the used event is of the type unitevent:
JASS:
constant unitevent EVENT_UNIT_SELECTED                             = ConvertUnitEvent(57)
And the "A unit starts the effect of an ability" is of type playerunitevent, that's why GetTriggerPlayer() works there.
JASS:
constant playerunitevent   EVENT_PLAYER_UNIT_SPELL_EFFECT         = ConvertPlayerUnitEvent(274)
There's an alternative, though not specifically for one unit. But there, GetTriggerPlayer() and GetTriggerUnit(), both work.
JASS:
call TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_DESELECTED, null)
Thank you very much, I've changed my code to this.
 
Status
Not open for further replies.
Top