Why does this code crash the game, when I try to share vision?
JASS:
function Trig_AllyPlayer_Actions takes nothing returns nothing
local string chat = GetEventPlayerChatString()
local player p1 = GetTriggerPlayer()
local integer i2 = S2I(SubString(chat ,6,StringLength(chat)))-1
local player p2 = Player(i2)
if(p1 != p2)then
call SetPlayerAllianceStateAllyBJ(p1,p2, true)
endif
set chat = null
set p1 = null
set p2 = null
endfunction
function UnAllyPlayer_Actions takes nothing returns nothing
local string chat = GetEventPlayerChatString()
local player p1 = GetTriggerPlayer()
local integer i2 = S2I(SubString(chat ,8,StringLength(chat)))-1
local player p2 = Player(i2)
if(p1 != p2)then
call SetPlayerAllianceStateAllyBJ(p1,p2,false)
call SetPlayerAllianceStateControlBJ(p1,p2,false)
call SetPlayerAllianceStateFullControlBJ(p1,p2,false)
call SetPlayerAllianceStateVisionBJ(p1,p2,false)
endif
set chat = null
set p1 = null
set p2 = null
endfunction
function VisionPlayer_Actions takes nothing returns nothing
local string chat = GetEventPlayerChatString()
local player p1 = GetTriggerPlayer()
local integer i2 = S2I(SubString(chat ,6,StringLength(chat)))-1
local player p2 = Player(i2)
if(p1 != p2)then
call SetPlayerAllianceStateVisionBJ(p1,p2, true)
endif
set chat = null
set p1 = null
set p2 = null
endfunction
function UnVisionPlayer_Actions takes nothing returns nothing
local string chat = GetEventPlayerChatString()
local player p1 = GetTriggerPlayer()
local integer i2 = S2I(SubString(chat ,6,StringLength(chat)))-1
local player p2 = Player(i2)
if(p1 != p2)then
call SetPlayerAllianceStateVisionBJ(p1,p2, false)
endif
set chat = null
set p1 = null
set p2 = null
endfunction
//===========================================================================
function InitTrig_AllyPlayer takes nothing returns nothing
local integer index
local trigger UnAllyPlayer = CreateTrigger()
local trigger VisionPlayer = CreateTrigger()
local trigger UnVisionPlayer = CreateTrigger()
set gg_trg_AllyPlayer = CreateTrigger()
set index = 0
loop
call TriggerRegisterPlayerChatEvent( gg_trg_AllyPlayer, Player(index), "-ally", false )
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction( gg_trg_AllyPlayer, function Trig_AllyPlayer_Actions )
set index = 0
loop
call TriggerRegisterPlayerChatEvent( UnAllyPlayer, Player(index), "-unally", false )
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction( UnAllyPlayer, function UnAllyPlayer_Actions )
set index = 0
loop
call TriggerRegisterPlayerChatEvent( VisionPlayer, Player(index), "-vision", false )
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction( VisionPlayer, function VisionPlayer_Actions )
set index = 0
loop
call TriggerRegisterPlayerChatEvent( UnVisionPlayer, Player(index), "-vision", false )
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction( UnVisionPlayer, function UnVisionPlayer_Actions )
endfunction