Hey there - it's been a really long time since I've been in the coding loop and I've apparantly gotten pritty rusty. Anyways I have a bit of code I'm working on that refuses to work correctly.
The idea was to have an array so each of the four players could each 'target' a unit. However, whenever any player selects a unit it overwrites the other players selections.
Well here's my code:
I honestly can't spot the error, although my logical debugging ability has been blown up after nearly a year without coding.
Nice to see you all again ;P and thanks for the help.
-Blackroot.
The idea was to have an array so each of the four players could each 'target' a unit. However, whenever any player selects a unit it overwrites the other players selections.
Well here's my code:
JASS:
struct PLAYER_TARGET_DATA
unit TARGET
playercolor COLOR
endstruct
globals
PLAYER_TARGET_DATA array SYSTEM_PTD[4]
endglobals
function ENGINE_TARGET_SYSTEM_HANDLER_DES takes nothing returns nothing
local player p = GetTriggerPlayer()
local unit u = GetTriggerUnit()
local PLAYER_TARGET_DATA ptd = SYSTEM_PTD[GetPlayerId(p)]
call SetUnitColor(ptd.TARGET, ptd.COLOR)
set ptd.COLOR = null
set ptd.TARGET = null
endfunction
function ENGINE_TARGET_SYSTEM_HANDLER takes nothing returns nothing
local player p = GetTriggerPlayer()
local unit u = GetTriggerUnit()
local player o = GetOwningPlayer(u)
local PLAYER_TARGET_DATA ptd = SYSTEM_PTD[GetPlayerId(p)]
if(ptd.TARGET != null)then
call SetUnitColor(ptd.TARGET, ptd.COLOR)
set ptd.COLOR = null
endif
if(o != p)then
set ptd.TARGET = u
set ptd.COLOR = GetPlayerColor(o)
if(GetLocalPlayer() == p)then
call SetUnitColor(u, GetPlayerColor(p))
endif
endif
endfunction
function ENGINE_TARGET_SYSTEM_INIT takes nothing returns nothing
local trigger ENGINE_PLAYER_SELECT = CreateTrigger()
local trigger ENGINE_PLAYER_DESELECT = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(0), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(1), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(2), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(3), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerAddAction(ENGINE_PLAYER_SELECT, function ENGINE_TARGET_SYSTEM_HANDLER)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(0), EVENT_PLAYER_UNIT_DESELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(1), EVENT_PLAYER_UNIT_DESELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(2), EVENT_PLAYER_UNIT_DESELECTED, null)
call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(3), EVENT_PLAYER_UNIT_DESELECTED, null)
call TriggerAddAction(ENGINE_PLAYER_DESELECT, function ENGINE_TARGET_SYSTEM_HANDLER_DES)
endfunction
I honestly can't spot the error, although my logical debugging ability has been blown up after nearly a year without coding.
Nice to see you all again ;P and thanks for the help.
-Blackroot.