help with desync problems in my map

waaaks!

Zinctified
Reaction score
255
Hello, I'm having problems with players disconnecting (desync) in my map in some weird situations, especially now, in which I attempted to create all the triggers in my map using jass. I really need someone to help me search codes that causes desync. I can't post all the codes here, because 90% of my systems are already coded, and looks like 10% of it causes desync. I will just send the open map VIA Pm.

Ok, I'll just post some of my triggers that uses GetLocalPlayer()
JASS:
scope KillsUI initializer init

    globals
        private integer array streak
        private string array title
        private boolean fb = false
        private sound array killSound
    endglobals
    
    private function initSounds takes nothing returns nothing
        set killSound[0] = gg_snd_firstblood
        set killSound[1] = gg_snd_Killing_Spree
        set killSound[2] = gg_snd_Dominating
        set killSound[3] = gg_snd_MegaKill
        set killSound[4] = gg_snd_Unstoppable
        set killSound[5] = gg_snd_WhickedSick
        set killSound[6] = gg_snd_MonsterKill
        set killSound[7] = gg_snd_GodLike
        set killSound[8] = gg_snd_HolyShit
    endfunction
    
    private function initTitle takes nothing returns nothing
        set title[1] = ""
        set title[2] = ""
        set title[3] = "|cff80ff00Killing Spree|r"
        set title[4] = "|cff0135e7Dominating|r"
        set title[5] = "|cffff00ffMega Kill|r"
        set title[6] = "|cffff8000Unstoppable|r"
        set title[7] = "|cff808000Wicked Sick|r"
        set title[8] = "|cffff80ffMonster Kill|r"
        set title[9] = "|cffff0000GODLIKE!|r"
        set title[10] = "|cffff8040beyond GODLIKE!|r"
    endfunction

    private function con takes nothing returns boolean
        return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) and not IsUnitIllusion(GetTriggerUnit())
    endfunction
    
    private function act takes nothing returns nothing
        local unit c = GetTriggerUnit()
        local unit t = GetKillingUnit()
        local string s = ""
        local group g = null
        local unit u = null
        local integer bon = 0
        call SetPlayerState(GetOwningPlayer(c),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(GetOwningPlayer(c),PLAYER_STATE_RESOURCE_LUMBER)-1)
        if ( GetOwningPlayer(t) == playerGwapo ) then
            if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                set s = PlayerColor[9] + "The Extrinsic|r has pwned " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r."
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
            endif
        elseif ( GetOwningPlayer(t) == playerPangit ) then
            if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                set s = PlayerColor[10] + "The Intrinsic|r has pwned " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r."
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
            endif
        elseif ( IsUnitType(t,UNIT_TYPE_HERO) and GetOwningPlayer(t) != GetOwningPlayer(c) and IsUnitEnemy(t,GetOwningPlayer(c)) ) then
            call SetPlayerState(GetOwningPlayer(t),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(GetOwningPlayer(t),PLAYER_STATE_RESOURCE_LUMBER)+1)
            set streak[GetPlayerId(GetOwningPlayer(t))] = streak[GetPlayerId(GetOwningPlayer(t))]+1
            set bon = 200
            if (not fb) then
                set fb = true
                set bon = 200 + 200
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r drew |cffff0000First Blood|r to " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r for an extra " + PlayerColor[12] + I2S(bon) + "|r gold."
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[0])
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 3) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 4) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 5) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 6) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 7) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 8) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 9) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            elseif (streak[GetPlayerId(GetOwningPlayer(c))] == 10) then
                set bon = 200 + (streak[GetPlayerId(GetOwningPlayer(c))] * 30)
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has ended " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r's " + title[streak[GetPlayerId(GetOwningPlayer(c))]] + " for an extra " + PlayerColor[12] + I2S(bon) + "|r gold." 
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
            endif
            if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) +"|r has pwned " + PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r for an extra " + PlayerColor[12] + I2S(bon) + "|r gold."
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
            endif
            call Bounty(GetOwningPlayer(t),bon,GetUnitX(c),GetUnitY(c))
            if (streak[GetPlayerId(GetOwningPlayer(t))] == 3) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is on " + title[streak[GetPlayerId(GetOwningPlayer(t))]]
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[1])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 4) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is " + title[streak[GetPlayerId(GetOwningPlayer(t))]]
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[2])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 5) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is on " + title[streak[GetPlayerId(GetOwningPlayer(t))]]
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[3])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 6) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is " + title[streak[GetPlayerId(GetOwningPlayer(t))]]
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[4])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 7) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is " + title[streak[GetPlayerId(GetOwningPlayer(t))]]
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[5])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 8) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is on " + title[streak[GetPlayerId(GetOwningPlayer(t))]] + ". Better kill him or else!!!"
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[6])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 9) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is " + title[streak[GetPlayerId(GetOwningPlayer(t))]] + ", someone kill him!!!"
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[7])
            elseif (streak[GetPlayerId(GetOwningPlayer(t))] == 10) then
                if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                    set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r is on " + title[streak[GetPlayerId(GetOwningPlayer(t))]] + ", omfg!!!"
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
                endif
                call PlaySoundBJ(killSound[8])
            endif
            set streak[GetPlayerId(GetOwningPlayer(c))] = 0
            set s = ""
        elseif t == c then
            if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
                set s = PlayerColor[GetPlayerId(GetOwningPlayer(t))] + GetPlayerName(GetOwningPlayer(t)) + "|r killed himself."
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 15.0, s)
            endif
        endif
        set c = null
        set t = null
        set g = null
        set u = null
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer n = 0
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(t, function act)
        call TriggerAddCondition(t, Condition(function con))
        loop
            exitwhen n > 11
            set streak[n] = 0
            set n = n + 1
        endloop
        call initTitle()
        call initSounds()
        set n = 0
    endfunction
    
endscope


JASS:
scope HeroPicked initializer init

    private function con takes nothing returns boolean
        return IsUnitType(GetSoldUnit(), UNIT_TYPE_HERO) == true
    endfunction
    
    private function act takes nothing returns nothing
        local integer n = 0
        local unit c = GetSoldUnit()
        local string s
        local group g = NewGroup()
        local unit u
        call GroupEnumUnitsInRange(g,0,0,9999999,BOOLEXPR_TRUE)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null
            if( GetUnitTypeId(u) == 'n000' and GetOwningPlayer(u) == GetOwningPlayer(c) )then
                call RemoveUnit(u)
            endif
            call GroupRemoveUnit(g,u)
        endloop
        call ReleaseGroup(g)
        set g = null
        set u = null
        loop
            exitwhen n > 11
            call SetPlayerTechMaxAllowed(Player(n), GetUnitTypeId(c), 0)
            set n = n + 1
        endloop
        set n = 0
        loop
            exitwhen n > heroMax
            call SetPlayerTechMaxAllowed(GetOwningPlayer(c),heroType[n],0)
            set n = n + 1
        endloop
        set n =0
        if( IsUnitInForce(c,teamGwapo) ) then
            call SetUnitX(c,GetRectCenterX(gg_rct_gHero))
            call SetUnitY(c,GetRectCenterY(gg_rct_gHero))
            if (GetLocalPlayer() == GetOwningPlayer(c)) then
                call ClearSelection()
                call SelectUnit(c, true)
                call PanCameraToTimed(GetRectCenterX(gg_rct_gHero), GetRectCenterY(gg_rct_gHero),0.0)
            endif
            if (IsPlayerInForce(GetLocalPlayer(), teamPangit)) then
                set s = PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r has picked " + GetUnitName(c)
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, s)
            endif
        elseif( IsUnitInForce(c,teamPangit) ) then
            call SetUnitX(c,GetRectCenterX(gg_rct_pHero))
            call SetUnitY(c,GetRectCenterY(gg_rct_pHero))
            if (GetLocalPlayer() == GetOwningPlayer(c)) then
                call ClearSelection()
                call SelectUnit(c, true)
                call PanCameraToTimed(GetRectCenterX(gg_rct_pHero), GetRectCenterY(gg_rct_pHero),0.0)
            endif
            if (IsPlayerInForce(GetLocalPlayer(), teamGwapo)) then
                set s = PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r has picked " + GetUnitName(c)
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, s)
            endif
        endif
        set c = null
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SELL )
        call TriggerAddCondition( t, Condition( function con ) )
        call TriggerAddAction( t, function act )
    endfunction

endscope


JASS:
scope INIT initializer init

    globals
        force teamGwapo = CreateForce()
        force teamPangit = CreateForce()
        player playerGwapo = Player(13) //Victim
        player playerPangit = Player(14) //Extra
        integer array heroType
        integer heroMax = 0
        integer lifeBug = 'lfbg'
    endglobals
    
    private function assignHeroes takes nothing returns nothing
        set heroType[0] = 'H006' //Helios
        set heroType[1] = 'U000' //Stuart
        set heroType[2] = 'E003' //Zerogath
        set heroType[3] = 'U006' //Hellena
        set heroType[4] = 'H009' //Bob McDonald
        set heroType[5] = 'E004' //Ether
        set heroType[6] = 'H00A' //Raven
        set heroType[7] = 'H00B' //Storm
        set heroType[8] = 'O001' //Apostrophe
        set heroMax = 8
    endfunction
    
    private function init takes nothing returns nothing
        local integer n = 0
        local trigger t = CreateTrigger()
        if (GetLocalPlayer() == Player(0)) then
            call PanCameraToTimed(0.0,0.0,0.0)
        endif
        call CameraSetSmoothingFactor(5.0)
        call SetPlayerAllianceStateBJ( playerGwapo, playerPangit, bj_ALLIANCE_UNALLIED )
        call SetPlayerAllianceStateBJ( playerPangit, playerGwapo, bj_ALLIANCE_UNALLIED )
        loop
            if( n < 6 and GetPlayerSlotState(Player(n)) == PLAYER_SLOT_STATE_PLAYING ) then
                call SetPlayerState(Player(n),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(Player(n),PLAYER_STATE_RESOURCE_GOLD)+625)
                call ForceAddPlayer(teamGwapo,Player(n))
                call CreateUnit(Player(n),'n000',GetUnitX(gg_unit_h001_0021),GetUnitY(gg_unit_h001_0021),0.0)
                call SetPlayerAllianceStateBJ(Player(n), playerGwapo, bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerAllianceStateBJ(playerGwapo, Player(n), bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerAllianceStateBJ( Player(n), playerPangit, bj_ALLIANCE_UNALLIED )
                call SetPlayerAllianceStateBJ( playerPangit, Player(n), bj_ALLIANCE_UNALLIED )
            elseif( n >= 6 and GetPlayerSlotState(Player(n)) == PLAYER_SLOT_STATE_PLAYING ) then
                call SetPlayerState(Player(n),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(Player(n),PLAYER_STATE_RESOURCE_GOLD)+625)
                call ForceAddPlayer(teamPangit,Player(n))
                call CreateUnit(Player(n),'n000',GetUnitX(gg_unit_h002_0023),GetUnitY(gg_unit_h002_0023),0.0)
                call SetPlayerAllianceStateBJ(Player(n), playerPangit, bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerAllianceStateBJ(playerPangit, Player(n), bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerAllianceStateBJ( Player(n),  playerGwapo, bj_ALLIANCE_UNALLIED )
                call SetPlayerAllianceStateBJ( playerGwapo, Player(n), bj_ALLIANCE_UNALLIED )
            endif
            call SetPlayerState(Player(n), PLAYER_STATE_GIVES_BOUNTY, 1)
            set n = n + 1
            exitwhen n == 12
        endloop
        call SetPlayerAllianceStateBJ(Player(12), playerPangit, bj_ALLIANCE_UNALLIED)
        call SetPlayerAllianceStateBJ(playerPangit, Player(12), bj_ALLIANCE_UNALLIED)
        call SetPlayerAllianceStateBJ( Player(12),  playerGwapo, bj_ALLIANCE_UNALLIED )
        call SetPlayerAllianceStateBJ( playerGwapo, Player(12), bj_ALLIANCE_UNALLIED )
        call assignHeroes()
        call SetPlayerName(playerGwapo, "Extrinsic")
        call SetPlayerName(playerPangit, "Intrinsic")
        call SetPlayerState(playerGwapo, PLAYER_STATE_GIVES_BOUNTY, 1)
        call SetPlayerState(playerPangit, PLAYER_STATE_GIVES_BOUNTY, 1)
        call SetPlayerColor(playerGwapo,ConvertPlayerColor(9))
        call SetPlayerColor(playerPangit,ConvertPlayerColor(10))
        call CleanWeatherWeights()
        call SetWeatherWeight(Lordaeron_Rain_Heavy,3.)
        call SetWeatherWeight(Lordaeron_Rain_Light,4.)
        call SetWeatherWeight(Rays_Of_Light, 5.)
        call SetWeatherWeight(Rays_Of_Moonlight, 5.)
        call XE_PreloadAbility(lifeBug)
        set n = 0
    endfunction
    
endscope


JASS:
scope HeroDeath initializer init

    globals
        private constant integer spell = 'ZZZY'
        private constant integer stell = 'A00O'
        private constant integer soulStone = 'h003'
        private constant integer ct = 'h000'
        private constant real INVULNE_TIME = 6.0
        private unit array myHero
    endglobals
    
    private function deathCon takes nothing returns boolean
        return IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO) and not IsUnitIllusion(GetTriggerUnit())
    endfunction
    
    private function deathAct takes nothing returns nothing
        local unit c = GetTriggerUnit()
        local unit u = CreateUnit(GetOwningPlayer(c),soulStone,GetUnitX(c),GetUnitY(c),0.0)
        set myHero[GetPlayerId(GetOwningPlayer(c))] = c
        if ( IsUnitInForce(c,teamPangit) ) then
            set heroKills[0] = heroKills[0] + 1
        elseif ( IsUnitInForce(c,teamGwapo) ) then
            set heroKills[1] = heroKills[1] + 1
        endif
        if ( GetRandomInt(1,3) == 1 ) then
            call CreateItem('I000',GetUnitX(c),GetUnitY(c))
        endif
        if ( GetRandomInt(1,3) == 1 ) then
            call CreateItem('I00B',GetUnitX(c),GetUnitY(c))
        endif
        if (GetLocalPlayer() == GetOwningPlayer(c)) then
            call ClearSelection()
            call SelectUnit(u, true)
            call PanCameraToTimed(GetUnitX(u), GetUnitY(u),0.0)
        endif
        call reloadBoard()
        set c = null
        set u = null
    endfunction
    
    private function abortAct takes nothing returns nothing
        local unit c = SpellEvent.CastingUnit
        if ( SpellEvent.TargetUnit != null ) then
            if ( GetUnitTypeId(SpellEvent.TargetUnit) != ct ) then
                call AbortSpell(c,"Must target Control Tower.", "R")
            endif
        endif
        set c = null
    endfunction
    
    private struct invulne
        unit h
    endstruct
    
    private function removeInvulne takes nothing returns boolean
        local timer t = GetExpiredTimer()
        local invulne d = GetTimerData(t)
        call SetUnitInvulnerable(d.h,false)
        call SetUnitVertexColor(d.h,255,255,255,255)
        call ReleaseTimer(t)
        call d.destroy()
        set t = null
        return true
    endfunction
    
    private function reviveAct takes nothing returns nothing
        local unit c = SpellEvent.CastingUnit
        local unit uu
        local integer n = 0
        local group g
        local unit u
        local unit r = null
        local boolean go = false
        local real x = SpellEvent.TargetX
        local real y = SpellEvent.TargetY
        local real dist
        local real td = 999999.0
        local timer t = NewTimer()
        local invulne d
        if ( GetUnitTypeId(c) == soulStone ) then
            if ( SpellEvent.TargetUnit == null ) then
                set g = NewGroup()
                call GroupEnumUnitsInRange(g,x,y,999999,BOOLEXPR_TRUE)
                loop
                    set u = FirstOfGroup(g)
                    exitwhen u == null
                    if ( IsUnitAlly(u,GetOwningPlayer(c)) and GetUnitTypeId(u) == ct ) then
                        set dist = SquareRoot( (GetUnitX(u)-x)*(GetUnitX(u)-x) + (GetUnitY(u)-y)*(GetUnitY(u)-y) )
                        if ( dist < td ) then
                            set td = dist
                            set r = u
                        endif
                    endif
                    call GroupRemoveUnit(g,u)
                endloop
                call ReleaseGroup(g)
                set g = null
                set u = null
            elseif ( SpellEvent.TargetUnit != null ) then
                if ( GetUnitTypeId(SpellEvent.TargetUnit) == ct and IsUnitAlly(SpellEvent.TargetUnit,GetOwningPlayer(c)) ) then
                    set r = SpellEvent.TargetUnit
                endif
            endif
            if ( r != null ) then
                set uu = myHero[GetPlayerId(GetOwningPlayer(c))]
                call ReviveHero(uu,GetUnitX(r),GetUnitY(r),true)
                set d = invulne.create()
                set d.h = uu
                call SetUnitInvulnerable(uu,true)
                call SetUnitVertexColor(uu,255,50,50,255)
                call TimerStart(t,INVULNE_TIME,false,function removeInvulne)
                call SetTimerData(t,d)
                if (GetLocalPlayer() == GetOwningPlayer(uu)) then
                    call ClearSelection()
                    call SelectUnit(uu, true)
                    call PanCameraToTimed(GetUnitX(uu), GetUnitY(uu),0.0)
                endif
                call SetUnitState(uu,UNIT_STATE_MANA,GetUnitState(uu,UNIT_STATE_MAX_MANA))
                set uu = null
                set myHero[GetPlayerId(GetOwningPlayer(c))] = null
                set r = null
                call RemoveUnit(c)
            endif
        endif
        set c = null
        set t = null
    endfunction
    
    private function reviveHere takes nothing returns nothing
        local unit c = SpellEvent.CastingUnit
        local real x = GetUnitX(c)
        local real y = GetUnitY(c)
        local unit u
        local timer t = NewTimer()
        local invulne d
        if(GetUnitTypeId(c) == soulStone)then
            set u = myHero[GetPlayerId(GetOwningPlayer(c))]
            call ReviveHero(u,x,y,true)
            set d = invulne.create()
            set d.h = u
            call SetUnitInvulnerable(u,true)
            call SetUnitVertexColor(u,255,50,50,255)
            call TimerStart(t,INVULNE_TIME,false,function removeInvulne)
            call SetTimerData(t,d)
            if (GetLocalPlayer() == GetOwningPlayer(u)) then
                call ClearSelection()
                call SelectUnit(u, true)
                call PanCameraToTimed(GetUnitX(u), GetUnitY(u),0.0)
            endif
            call SetUnitState(u,UNIT_STATE_MANA,GetUnitState(u,UNIT_STATE_MAX_MANA))
            set myHero[GetPlayerId(GetOwningPlayer(c))] = null
            set u = null
            call RemoveUnit(c)
        endif
        set c = null
        set t = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(t,function deathAct)
        call TriggerAddCondition(t, Condition(function deathCon))
        call RegisterSpellEffectResponse(spell,reviveAct)
        call RegisterSpellEffectResponse(stell,reviveHere)
        call RegisterSpellCastResponse(spell,abortAct)
    endfunction
    
endscope


I posted the triggers that mostly deal with hero death and hero kills, because when I tested my map in lan with my friends, there's a high tendency that when a hero dies the game desyncs.

Thanks.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Getting the player slot state on map init causes differing data for different players and thus causes desyncs upon calling/returning. This is a known bug.
Get the player slot state at GameTimeExpired = 0.01 s

Also, better not initialize strings inside a local block. Initialize them outside and copy the string.

Like that:
JASS:

local string s1 = ""
local string s2 = I2S(GetPlayerId(P)) //... etc.
if GetLocalPlayer() == Player(0) then
    set s1 = s2
endif
call DisplayTimedTextToPlayer(Player(0), s1 ... )

Though strings usually do not cause desyncs, they seem not 100% safe in local blocks - at least the string initialization.
And besides ... the whole local block thing with the player colors makes no sense in your script. There is not reason to use local blocks at all here, as you can easily display a string for just one player.
You only need localized strings for something like displaying a special effect for only one player or changing the art path for something locally.


And why do you use [ljass]DisplayTimedTextToPlayer[/ljass] inside a local block? That makes no sense, as the function has a player parameter. Although that should not be the problem, you should avoid doing something like that. Only use functions inside local blocks that make sense.
 

Azlier

Old World Ghost
Reaction score
461

Zwiebelchen

You can change this now in User CP.
Reaction score
60

Azlier

Old World Ghost
Reaction score
461
Yes, luckily text display natives take a player.
 

waaaks!

Zinctified
Reaction score
255
but what about displaying text message for a force, like this?
JASS:
if (IsPlayerInForce(GetLocalPlayer(), teamPangit)) then
    set s = PlayerColor[GetPlayerId(GetOwningPlayer(c))] + GetPlayerName(GetOwningPlayer(c)) + "|r has picked " + GetUnitName(c)
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, s)
endif

do I need to call [ljass]DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, s)[/ljass] outside the local block or what?

Edit:
and what about this?
JASS:
if (GetLocalPlayer() == GetOwningPlayer(c)) then
      call ClearSelection()
      call SelectUnit(u, true)
      call PanCameraToTimed(GetUnitX(u), GetUnitY(u),0.0)
  endif

is this safe?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top