Warcraft III resources & community, 2003–2006 · archived

WaitForPlayerEvent

not rated
Submitted by PepparExecution0 downloads
Waits for the given event to occur to whichPlayerOrForce (you can pass a player or a force, if you pass a force the function will wait until the given event occurs to *any* player in the group), checking with the specified interval. The condition can be used to supply extra checking. Pass null as condition if you don't wish to have any.

This funcition doesn't work with EVENT_PLAYER_CHAT, it is unclear whether it works with EVENT_PLAYER_STATE_LIMIT and EVENT_PLAYER_ALLIANCE_CHANGED.

Source

function WaitForPlayerEvent_H2P takes handle h returns player
    return h
endfunction

function WaitForPlayerEvent_H2F takes handle h returns force
    return h
endfunction

function WaitForPlayerEvent_PE2I takes playerevent p returns integer
    if true then
        return p
    endif
    return 0
endfunction

function WaitForPlayerEvent_Enum takes nothing returns nothing
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, GetEnumPlayer(), ConvertPlayerEvent(bj_forceCountPlayers))
endfunction

function WaitForPlayerEvent takes handle whichForceOrPlayer, playerevent whichPlayerEvent, boolexpr condition, real interval returns nothing
    local trigger bj_temp = bj_delayedSuspendDecayTrig
    local trigger t
    local triggercondition c
    local player whichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
    local force whichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
    if whichForceOrPlayer == null or whichPlayerEvent == null then
        set whichForce = null
        return
    elseif interval < 0 then
        set interval = 0
    endif
    set t = CreateTrigger()
    set bj_delayedSuspendDecayTrig = t
    set bj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
    call ForForce(whichForce, function WaitForPlayerEvent_Enum)
    call TriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
    if condition != null then
        set c = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
    endif
    set bj_delayedSuspendDecayTrig = bj_temp
    loop
        call TriggerSleepAction(interval)
        exitwhen GetTriggerExecCount(t) != 0
    endloop
    if condition != null then
        call TriggerRemoveCondition(t, c)
        set c = null
    endif
    call DestroyTrigger(t)
    set t = null
    set whichForce = null
endfunction

Comments

0

No comments.