Light Alkmst
New Member
- Reaction score
- 20
I've been trying to find a way to optimize this when I thought of a way to do it. I didn't want 10 individual triggers running each unit death, and came up with this solution, that unfortunately doesn't work.
Somehow, although the "next" variable displays the right numbers, and adding the 's000' makes sense, and the end ID is right, it mysteriously stops at the 10 Spartans. 1-6 work fine, but it stops when the 10 should spawn. I know the trouble is within the Actions function, but it's beyond me why it doesn't work now...
JASS:
library Sparta initializer Absolute
private function End takes nothing returns nothing
local group g = CreateGroup()
local unit u
call GroupEnumUnitsInRect(g, GetWorldBounds(), null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
call SetHeroXP(u, GetHeroXP(u) * 300, true)
endloop
endfunction
//! textmacro SPARTANS takes NUMBER, HEALTH, NEXT
// //! external ObjectMerger w3u n001 s$NUMBER$ unam "$NUMBER$ Spartan" ua1d $NUMBER$ udef $NUMBER$ uhpm $HEALTH$
private function Filt$NUMBER$ takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 039;s$NUMBER$039; and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0. and IsUnitAlly(GetFilterUnit(), GetTriggerPlayer())
endfunction
private function Conditions$NUMBER$ takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 039;s$NUMBER$039;
endfunction
private function Actions$NUMBER$ takes nothing returns nothing
local group g = CreateGroup()
local integer c = 0
local integer next = $NUMBER$ + 1
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
local real a = GetUnitFacing(GetTriggerUnit())
call GroupEnumUnitsInRect(g, GetWorldBounds(), Condition(function Filt$NUMBER$))
if (FirstOfGroup(g) == null) then
if ($NUMBER$ != 300) then
loop
exitwhen I2R(300 / next) == 300. / I2R(next)
set next = next + 1
endloop
debug call BJDebugMsg("Next Spartan count: " + I2S(next))
debug call BJDebugMsg("Next Spartan count: " + I2S(039;s000039; + next))
loop
exitwhen c == $NEXT$ or $NEXT$ == 0
//call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), 's$NEXT$', x, y, a)
call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), 039;s000039; + next, x, y, a)
set c = c + 1
endloop
else
//call End()
endif
endif
call DestroyGroup(g)
set g = null
endfunction
private function Init$NUMBER$ takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t, Condition(function Conditions$NUMBER$))
call TriggerAddAction(t, function Actions$NUMBER$)
endfunction
//! endtextmacro
//! runtextmacro SPARTANS("001", "300", "002")
//! runtextmacro SPARTANS("002", "150", "003")
//! runtextmacro SPARTANS("003", "100", "004")
//! runtextmacro SPARTANS("004", "075", "005")
//! runtextmacro SPARTANS("005", "060", "006")
//! runtextmacro SPARTANS("006", "050", "010")
//! runtextmacro SPARTANS("010", "030", "012")
//! runtextmacro SPARTANS("012", "025", "015")
//! runtextmacro SPARTANS("015", "020", "020")
//! runtextmacro SPARTANS("020", "015", "025")
//! runtextmacro SPARTANS("025", "012", "030")
//! runtextmacro SPARTANS("030", "010", "050")
//! runtextmacro SPARTANS("050", "006", "060")
//! runtextmacro SPARTANS("060", "005", "075")
//! runtextmacro SPARTANS("075", "004", "100")
//! runtextmacro SPARTANS("100", "003", "150")
//! runtextmacro SPARTANS("150", "002", "300")
//! runtextmacro SPARTANS("300", "001", "000")
private function Absolute takes nothing returns nothing
call Init001()
call Init002()
call Init003()
call Init004()
call Init005()
call Init006()
call Init010()
call Init012()
call Init015()
call Init020()
call Init025()
call Init030()
call Init050()
call Init060()
call Init075()
call Init100()
call Init150()
call Init300()
endfunction
endlibrary
Somehow, although the "next" variable displays the right numbers, and adding the 's000' makes sense, and the end ID is right, it mysteriously stops at the 10 Spartans. 1-6 work fine, but it stops when the 10 should spawn. I know the trouble is within the Actions function, but it's beyond me why it doesn't work now...