HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Desync?

12-13-2008, 12:20 AM#1
Fledermaus
Ok in my map people will occasionally drop when they should be reviving (timer expires). I can't see anything in the code that could be causing a desync so I'm coming here in the hope that someone will spot something I've missed.

Collapse JASS:
scope HeroRevive

private function DeathConditions takes nothing returns boolean
    return GetTriggerUnit()==udg_Hero[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))]
endfunction

private function ForceConditions takes nothing returns boolean
    return IsUnitType(udg_Hero[GetPlayerId(GetTriggerPlayer())], UNIT_TYPE_DEAD) and GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER)>=3 and TimerGetRemaining(ReviveTimer[GetPlayerId(GetTriggerPlayer())])==0
endfunction

private function Revive takes nothing returns nothing
    local integer p=0
    local unit hero
    local unit corpse
    local real x
    local real y
    loop
      exitwhen GetExpiredTimer()==ReviveTimer[p]
        set p=p+1
    endloop
    set hero=udg_Hero[p]
    set corpse=udg_HeroCorpse[p]
    if IsUnitType(hero, UNIT_TYPE_DEAD) and GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER)>=3 then
        call ShowUnit(corpse, false)
        call SetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER)-3)
        call ShowUnit(hero, true)
        set x=GetRectCenterX(BindStoneRect[BindStoneInt[p]])
        set y=GetRectCenterY(BindStoneRect[BindStoneInt[p]])
        call ReviveHero(hero, x, y, true)
        call SetUnitAcquireRange(hero, 275)
        call TimerDialogDisplay(ReviveWindow[p], false)
        if GetLocalPlayer()==Player(p) then
            call ClearSelection()
            call SelectUnit(hero, true)
            call SetCameraPosition(x, y)
        endif
        if DeathForm[p]==1 then
            call UnitAddItemById(hero, 'rhe3')
        elseif DeathForm[p]==2 then
            call UnitAddItemById(hero, 'rre2')
        elseif DeathForm[p]==3 then
            call UnitAddItemById(hero, 'gfor')
        endif
    endif
    call PauseTimer(ReviveTimer[p])
    set hero=null
    set corpse=null
endfunction

private function DeathActions takes nothing returns nothing
    local unit hero=GetDyingUnit()
    local integer p=GetPlayerId(GetOwningPlayer(hero))
    local unit corpse=udg_HeroCorpse[p]
    local real x=GetUnitX(hero)
    local real y=GetUnitY(hero)
    call ShowUnit(hero, false)
    call SetUnitPosition(corpse, x, y)
    call SetUnitFacing(corpse, GetUnitFacing(hero))
    call SetUnitAnimation(corpse, "death")
    call ShowUnit(corpse, true)
    call TimerStart(ReviveTimer[p], 45, false, function Revive)
    call TimerDialogDisplay(ReviveWindow[p], GetLocalPlayer()==Player(p))
    if GetUnitTypeId(hero)=='Eidm' then
        set DeathForm[p]=1
    elseif GetUnitTypeId(hero)=='Eilm' then
        set DeathForm[p]=2
    elseif GetUnitTypeId(hero)=='Edmm' then
        set DeathForm[p]=3
    else
        set DeathForm[p]=0
    endif
    set hero=null
    set corpse=null
endfunction

private function ForceActions takes nothing returns nothing
    local integer p=GetPlayerId(GetTriggerPlayer())
    local unit hero=udg_Hero[p]
    local unit corpse=udg_HeroCorpse[p]
    local real x=GetRectCenterX(BindStoneRect[BindStoneInt[p]])
    local real y=GetRectCenterY(BindStoneRect[BindStoneInt[p]])
    call ShowUnit(corpse, false)
    call SetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER)-3)
    call ShowUnit(hero, true)
    call ReviveHero(hero, x, y, true)
    call SetUnitAcquireRange(hero, 275)
    call TimerDialogDisplay(ReviveWindow[p], false)
    if GetLocalPlayer()==GetOwningPlayer(hero) then
        call ClearSelection()
        call SelectUnit(hero, true)
        call SetCameraPosition(x, y)
    endif
    if DeathForm[p]==1 then
        call UnitAddItemById(hero, 'rhe3')
    elseif DeathForm[p]==2 then
        call UnitAddItemById(hero, 'rre2')
    elseif DeathForm[p]==3 then
        call UnitAddItemById(hero, 'gfor')
    endif
    set hero=null
    set corpse=null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig=CreateTrigger()
    call TriggerRegisterAnyUnitEvent(trig, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(trig, Condition(function DeathConditions))
    call TriggerAddAction(trig, function DeathActions)
    
    set trig=CreateTrigger()
    call TriggerRegisterAnyPlayerChatEvent(trig, "-revive", true)
    call TriggerAddCondition(trig, Condition(function ForceConditions))
    call TriggerAddAction(trig, function ForceActions)
endfunction

endscope

Here's the setting of some of the variables at map init
Collapse JASS:
    set i=0
    loop
      exitwhen i==8
        if GetPlayerSlotState(Player(i))==PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i))==MAP_CONTROL_USER then
            set Locked[i]=true
            set Rotate[i]=true
            set ControlableAoA[i]=340
            set ControlableRot[i]=0
            set Hunger[i]=0
            set DeathForm[i]=0
            set ReviveTimer[i]=CreateTimer()
            set ReviveWindow[i]=CreateTimerDialog(ReviveTimer[i])
            set BindStoneInt[i]=0
            call TimerDialogSetTitle(ReviveWindow[i], "Revive in")
            call SetPlayerHandicapXP(Player(i), 0.00)
            if GetLocalPlayer()==Player(i) then
                call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
            endif
            call ForceAddPlayer(udg_Humans, Player(i))
        endif
        set i=i+1
    endloop
12-13-2008, 01:59 AM#2
Ammorth
Try commenting out actions in the GetLocalPlayer() blocks within your revive function, until the bug stops happening. All the actions "look" safe, but sometimes you never know.