- Joined
- Jun 30, 2008
- Messages
- 580
I'm having this problem. The dummy unit has locust, but when the function is ran it suddenly doesn't have it anymore. But I have a regular placed dummy that is not affected by the code, and it still has locust.
Basically the code is suppose to create this dummy unit at the unit you left clicked. I have another code that moves that dummy unit to the targeted unit. But when I select a group around that unit, it selects the dummy unit and then the code is ran on that and it moves and disappears.
Here is the code:
Basically the code is suppose to create this dummy unit at the unit you left clicked. I have another code that moves that dummy unit to the targeted unit. But when I select a group around that unit, it selects the dummy unit and then the code is ran on that and it moves and disappears.
Here is the code:
JASS:
library DamageTargSys initializer Init
globals
constant integer SELECTER_MODEL = 'h004'
private constant integer MAX_DISTANCE = 1000
private boolean IsSelect = false
endglobals
private function OnLeftClick takes nothing returns nothing
local player selecter = GetTriggerPlayer()
local unit target = GetTriggerUnit()
local CharDat dat = LoadInteger(CD, GetPlayerId(selecter), 1)
if (IsSelect == false) then
if (dat.Character != target) then
call ShowUnit(dat.SelectionMod, true)
set dat.Selection = target
set IsSelect = true
if (GetLocalPlayer() == selecter) then
// Use only local code (no net traffic) within this block to avoid desyncs.
call ClearSelection()
call SelectUnit(dat.Character, true)
endif
set IsSelect = false
endif
endif
set selecter = null
set target = null
endfunction
function OnDoubleLeftClick takes nothing returns nothing
endfunction
function OnRightClick takes nothing returns nothing
endfunction
private function CheckDist takes nothing returns nothing
local integer a = 0
local CharDat dat
local real dx
local real dy
local real dxy
loop
exitwhen a > 9
set dat = LoadInteger(CD, a, 1)
set dx = GetUnitX(dat.Selection) - GetUnitX(dat.Character)
set dy = GetUnitY(dat.Selection) - GetUnitY(dat.Character)
set dxy = SquareRoot(dx * dx + dy * dy)
if (dxy >= MAX_DISTANCE) then
set dat.Selection = null
call ShowUnit(dat.SelectionMod, false)
endif
set a = a+1
endloop
set a = 0
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer a = 0
loop
exitwhen a > 9
call TriggerRegisterPlayerSelectionEventBJ(t, Player(a), true)
set a = a + 1
endloop
set a = 0
call TriggerAddAction(t, function OnLeftClick)
call TimerStart(CreateTimer(), 0.03, true, function CheckDist)
endfunction
endlibrary