spawning of units not right?

waaaks!

Zinctified
Reaction score
255
ok I have this not-so-complicated-but-not-so-simple-spawn-system trigger.

What it does is:
  1. check if a global boolean is true
  2. randoms out an integer and picks a route depending on the randomn integer
  3. creates 2 the same melee unit type
  4. creates 1 range unit
  5. creates 1 siege unit
  6. orders the unit to use "smart" order to a specified route
  7. ...another set of the same codes for the other team
the problem is, it does only creates 1 melee unit, and 1 siege unit for team 1, and no units for team 2

heres the code
JASS:
scope SpawnMob initializer init

    globals
        private constant integer meleeCount = 2
        private constant integer meleeUnit = 'n000'
        private constant integer rangeUnit = 'n001'
        private constant integer mayorUnit = 'o000'
        boolean array mayorSpawnReady //at init
    endglobals
    
    private function act takes nothing returns nothing
        local integer n = 0
        local unit u = null
        if ( mayorSpawnReady[0] ) then
            set mayorSpawnReady[0] = false
            if ( GetRandomInt(0,1) == 0 ) then
                loop
                    exitwhen n > meleeCount
                    set u = CreateUnit(playerGwapo,meleeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                    call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
                    set n = n + 1
                endloop
                set n = 0
                set u = CreateUnit(playerGwapo,rangeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
                set u = CreateUnit(playerGwapo,mayorUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
            else
                loop
                    exitwhen n > meleeCount
                    set u = CreateUnit(playerGwapo,meleeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                    call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
                    set n = n + 1
                endloop
                set n = 0
                set u = CreateUnit(playerGwapo,rangeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
                set u = CreateUnit(playerGwapo,mayorUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
            endif
        endif
        //============For Enemy==============
        if ( mayorSpawnReady[1] ) then
            set mayorSpawnReady[1] = false
            if ( GetRandomInt(0,1) == 0 ) then
                loop
                    exitwhen n > meleeCount
                    set u = CreateUnit(playerPangit,meleeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                    call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
                    set n = n + 1
                endloop
                set n = 0
                set u = CreateUnit(playerPangit,rangeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
                set u = CreateUnit(playerPangit,mayorUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),90.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerTop),GetRectCenterY(gg_rct_centerTop))
            else
                loop
                    exitwhen n > meleeCount
                        set u = CreateUnit(playerPangit,meleeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                    call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
                    set n = n + 1
                endloop
                set n = 0
                set u = CreateUnit(playerPangit,rangeUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
                set u = CreateUnit(playerPangit,mayorUnit,GetRectCenterX(gg_rct_gSpawn),GetRectCenterY(gg_rct_gSpawn),270.0)
                call IssuePointOrder(u,"smart",GetRectCenterX(gg_rct_centerBottom),GetRectCenterY(gg_rct_centerBottom))
            endif
        endif
        set u = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t,30)
        call TriggerAddAction(t, function act)
        set mayorSpawnReady[0] = true
        set mayorSpawnReady[1] = true
    endfunction
    
endscope

notice that mayorSpawnReady is a global variable created from another trigger
thanks :D
 

jomik

New Member
Reaction score
17
Who is playerGwapo and playerPangit? Lol :D
Umm, and you did test more than once right? - Since there's only 50% chance that it'll spawn :O (If it works for 1 team it should work for the other too? :O)
I'd rather make it something like GetRandomInt(0, 100) < 51

Do you have other triggers with this one? - I'll look at it when I get home :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
notice that mayorSpawnReady is a global variable created from another trigger

So what is this then:
JASS:
    globals
        private constant integer meleeCount = 2
        private constant integer meleeUnit = &#039;n000&#039;
        private constant integer rangeUnit = &#039;n001&#039;
        private constant integer mayorUnit = &#039;o000&#039;
        boolean array mayorSpawnReady //at init
    endglobals


And this:
JASS:
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t,30)
        call TriggerAddAction(t, function act)
        set mayorSpawnReady[0] = true
        set mayorSpawnReady[1] = true
    endfunction


They're created and set in the very same trigger, or am I missing something ? :S

Also, in my experience, there should be 4 melee units created, since first n = 0, and it becomes 1, then 2 and at last 3 (Which makes [ljass]n > meleeCount[ljass] true, since 3 or more than 2...)

But, I can't say why it only creates one... :S
 

waaaks!

Zinctified
Reaction score
255
looks like I placed the mayorSpawnReady inside that trigger before posting it here, and yeah, all variables inside the code that are not initialized or created in the code, then it may be a global variable from outside the code
 

jomik

New Member
Reaction score
17
Can you explain more precisely what the code is supposed to do? Why do you have the mayorSpawnReady global? :D
 

chobibo

Level 1 Crypt Lord
Reaction score
48
JASS:
function CreateSpawns takes nothing returns nothing
    
    local unit spawn
    
    local integer i
    local integer j
    
    // Create spawns for playerGwapo
    if READY[0] then
        set i=0
        set j=GetRandomInt(0,1)  // 0=top,1=bottom
    
        loop
            exitwhen (i==meleeCount)
            set spawn=CreateUnit(playerGwapo, meleeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
            call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
            set i=i+1
        endloop
    
        set spawn=CreateUnit(playerGwapo, rangeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
        call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
    
        set spawn=CreateUnit(playerGwapo, siegeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
        call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
    endif
    
    
    
    // Create spawns for playerPangit
    if READY[1] then
        set i=0
        set j=GetRandomInt(0,1)  // 0=top,1=bottom
    
        loop
            exitwhen (i==meleeCount)
            set spawn=CreateUnit(playerPangit, meleeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
            call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
            set i=i+1
        endloop
    
        set spawn=CreateUnit(playerPangit, rangeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
        call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
    
        set spawn=CreateUnit(playerPangit, siegeUnit, SPAWN_POINT_X, SPAWN_POINT_Y, 90.00)
        call IssuePointOrder(spawn,&quot;smart&quot;,GetRectCenterX(ROUTE[j]),GetRectCenterY(ROUTE[j]))
    endif

endfunction

Suggestion.
 

waaaks!

Zinctified
Reaction score
255
mayorSpawnReady global's role in the trigger is to check if the siege unit (mayor) is spawned, because it should only spawn ONCE every 30 seconds, lets say if mayor is in the game, and another 30 seconds have passed, then it checks if the previous mayor is still there

this is to ensure that there will be only 1 mayor unit spawned
 

waaaks!

Zinctified
Reaction score
255
bump, please don't give me any reworked code, just tell me the reason why it doesn't work?
 

jomik

New Member
Reaction score
17
Who is playerGwapo and playerPangit? Lol :D
Umm, and you did test more than once right? - Since there's only 50% chance that it'll spawn :O (If it works for 1 team it should work for the other too? :O)
I'd rather make it something like GetRandomInt(0, 100) < 51

Do you have other triggers with this one? - I'll look at it when I get home :D

Yay for quoting myself.
Can you answer the questions I put up here please? I'd help pretty much with seeing whats wrong lol.
Also, you should just check if there's a unit of unit-type major owned by player pangit alive, then if not, spawn the wave.
 
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