The 300 Spartans!!!...doesn't work anymore...

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.

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()) == 's$NUMBER$' and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0. and IsUnitAlly(GetFilterUnit(), GetTriggerPlayer())
    endfunction
    
    private function Conditions$NUMBER$ takes nothing returns boolean
        return GetUnitTypeId(GetTriggerUnit()) == 's$NUMBER$'
    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('s000' + 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), 's000' + 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...
 

Light Alkmst

New Member
Reaction score
20
Yes

EDIT: when it was hardcoded with the right values, it worked perfectly. I wanted to remove the hardcoding, and made the function to set the "next" to integrate it all into 1 trigger. That's when it stopped working, and I don't want to revert.
 
Reaction score
341
Try adding this..

debug call BJDebugMsg(R2S(I2R(300 / next)) + " == " + R2S(300. / I2R(next)))

To see if the exitwhen is causing it.
 

Light Alkmst

New Member
Reaction score
20
I'm going to sleep now. I'll make sure the ID's are right tomorrow. I'll just line them up instead of putting them like they are now I guess...
 

Light Alkmst

New Member
Reaction score
20
I think I've figured it out. In the text macros, the integers I have have preceding 0s. I left them there to just hold place to make it tidy, but they're actually turning my numbers into octal! 010 != 10. 010 == 8
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top