- Joined
- Aug 27, 2012
- Messages
- 362
Hi guys, I need help with a trigger I've made. It's supposed to allow you to automatically send resources to an ally every 10 seconds. However, when I tested, typing the -autosend # command causes an instant crash to desktop, and I can't figure out why.
Here's my trigger:
Here's my trigger:
JASS:
globals
boolean array AutopoolOn
boolean array AutopoolOn2
endglobals
scope Autopool initializer OnInit
private struct AP
player pooler
player poolee
method destroy takes nothing returns nothing
set this.pooler = null
set this.poolee = null
endmethod
endstruct
private function Handler takes nothing returns nothing
local timer t = GetExpiredTimer()
local AP data = GetTimerData(t)
local integer gold
local integer wood
local integer gold2
local integer wood2
if GetPlayerSlotState(data.poolee) != PLAYER_SLOT_STATE_PLAYING or GetPlayerSlotState(data.pooler) != PLAYER_SLOT_STATE_PLAYING or not AutopoolOn[GetPlayerId(data.pooler)] then
set AutopoolOn2[GetPlayerId(data.pooler)] = false
call DisplayTextToPlayer(data.pooler,0.,0.,"Autosend disabled.")
call data.destroy()
call ReleaseTimer(t)
else
set gold = GetPlayerState(data.pooler, PLAYER_STATE_RESOURCE_GOLD)
set wood = GetPlayerState(data.pooler, PLAYER_STATE_RESOURCE_LUMBER)
call SetPlayerState(data.pooler,PLAYER_STATE_RESOURCE_GOLD,0)
call SetPlayerState(data.pooler,PLAYER_STATE_RESOURCE_LUMBER,0)
set gold2 = GetPlayerState(data.poolee, PLAYER_STATE_RESOURCE_GOLD)
set wood2 = GetPlayerState(data.poolee, PLAYER_STATE_RESOURCE_LUMBER)
if gold + gold2 >= 1000000 then
call SetPlayerState(data.poolee,PLAYER_STATE_RESOURCE_GOLD,1000000)
call DisplayTextToPlayer(data.pooler,0.,0.,"Warning: Autopool player has maximum gold. Stop pooling to prevent loss of resources. To turn off autosend, type -autosend off.")
call DisplayTextToPlayer(data.poolee,0.,0.,"Warning: You have maximum gold. Either spend it or convert it to prevent loss of resources.")
else
call SetPlayerState(data.poolee,PLAYER_STATE_RESOURCE_GOLD,gold + gold2)
endif
call SetPlayerState(data.poolee,PLAYER_STATE_RESOURCE_LUMBER,wood + wood2)
call SetTimerData(t,data)
call TimerStart(t,10.,false,function Handler)
endif
set t = null
endfunction
private function Conditions takes nothing returns boolean
local integer PlayerString = S2I(SubString(GetEventPlayerChatString(),11,StringLength(GetEventPlayerChatString()))) - 1
local timer t
local AP data
if PlayerString < 12 and PlayerString >= 0 then
if not AutopoolOn[GetPlayerId(GetTriggerPlayer())] and GetPlayerSlotState(Player(PlayerString)) == PLAYER_SLOT_STATE_PLAYING and IsPlayerAlly(GetTriggerPlayer(),Player(PlayerString)) and not AutopoolOn2[GetPlayerId(GetTriggerPlayer())] and GetTriggerPlayer() != Player(PlayerString) and PlayerString != GetPlayerId(GetTriggerPlayer()) then
set t = NewTimer()
set data = AP.create()
set data.pooler = GetTriggerPlayer()
set data.poolee = Player(PlayerString)
set AutopoolOn[GetPlayerId(data.pooler)] = true
set AutopoolOn2[GetPlayerId(data.pooler)] = true
call SetTimerData(t,data)
call TimerStart(t,10.,false, function Handler)
else
call DisplayTextToPlayer(GetTriggerPlayer(),0.,0.,"Error: Invalid input or you are already autosending someone. To turn off autosend, type -autosend off.")
endif
endif
set t = null
return false
endfunction
private function OnInit takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterPlayerChatEvent( trig, Player(0), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(1), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(2), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(3), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(4), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(5), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(6), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(7), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(8), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(9), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(10), "-autosend", false )
call TriggerRegisterPlayerChatEvent( trig, Player(11), "-autosend", false )
call TriggerAddCondition( trig, Condition(function Conditions) )
set AutopoolOn[0] = false
set AutopoolOn[1] = false
set AutopoolOn[2] = false
set AutopoolOn[3] = false
set AutopoolOn[4] = false
set AutopoolOn[5] = false
set AutopoolOn[6] = false
set AutopoolOn[7] = false
set AutopoolOn[8] = false
set AutopoolOn[9] = false
set AutopoolOn[10] = false
set AutopoolOn[11] = false
set AutopoolOn2[0] = false
set AutopoolOn2[1] = false
set AutopoolOn2[2] = false
set AutopoolOn2[3] = false
set AutopoolOn2[4] = false
set AutopoolOn2[5] = false
set AutopoolOn2[6] = false
set AutopoolOn2[7] = false
set AutopoolOn2[8] = false
set AutopoolOn2[9] = false
set AutopoolOn2[10] = false
set AutopoolOn2[11] = false
endfunction
endscope