• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Revive trigger action run multiple times

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
once happened with me similiar with level up trigger or what, there if i moved everything to action function then worked well, else in cindition function it was ran multiple times

now the respawn, reiving trigger do same but the action part and i dont know why

JASS:
function Revive_and_Respawn takes nothing returns nothing
    local unit du = GetDyingUnit()
    local unit ku = GetKillingUnit()
    local integer dutype = GetUnitTypeId(du)
    local integer dLv
    local real x = GetUnitX(du)
    local real y = GetUnitY(du)
    local real ang = GetUnitFacing(du)
    local player pd = GetOwningPlayer(du)
    local player pk = GetOwningPlayer(ku)
    local integer pld = GetPlayerId(pd) + 1
    local integer plk = GetPlayerId(pk) + 1
    local integer cvd = GetUnitUserData(du)
    local integer cvk = GetUnitUserData(ku)
    local integer exp
    local integer boss = 0
    local timer t
    set udg_CombatTimer[cvd] = 1
    if GetPlayerController(pd) == MAP_CONTROL_USER then
       call DisplayTextToPlayer(Player(0), 0, 0, "debug 1."+GetUnitName(du)+R2S(GetWidgetLife(du)))
        if IsUnitType(du, UNIT_TYPE_HERO) then
            //if udg_Inv_Unit[pld] == cvd then
            //    if udg_Camera_Lock[pld] > 0 then
            //        call WindowTransition (pld, udg_Camera_Lock[pld], 0)
            //    endif
            //endif
            set t = CreateTimer()
            call SaveUnitHandle(udg_Stat_Table, 8991, GetHandleId(t), du)
            call TimerStart(t,5, false, function Revive_Hero) //here was wait, i changed to timer coz i thought that the problem but no
            set t = null
        endif
    else
    //get the dying unit lv
        if not IsUnitType(du, UNIT_TYPE_HERO) then
            set dLv = GetUnitLevel(du)
        else
            set dLv = GetHeroLevel(du)
            set boss = 1
        endif
    //add exp
        if ku == udg_Hero[plk] then
            set exp = R2I((udg_Global_Exp[cvd] * ((100.00 + udg_Stat_Exp[cvk]) / 100.00)))
            call SuspendHeroXP(ku, false)
            call AddHeroXP(ku, exp, true)
            call SuspendHeroXP(ku, true)
            call FT_Ex (pk, pk, "+" + I2S(exp) + " exp", 2, du, 13, 0, 0, 255, 255, 90)
            if udg_Global_Hp4Kill[cvk] > 0 then
                call SetWidgetLife(ku, GetWidgetLife(ku) + udg_Global_Hp4Kill[cvk])
            endif
            if udg_Global_Mp4Kill[cvk] > 0 then
                call SetUnitState(ku, UNIT_STATE_MANA, GetUnitState(ku, UNIT_STATE_MANA) + udg_Global_Mp4Kill[cvk])
            endif
        endif
        if not IsUnitType(du, UNIT_TYPE_SUMMONED) then
            call CreateDrop(du, ku)
            call TriggerSleepAction(10)

            if boss == 0 then
                call RemoveUnit(du)
                call CreateUnit(pd, dutype, LoadReal(udg_Stat_Table, 9999, cvd), LoadReal(udg_Stat_Table, 9998, cvd), bj_RADTODEG * LoadReal(udg_Stat_Table, 9997, cvd))
            else
                call ReviveHero(du, LoadReal(udg_Stat_Table, 9999, cvd), LoadReal(udg_Stat_Table, 9998, cvd), false)
                call SetHeroLevel(du, LoadInteger(udg_Stat_Table, 9996, cvd), true)
            endif
        endif
    endif
    call TriggerSleepAction(1) //if this 1 second then debug msg appear every sec, if this wait removed then every second appear the msg even unit already revived
                                    //sometimes revive faster than needed and on old position
    set du = null
    set ku = null
    set pd = null
    set pk = null
endfunction

//===========================================================================
function InitTrig_Revive_Respawn_Drop takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
        call TriggerAddAction( t, function Revive_and_Respawn )
        set i = i + 1
        exitwhen i == 15
    endloop
    set t = null
endfunction
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
with neutral hostile work well so i made few changes

JASS:
function Revive_Hero takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local unit u = LoadUnitHandle(udg_Stat_Table, 8991, id)
    local player p = GetOwningPlayer(u)
    local integer pl = GetPlayerId(p) + 1
    local integer cv = GetUnitUserData(u)
    local integer w
    call RemoveSavedHandle(udg_Stat_Table, 8991, id)
    call ReviveHero(u, GetUnitX(u), GetUnitY(u), true)
    // we select the hero after he revived
    if GetLocalPlayer() == p then
        call ClearSelection()
        call SelectUnit(u, true)
    endif
        //--------------------------- here we must change to ranged if our hero was ranged before he died
    if LoadBoolean(udg_FSS, 631, GetUnitTypeId(u)) then
        set w = LoadInteger(udg_CItem_Table, GetHandleId(LoadItemHandle(udg_Stat_Table, cv, 3)), 3)
        if ( w==6 ) then
            if ( GetUnitTypeId( u ) == HERO_MELEE() ) then
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), true )
                call IssueImmediateOrder( u, "metamorphosis" )
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), false )
            endif
        else
            if ( GetUnitTypeId( u ) == HERO_RANGED() ) then
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), true )
                call IssueImmediateOrder( u, "metamorphosis" )
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), false )
            endif
        endif
    endif
    set udg_Revive[cv] = false
    call PauseTimer(t)
    call DestroyTimer(t)
    set p = null
    set u = null
    set t = null
endfunction

function Revive_and_Respawn takes nothing returns nothing
    local unit du = GetDyingUnit()
    local unit ku = GetKillingUnit()
    local integer dutype = GetUnitTypeId(du)
    local integer dLv
    local real x = GetUnitX(du)
    local real y = GetUnitY(du)
    local real ang = GetUnitFacing(du)
    local player pd = GetOwningPlayer(du)
    local player pk = GetOwningPlayer(ku)
    local integer pld = GetPlayerId(pd) + 1
    local integer plk = GetPlayerId(pk) + 1
    local integer cvd = GetUnitUserData(du)
    local integer cvk = GetUnitUserData(ku)
    local integer exp
    local integer boss = 0
    local timer t
    set udg_CombatTimer[cvd] = 1
    if GetPlayerController(pd) == MAP_CONTROL_USER then
        call DisplayTextToPlayer(Player(0), 0, 0, "debug 1." + GetUnitName(du) + R2S(GetWidgetLife(du))) 
        //multiple times write out the debug 1=>trigger run around 15x, after death for few sec
        if IsUnitType(du, UNIT_TYPE_HERO) and not udg_Revive[cvd] then
        call DisplayTextToPlayer(Player(0), 0, 0, "debug 2." + GetUnitName(du) + R2S(GetWidgetLife(du))) 
         //appear only 1x and could be a solution but real solution if this trigger not executed more than 1x /user hero death

            set udg_Revive[cvd] = true
            if udg_Inv_Unit[pld] == cvd then
                if udg_Camera_Lock[pld] > 0 then
                    call WindowTransition (pld, udg_Camera_Lock[pld], 0)
                endif
            endif
            set t = CreateTimer()
            call SaveUnitHandle(udg_Stat_Table, 8991, GetHandleId(t), du)
            call TimerStart(t, 5, false, function Revive_Hero)
            set t = null
        endif
    else
            //blabla we dont care about this because in my case this dont running
    endif
    //call TriggerSleepAction(1)
    set du = null
    set ku = null
    set pd = null
    set pk = null
endfunction

//===========================================================================
function InitTrig_Revive_Respawn_Drop takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
        call TriggerAddAction( t, function Revive_and_Respawn )
        set i = i + 1
        exitwhen i == 15
    endloop
        call DisplayTextToPlayer(Player(0), 0, 0, "debug 3") 
       //this displaytext run 1x, so here ok
    set t = null
endfunction
 
Status
Not open for further replies.
Top