• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Units Spawning Per X Amount of Nights Passing?

Level 5
Joined
Nov 17, 2022
Messages
84
I was curious if anyone here knew an answer for this and could post an example for me since I can't seem to figure it out.

In my horse game, I wanted to give some balance to the map via the progression of predators that appear on the map per night. So for example, Night 1 could start with the easier and weaker predators that patrol the map to prey on your horses. Then as the nights continue, new predator types unlock that weren't there before on the map get added, upping the difficulty to challenge you and your herds.

Anyone have an idea how I can do this?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
So you already know that:

1) You want to track how many Nights have passed.
2) Your example is: Night 1, Night 2, Night 3, etc.

So, you have to ask yourself, what tool can accomplish this? Since we're dealing with Triggers you should be thinking about Events, Conditions, Actions, and Variables. In this case we can focus on the Variable first.

You've already written down the type of variable you need in your post -> "Night 1", the number 1 is an Integer:
  • Set Variable Night_Cycles = 1
So now that you have a variable which tracks the current "night cycle", you need to figure out how to detect when it becomes Night. Funnily enough, I made a day/night system for you in this thread a little while ago: Is there a way to make a player team sleep like creeps do?

So now you just need to use that system to increase the number of Night cycles whenever it becomes Night time:
  • Night Has Started
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night_Time Equal to True
    • Actions
      • Set Variable Night_Cycles = (Night_Cycles + 1)
      • -------- You can use this variable to determine what to do next --------
This is also a good time to setup your Night time predators. When you want to ask questions in your Actions you use the If Then Else action:
  • Set Variable Night_Cycles = (Night_Cycles + 1)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Night_Cycles Equal to 3
    • Then - Actions
      • Trigger - Run Third Night <gen> (ignoring conditions)
    • Else - Actions
The Run trigger in this example would include all of your "Night 3" logic.

But a Trigger array variable would be even better here since it helps keep things organized and scales infinitely:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set Variable Night_Trigger[1] = First Night <gen>
    • Set Variable Night_Trigger[2] = Second Night <gen>
    • Set Variable Night_Trigger[3] = Third Night <gen>
  • Night Has Started ADVANCED
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night_Time Equal to True
    • Actions
      • Set Variable Night_Cycles = (Night_Cycles + 1)
      • Trigger - Run Night_Trigger[Night_Cycles] (ignoring conditions)
Now every time it becomes Night, the Night_Cycles variable will increase by 1, and it's associated Night_Trigger that we setup beforehand will run. First Night, Second Night, and Third Night would be their own triggers which have Actions for doing anything you want. This could involve removing existing daytime units and creating new nighttime units (predators). Each trigger is unique so you can customize each Night to your liking.

Taking this further, you can introduce other Array variables and create a sort of automated system which can alleviate you from creating redundant triggers:
  • Actions
    • Unit - Create Night_Spawn_Count[Night_Cyles] Night_Spawn_Type[Night_Cycles] for Neutral Hostile at (Random point in (Playable map area))
Night_Spawn_Count is an Integer array. Night_Spawn_Type is a Unit-Type array. These would get setup along with Night_Trigger[1] -> [3].
So Night_Spawn_Type[1] could be a couple of foxes where as Night_Spawn_Type[3] could be a wild pack of coyotes.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
1) Your TOD trigger isn't running any of the Night triggers (First, Second, Third). Nothing will happen if you never run them:
  • TOD
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night Equal to True
    • Actions
      • Set VariableSet NightCycles = (NightCycles + 1)
      • Trigger - Run Nighttimes[NightCycles] (ignoring conditions)

2) You don't need this Condition in any of the Night triggers since we know for a fact that we're running the correct trigger:
  • Conditions
    • NightCycles Equal to 3

3) You're referencing a variable called RandomPt but I don't see it being set anywhere:
  • Unit - Create 1 Raging Bear (Level 2) for Player 7 (Green) at RandomPt facing (Random angle) degrees
If you wanted this to be random each time you would need to set it again or just use the (Random point) function.


4) If it still doesn't work after these fixes then you may have failed to import the Time Of Day system correctly.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
1) Your TOD trigger isn't running any of the Night triggers (First, Second, Third). Nothing will happen if you never run them:
  • TOD
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night Equal to True
    • Actions
      • Set VariableSet NightCycles = (NightCycles + 1)
      • Trigger - Run Nighttimes[NightCycles] (ignoring conditions)

2) You don't need this Condition in any of the Night triggers since we know for a fact that we're running the correct trigger:
  • Conditions
    • NightCycles Equal to 3

3) You're referencing a variable called RandomPt but I don't see it being set anywhere:
  • Unit - Create 1 Raging Bear (Level 2) for Player 7 (Green) at RandomPt facing (Random angle) degrees
If you wanted this to be random each time you would need to set it again or just use the (Random point) function.


4) If it still doesn't work after these fixes then you may have failed to import the Time Of Day system correctly.
I ended up deleting my message after I noticed like an idiot I hadn't added Run Trigger function to TOD but seems it didn't fix the issue after I caught the blunder. I'll try fixing that RandomPt thing next and see if the clears up the spawning issue. I will also omit the unneeded condition stuff as well too.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
I ended up deleting my message after I noticed like an idiot I hadn't added Run Trigger function to TOD but seems it didn't fix the issue after I caught the blunder. I'll try fixing that RandomPt thing next and see if the clears up the spawning issue. I will also omit the unneeded condition stuff as well too.
Add something to the triggers that lets you know that they're actually running. Text Messages are very helpful here.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
That's a good idea, I'll try that.
When importing the TOD system you should not be creating anything yourself.

You literally copy the Folder called "TimeOfDay" from that example map and paste it into your own map. Everything is included and runs automatically.
tod.png

Also, do not rename any of the Variables that come with the system since they're used in the system's code.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
When importing the TOD system you should not be creating anything yourself.

You literally copy the Folder called "TimeOfDay" from that example map and paste it into your own map. Everything is included and runs automatically.
View attachment 483887
Also, do not rename any of the Variables that come with the system since they're used in the system's code.
I'll do that now. Sorry for not doing that from the getgo.
 
Level 5
Joined
Nov 17, 2022
Messages
84
When importing the TOD system you should not be creating anything yourself.

You literally copy the Folder called "TimeOfDay" from that example map and paste it into your own map. Everything is included and runs automatically.
View attachment 483887
Also, do not rename any of the Variables that come with the system since they're used in the system's code.
1724229923453.png

I copy pasted the folder into my map, made sure nothing was edited as well. But seems this error message appeared and since I don't understand coding, I am unsure what I did wrong to cause it to happen or how to prevent it.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
View attachment 483888
I copy pasted the folder into my map, made sure nothing was edited as well. But seems this error message appeared and since I don't understand coding, I am unsure what I did wrong to cause it to happen or how to prevent it.
You need to:
1) Enable JassHelper. There's a menu for it in the Trigger Editor. This SHOULD fix everything.
2) Delete any TOD_ variables that you may have created before. No two variables can share the same name which can mess things up.
3) Make sure that the TimeOfDay folder is at the very top of your trigger editor.
4) Make sure that your map isn't on Lua mode. I'm 99.99% sure you aren't.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
You need to:
1) Enable JassHelper. There's a menu for it in the Trigger Editor. This SHOULD fix everything.
2) Delete any TOD_ variables that you may have created before. No two variables can share the same name which can mess things up.
3) Make sure that the TimeOfDay folder is at the very top of your trigger editor.
4) Make sure that your map isn't on Lua mode. I'm 99.99% sure you aren't.
Seems enabling JassHelper fixed it, the error message is gone now when I save my map.
 
Level 5
Joined
Nov 17, 2022
Messages
84
You need to:
1) Enable JassHelper. There's a menu for it in the Trigger Editor. This SHOULD fix everything.
2) Delete any TOD_ variables that you may have created before. No two variables can share the same name which can mess things up.
3) Make sure that the TimeOfDay folder is at the very top of your trigger editor.
4) Make sure that your map isn't on Lua mode. I'm 99.99% sure you aren't.
1724274315427.png


  • TOD
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night_Time Equal to True
    • Actions
      • Game - Display to (All players) the text: Night [Insert Numbe...
      • Set VariableSet NightCycles = (NightCycles + 1)
      • Trigger - Run Night Trigger <gen> (ignoring conditions)
Okay so good news, it seems to be working since its running the trigger here finally. Though no predators spawned on the first night still. So defs an error on my end that is happening.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
Well, you're not using a Trigger array variable like you had originally and you're running the wrong trigger. Try to follow this logic:


This trigger runs at the very start of the map. It keeps track of our different Night triggers inside of a Trigger array variable called Nighttimes. This basically assigns a "Night Cycle" number to each trigger:
  • Night Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Nighttimes[1] = First Night <gen>
      • Set VariableSet Nighttimes[2] = Second Night <gen>
      • Set VariableSet Nighttimes[3] = Third Night <gen>

This trigger runs whenever it becomes night time. It then runs one of the triggers that we Set above based on the value of NightCycles (1, 2, 3, etc):
  • Night Started
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night_Time Equal to True
    • Actions
      • Set VariableSet NightCycles = (NightCycles + 1)
      • Game - Display to (All players) the text: Night + (String(NightCycles))
      • Trigger - Run Nighttimes[NightCycles] (ignoring conditions)

Then in your various Night triggers you would create your units at random points:
  • First Night
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10 do (Actions)
        • Loop - Actions
          • Unit - Create 1 Giant Wolf for Player 7 (Green) at (Random point in (Playable map area)) facing (Random angle) degrees
          • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
          • Unit Group - Add (Last created unit) to Wolf_Group
          • Game - Display to (All players) the text: Created a + (Name of (Last created unit))
^ I'm creating 10 wolves at 10 random points in the map.

Obviously you don't NEED the Text Messages or that For each loop, just focus on getting the core logic setup.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
Well, you're not using a Trigger array variable like you had originally and you're running the wrong trigger. Try to follow this logic:


This trigger runs at the very start of the map. It keeps track of our different Night triggers inside of a Trigger array variable called Nighttimes. This basically assigns a "Night Cycle" number to each trigger:
  • Night Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Nighttimes[1] = First Night <gen>
      • Set VariableSet Nighttimes[2] = Second Night <gen>
      • Set VariableSet Nighttimes[3] = Third Night <gen>

This trigger runs whenever it becomes night time. It then runs one of the triggers that we Set above based on the value of NightCycles (1, 2, 3, etc):
  • Night Started
    • Events
      • Game - TOD_Event becomes Equal to 1.00
    • Conditions
      • TOD_Is_Night_Time Equal to True
    • Actions
      • Set VariableSet NightCycles = (NightCycles + 1)
      • Game - Display to (All players) the text: Night + (String(NightCycles))
      • Trigger - Run Nighttimes[NightCycles] (ignoring conditions)

Then in your various Night triggers you would create your units at random points:
  • First Night
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10 do (Actions)
        • Loop - Actions
          • Unit - Create 1 Giant Wolf for Player 7 (Green) at (Random point in (Playable map area)) facing (Random angle) degrees
          • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
          • Unit Group - Add (Last created unit) to Wolf_Group
          • Game - Display to (All players) the text: Created a + (Name of (Last created unit))
^ I'm creating 10 wolves at 10 random points in the map.

Obviously you don't NEED the Text Messages or that For each loop, just focus on getting the core logic setup.
I do have stuff set up for running the trigger like the arrays and the spawns linked to the night spawn triggers, being these things here below. I just didn't add it to my post like I should have, so I apologize for not clarifying that aspect. So its why I'm scratching my head since at least I THINK I copied what you instructed me to set up correctly.

EDIT: oh wait should I be adding that Integer A from 1 to 10 thing and loop? I didn't see that part.

EDIT 2: gonna add text to the spawns since realized hadn't done that during my test yet oops

Edit 3: nvm text never appeared

  • First Night
    • Events
    • Conditions
    • Actions
      • Unit - Create 7 Giant Wolf for Player 7 (Green) at (Random point in Region 003 <gen>) facing (Random angle) degrees
      • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
      • Unit Group - Add (Last created unit) to Wolf_Group
  • Second Night
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Brood Mother for Player 7 (Green) at (Random point in Region 003 <gen>) facing (Random angle) degrees
      • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
      • Unit Group - Add (Last created unit) to Spider_Group
  • Third Night
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Raging Bear (Level 2) for Player 7 (Green) at (Random point in Region 003 <gen>) facing (Random angle) degrees
      • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
      • Unit Group - Add (Last created unit) to Bear_Group
  • Night Trigger
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Nighttimes[1] = First Night <gen>
      • Set VariableSet Nighttimes[2] = Second Night <gen>
      • Set VariableSet Nighttimes[3] = Third Night <gen>
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
I do have stuff set up for running the trigger like the arrays and the spawns linked to the night spawn triggers, being these things here below. I just didn't add it to my post like I should have, so I apologize for not clarifying that aspect. So its why I'm scratching my head since at least I THINK I copied what you instructed me to set up correctly.

EDIT: oh wait should I be adding that Integer A from 1 to 10 thing and loop? I didn't see that part.

EDIT 2: gonna add text to the spawns since realized hadn't done that during my test yet oops

Edit 3: nvm text never appeared
Are you still struggling with this? I imagine you still aren't running the triggers properly.
 
Level 5
Joined
Nov 17, 2022
Messages
84
Are you still struggling with this? I imagine you still aren't running the triggers properly.
I am tbh.
And I probably am screwing up somewhere, I just can't seem to figure it out in my replica where I'm messing up the triggers 🤔
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
I could send you the map file if that's preferable, since could get a better look at the guts that way?
Whatever you're comfortable with.

You can use Pastebin to upload the map privately and then send me the link in a private message.
1724306335567.png

Or just click the "Attach files" button and upload it here.
 
Top