spawning of units not right?

waaaks!

Zinctified
Reaction score
256
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
256
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
256
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
256
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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.

      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