• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

Conditions for Unit Spawn Triggers

Status
Not open for further replies.
Level 5
Joined
Jun 3, 2010
Messages
100
Hey guys,

I've been able to get the trigger to spawn my units perfectly. But I can't get it to stop when it reaches 11 units. Actually, I can't figure out how to stop it period. I tried an If Then Else but had no luck. Any help or feedback is appreciated :)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
You need to keep track of unit numbers.

The stupid approach would be to just count the units of the spawn type and if it is less than 11, spawn.

The smart approach is to keep track of how many are created and destroyed. When one dies you remove 1 from the counter otherwise you add 1 when you spawn a new unit. You can keep spawning while the counter is less than 11 units. You also turn off and on the trigger (off when the spawn codition fails or on if a unit of that type dies).

To do this in GUI, I would have the perodic timer (rate of spawn) as the event. Then you are after an if statement. The condition checks the number of units of the type (via one of the methods described above) is less than 11. The actions just spawns a unit.

You can use arrays or loops to run it for many players.
 
Level 5
Joined
Jun 3, 2010
Messages
100
i kinda understand what you are saying, but am clueless on how to go about doing this stuff.

What's the proper way to keep track of the units? I'd like the SCV's to start off at 11, and only spawn after you start losing them. I'm guessing a Unit Dies trigger event is better? I tried to do something like that just now, and I wasnt sure where they would spawn, I had no region option for the spawn point.

Ok, I think I've got how I can do this. I'm going to create an Any Unit Dies trigger, so that when an SCV dies it will run a check on each players total amount and if under 11 it will spawn one. If it's already at 11 then it will just ignore it. I have a feeling that I'm still not doing it correctly, but I've almost managed to create it all. I'm still stuck at the Validator I think, I still can't figure out how to keep the SCV count at 11 maximum.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The problem you are suffering appears to me more realted to creating triggers in general, not figuring out how to do something like this. I advise taking a break and opening up The Wings of Liberty campaign maps or other spawn related maps and seeing how they handle unit spawning and such. This might help you a lot with future problems and you may find some ideas you can relate to during your mapping experience.

How I would personally do it is create 2 integer variables. Each represents the SCV number for each team. Every time I spawn a SCV for a team, I add 1 (incriment) its counter. I then check if that team's counter is equal to 11 and if so I then disable the spawn system for that team. When an SCV dies I would check if that team's counter is equal to 11 and if so turn back on the spawn system. Finally after that test I would decriment that teams counter by 1.

Honestly its that simple and has the advantage of only using the most basic of opperations (no opperations relating to the total number of units or opperations that provide constant overhead).
 
Level 5
Joined
Jun 3, 2010
Messages
100
yes you are correct, i have no clue how to do triggers, and there isnt a lot of info out there. i guess its a tough thing to teach :p

SpawnUnitsSCV.jpg


this is what i came up with and it seems to work ok, it instantly replaced the fallen SCV at your starting region. I would like a 1 second periodical timer, however, I am still wondering what some of these options for the triggers do :)

Edit: I was just confused about then value with Stop all instances of the trigger, but i went ahead and tried out a Periodic event instead of the Unit Dies and it's working fine now :) Thanks a ton.
 
Last edited:
Level 5
Joined
Jul 10, 2010
Messages
124
here's how to do something a little better than periodic triggers thats easy to understand; the biggest problem i see people on this forum have is they don't know how to use action definitions, which by themselves make SC2s editor 100% better than WC3

you will need to replace my "Empty Region" with the region on your map when you make this

attachment.php
 

Attachments

  • trig.jpg
    trig.jpg
    439.2 KB · Views: 552
  • scv trigger.SC2Map
    170.3 KB · Views: 111
Level 5
Joined
Jun 3, 2010
Messages
100
thanks a lot, got it working but theres a problem with the way this works. I still need seperate triggers for each player because their SCVS dont spawn in the same location. great information nonetheless ive learned a lot just now :)
 
Create an integer variable.
When a SCV is created, add +1 to the variable.
When the integer is 11 or above, turn on a trigger that kills SCVs when they are spawned.

Edit: Or even easier.. just create a custom resource that you need to build SCVs.
Give a player 11.
When an SCV dies, give the owner of triggering unit +1 of that resource.
 
Level 5
Joined
Jul 10, 2010
Messages
124
thanks a lot, got it working but theres a problem with the way this works. I still need seperate triggers for each player because their SCVS dont spawn in the same location. great information nonetheless ive learned a lot just now :)

no, you can just add a region parameter to your action definition and you still just need one
 
Status
Not open for further replies.
Top