- Joined
- Oct 29, 2007
- Messages
- 1,184
I am creating a respawn system for neutral passive controlled units. This is the code I have:
Why does bj_lastCreatedUnit seem to refer to a unit I created earlier using GUI, and not the units I am creating within this code?
JASS:
scope Initialization initializer InitInit
function InitInit takes nothing returns nothing
local rect r = bj_mapInitialPlayableArea
local location l
local integer i = 0
local real x
local real y
local integer random
loop
set x = GetRandomReal(GetRectMinX(r), GetRectMaxX(r))
set y = GetRandomReal(GetRectMinY(r), GetRectMaxY(r))
set l = Location(x,y)
set random = GetRandomInt(0, 4)
if random == 0 then
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nvlk',x,y,0)
elseif random == 1 then
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nvk2',x,y,0)
elseif random == 2 then
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nvlw',x,y,0)
elseif random == 3 then
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nvl2',x,y,0)
elseif random == 4 then
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'nvil',x,y,0)
endif
set udg_Citizen[i] = bj_lastCreatedUnit
set udg_CitizenStartLocX[i] = x
set udg_CitizenStartLocY[i] = y
call SetUnitUserData(udg_Citizen[i], i )
set i = i + 1
exitwhen i == 199
endloop
call RemoveLocation(l)
endfunction
endscope
scope Citizendies initializer InitCitizendies
function respawncitizen takes nothing returns nothing
local unit u = GetDyingUnit()
local integer i = GetUnitUserData(u)
call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), GetUnitTypeId(u), -1600,2000, 0)
call RemoveUnit(u)
set u = bj_lastCreatedUnit
call IssuePointOrder(u, "move" , udg_CitizenStartLocX[i], udg_CitizenStartLocY[i])
call SetUnitUserData(u, i )
call fade(u)
set u = null
endfunction
function InitCitizendies takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddAction(t, function respawncitizen)
set t = null
endfunction
endscope
Why does bj_lastCreatedUnit seem to refer to a unit I created earlier using GUI, and not the units I am creating within this code?