• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Trigger to Spawn Units based on Upgrades.

Status
Not open for further replies.
Level 2
Joined
Oct 28, 2017
Messages
10
Hello, first post here on the Forum. Long time lurker, first time poster.

I'm trying to figure out the best way to make a trigger that spawns a unit periodically (ex. every 60 sec) based on Units that have been trained at A building (ex. Barracks).

So, for a specific example:
Imagine a Barracks with the Footman Unit. When you purchase that unit, one Footman will spawn every 60 seconds from a specified region. When you purchase another one of that unit, 2 Footmen will spawn every 60 seconds from that same region. And so on.

I'm sure there is a way to do it, but I am not familiar enough with triggers to figure it out... Even if the Train Unit Button is an Upgrade or an Ability instead, that could work, just not sure how the triggers would look.

Thanks for taking the time to read through my issue, any help is appreciated. :)

EDIT: I thought I was posting in the World Edit Help Section, sorry for posting in the wrong section :s If a mod could move it over I would be grateful, so I don't have to double-post.
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
The first thing you have to ask yourself is what button you want.
Ability: cooldown, mana cost, also works with gold/lumber cost
Unit: train progress bar, gold lumber and supply
Research: I would not use it. Each research can only be researched once.

So I would go with units, as it allows you to have supply cost and a train progress bar.
The unit that is "trained" in the barracks is not the same as the unit that is spawned though. The trained unit only has the purpose of a button.
You have two events to detect when the unit is created:
  • Train
    • Events
      • Unit - A unit enters (Playable map area)
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
Then you would instantly remove that unit and trigger the effect in your spawn system.

If you also want supply, it is a bit more difficult.
You want to remove the unit, so its supply cost woll no longer be there. You would use
  • Player - Add 2 to Player 1 (Red) Food used
to add the supply with triggers. There are some problems with supply I can explain, if you need your units to cost supply.
 
Level 2
Joined
Oct 28, 2017
Messages
10
The first thing you have to ask yourself is what button you want.
Ability: cooldown, mana cost, also works with gold/lumber cost
Unit: train progress bar, gold lumber and supply
Research: I would not use it. Each research can only be researched once.

So I would go with units, as it allows you to have supply cost and a train progress bar.
The unit that is "trained" in the barracks is not the same as the unit that is spawned though. The trained unit only has the purpose of a button.
You have two events to detect when the unit is created:
  • Train
    • Events
      • Unit - A unit enters (Playable map area)
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
Then you would instantly remove that unit and trigger the effect in your spawn system.

If you also want supply, it is a bit more difficult.
You want to remove the unit, so its supply cost woll no longer be there. You would use
  • Player - Add 2 to Player 1 (Red) Food used
to add the supply with triggers. There are some problems with supply I can explain, if you need your units to cost supply.


Thank you for the reply, but after a couple days of looking around the trigger editor, I figured it out on my own :D
I just used the "unit-a unit finishes research" event, then made that 'turn on' another trigger to spawn the unit, so the correct trigger could be turned on based on which research was finished/which unit was wanted.
Then I just lined this up with a previously made timer and it all worked!

Thanks again for the reply!
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
A hacky way to do this would be to hide all trained units in some corner of the map and add them to a group. You can then create a copy of every unit in that group every 60 seconds.

Otherwise one could do as andreasaspenberg suggests and use a hash table or arrays to map unit types to unit counts and then iterate through all unit types creating the appropriate count.
 
Level 2
Joined
Oct 28, 2017
Messages
10
A hacky way to do this would be to hide all trained units in some corner of the map and add them to a group. You can then create a copy of every unit in that group every 60 seconds.

Otherwise one could do as andreasaspenberg suggests and use a hash table or arrays to map unit types to unit counts and then iterate through all unit types creating the appropriate count.

This was actually my first idea lol. I had an area where they would build up then i would move them to a new area with a trigger when it was time, but it just felt so messy and clunky.


i might have a better solution. it involves using a variable. each time you purchase a footman you add 1 to the variable which can be a real variable. then you spawn units equal to the value of that variable.

This is a great idea. I haven't used a lot of variables yet, but I imagine it would be a cleaner solution than my on-and-off triggers :O
Thank you!
 
Status
Not open for further replies.
Top