• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] Simulating animal life cycle

Level 7
Joined
Jul 22, 2021
Messages
81
Hello,

Recently, I was trying to create and implement a system that simulates an "animal life cycle in the forest". It basically went like this:
1. At 6 am, units from the Day_Animals group spawn (unpaused & unhidden) at their Den region
2. Then they are randomly sent to various "patrol points", like PP1 -> PP4 -> PP2, etc. The unit should be sent to any randomly picked point upon his arrival, but I did a version where the sequence was always the same.
3. At 5:30 pm daytime units go to their den location, when they enter the region they're hidden & paused until 6 am.
4. At 6 pm units from the Night_Animals group were out of their own Den region and should follow essentially the same routine as daytime animals.
5. At 5:30 pm nighttime units go to their den location, when they enter the region they're hidden & paused until the night comes.
6. The cycle repeats.

  • I also took into consideration that animals might not get to their den for various reasons, so they were automatically moved to their respective den regions, hiddeen & paused - about 15 mins before the next "shift".
  • There is also an issue when a unit is attacked during their "patrol routine" they should stop their own patrol and fight combat, and if the combat is no longer occuring (timer checking 5 sec time if unit is attacked or sth?) then the unit goes back to their patrol.
  • Another thing is that when any unit died, then a new unit is created at the den & added to the group when the next day/night cycle starts. Possibly a new unit type is spawned then.

But I stumbled upon all sorts of weird bugs, like units from a given group didn't react to commands, they didn't hide/pause, etc. I'm kinda clueless about these issues.

Basically, what I'm asking for are answers with tips for most efficient, bug-free scripts/triggers or any tips based on my description. I will later try to recreate this system since I clearly did something wrong. I'm using Lua script language for my map (but I'm a newbie when it comes to Lua still). I even asked LLM tools for the script for my system but it didn't really worked as you can imagine.
When I get home, I can post you the triggers I've created that didn't work for me.

Thank you for reading through!
 
Unpaused and not hidden units tend to not take orders in two main cases:
a) There are too many units for the game to process. I tend to not give simultaneous orders to more than 100 units just for safety. Otherwise the order will be delayed, and they will stand for some time while game gets to them.
b) If order is given to a unit group that has more than 12 units, only first 12 units will follow the order. In such case it is better to pick each unit in unit group and order picked unit to do stuff.

Units not getting unhidden/unpaused tend to happen when unit is hidden but is not referred in an existing variable (in my experience, I may be wrong).
Each unit should be assigned to a unit variable (probably an array with a tracker for their amount, and for each integer a from 1 to x unhide unit[a]), or to a unit group (set unit group = units in region (unhidden ones, it may work wonky with hidden units), then later pick each unit in group and unhide picked unit).
Picking units in region while they are hidden may not work, even if you specify to pick hidden units, and similar issue may occur if you refer to an already hidden preplaced unit directly.
 
Units not getting unhidden/unpaused tend to happen when unit is hidden but is not referred in an existing variable (in my experience, I may be wrong).
Each unit should be assigned to a unit variable (probably an array with a tracker for their amount, and for each integer a from 1 to x unhide unit[a]), or to a unit group (set unit group = units in region (unhidden ones, it may work wonky with hidden units), then later pick each unit in group and unhide picked unit).
I did exactly that regarding creating array variable for each unit. I even unhidden/unpaused each unit first before giving a command but the issue still persisted.
Also note that sometimes units did hid and sometimes they did not.

Perhaps I should have first fire a trigger which unhides/unpauses each unit separately and then it runs another trigger (ignoring conditions) which gives a move command to (again) each unit separately?
 
I managed to pull something like this (triggers in the spoiler below), it seems to work fine, but I'm not sure how it would fare when I scale things up (more units, multiple places with similar logic, etc). I also created simple respawn logic where stronger animals will appear in the position of ones who were previously killed.
  • ForestUnits
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Day Animals --------
      • Unit - Create 1 Dark Troll for Player 5 (Yellow) at (Center of Day_Animals_Den <gen>) facing Default building facing degrees
      • Set VariableSet DayAnimal[1] = (Last created unit)
      • Unit - Pause DayAnimal[1]
      • Unit - Hide DayAnimal[1]
      • Unit Group - Add DayAnimal[1] to Day_Animals
      • Unit - Create 1 Dark Troll for Player 5 (Yellow) at (Center of Day_Animals_Den <gen>) facing Default building facing degrees
      • Set VariableSet DayAnimal[2] = (Last created unit)
      • Unit - Pause DayAnimal[2]
      • Unit - Hide DayAnimal[2]
      • Unit Group - Add DayAnimal[2] to Day_Animals
      • -------- Night Animals --------
      • Unit - Create 1 Knight for Player 5 (Yellow) at (Center of Night_Animals_Den <gen>) facing Default building facing degrees
      • Set VariableSet NightAnimal[1] = (Last created unit)
      • Unit - Pause NightAnimal[1]
      • Unit - Hide NightAnimal[1]
      • Unit - Create 1 Knight for Player 5 (Yellow) at (Center of Night_Animals_Den <gen>) facing Default building facing degrees
      • Set VariableSet NightAnimal[2] = (Last created unit)
      • Unit - Pause NightAnimal[2]
      • Unit - Hide NightAnimal[2]
      • -------- Regions --------
      • Set VariableSet Patrol_Point[1] = (Random point in PatrolPoint01 <gen>)
      • Set VariableSet Patrol_Point[2] = (Random point in PatrolPoint02 <gen>)
      • Player - Make Player 1 (Red) treat Player 5 (Yellow) as an Enemy
      • Player - Make Player 5 (Yellow) treat Player 1 (Red) as an Enemy
  • Day6 part1
    • Events
      • Game - The in-game time of day becomes Equal to 6.00
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Night_Animals and do (Actions)
        • Loop - Actions
          • Unit - Move (Picked unit) instantly to (Center of Night_Animals_Den <gen>)
      • Trigger - Turn off GoToDen Night <gen>
      • Trigger - Run Day Units Respawn <gen> (ignoring conditions)
  • Day6 part2
    • Events
    • Conditions
    • Actions
      • Unit - Unhide DayAnimal[1]
      • Unit - Unhide DayAnimal[2]
      • Unit - Unpause DayAnimal[1]
      • Unit - Unpause DayAnimal[2]
      • Unit - Order DayAnimal[1] to Attack-Move To (Random point in PatrolPoint01 <gen>)
      • Unit - Order DayAnimal[2] to Attack-Move To (Random point in PatrolPoint02 <gen>)
      • Trigger - Turn on PatrolRoutineDay <gen>
  • PatrolRoutineDay
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order DayAnimal[1] to Attack-Move To Patrol_Point[(Random integer number between 1 and 2)]
      • Unit - Order DayAnimal[2] to Attack-Move To Patrol_Point[(Random integer number between 1 and 2)]
  • Day17
    • Events
      • Game - The in-game time of day becomes Equal to 17.00
    • Conditions
    • Actions
      • Trigger - Turn off PatrolRoutineDay <gen>
      • Trigger - Turn on GoToDen Day <gen>
      • Wait 4.00 seconds
      • Unit - Order DayAnimal[1] to Attack-Move To (Center of Day_Animals_Den <gen>)
      • Unit - Order DayAnimal[2] to Attack-Move To (Center of Day_Animals_Den <gen>)
  • GoToDen Day
    • Events
      • Unit - A unit enters Day_Animals_Den <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Triggering unit) Equal to DayAnimal[1]
          • (Triggering unit) Equal to DayAnimal[2]
    • Actions
      • Unit - Pause (Triggering unit)
      • Unit - Hide (Triggering unit)
  • Night18 part 1
    • Events
      • Game - The in-game time of day becomes Equal to 18.00
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Day_Animals and do (Actions)
        • Loop - Actions
          • Unit - Move (Picked unit) instantly to (Center of Day_Animals_Den <gen>)
      • Trigger - Turn off GoToDen Day <gen>
      • Trigger - Run Night Units Respawn <gen> (ignoring conditions)
  • Night18 part 2
    • Events
    • Conditions
    • Actions
      • Unit - Unhide NightAnimal[1]
      • Unit - Unhide NightAnimal[2]
      • Unit - Unpause NightAnimal[1]
      • Unit - Unpause NightAnimal[2]
      • Unit - Order NightAnimal[1] to Attack Ground (Random point in PatrolPoint01 <gen>)
      • Unit - Order NightAnimal[2] to Attack Ground (Random point in PatrolPoint02 <gen>)
      • Trigger - Turn on PatrolRoutineNight <gen>
  • PatrolRoutineNight
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order NightAnimal[1] to Attack-Move To Patrol_Point[(Random integer number between 1 and 2)]
      • Unit - Order NightAnimal[2] to Attack-Move To Patrol_Point[(Random integer number between 1 and 2)]
  • Night5
    • Events
      • Game - The in-game time of day becomes Equal to 5.00
    • Conditions
    • Actions
      • Trigger - Turn off PatrolRoutineNight <gen>
      • Trigger - Turn on GoToDen Night <gen>
      • Wait 4.00 seconds
      • Unit - Order NightAnimal[1] to Attack-Move To (Center of Night_Animals_Den <gen>)
      • Unit - Order NightAnimal[2] to Attack-Move To (Center of Night_Animals_Den <gen>)
  • GoToDen Night
    • Events
      • Unit - A unit enters Night_Animals_Den <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Triggering unit) Equal to NightAnimal[1]
          • (Triggering unit) Equal to NightAnimal[2]
    • Actions
      • Unit - Pause (Triggering unit)
      • Unit - Hide (Triggering unit)
  • Day Units Respawn
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (DayAnimal[1] is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • DayAnimal_kill_count[1] Equal to 1
            • Then - Actions
              • Unit Group - Remove DayAnimal[1] from Day_Animals.
              • Unit - Create 1 Dark Troll Warlord for Player 5 (Yellow) at (Center of Day_Animals_Den <gen>) facing Default building facing degrees
              • Set VariableSet DayAnimal[1] = (Last created unit)
              • Unit - Pause DayAnimal[1]
              • Unit - Hide DayAnimal[1]
              • Unit Group - Add DayAnimal[1] to Day_Animals
            • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (DayAnimal[2] is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • DayAnimal_kill_count[2] Equal to 1
            • Then - Actions
              • Unit Group - Remove DayAnimal[2] from Day_Animals.
              • Unit - Create 1 Dark Troll Warlord for Player 5 (Yellow) at (Center of Day_Animals_Den <gen>) facing Default building facing degrees
              • Set VariableSet DayAnimal[2] = (Last created unit)
              • Unit - Pause DayAnimal[2]
              • Unit - Hide DayAnimal[2]
              • Unit Group - Add DayAnimal[2] to Day_Animals
            • Else - Actions
        • Else - Actions
      • Trigger - Run Day6 part2 <gen> (ignoring conditions)
  • Night Units Respawn
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (NightAnimal[1] is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NightAnimal_kill_count[1] Equal to 1
            • Then - Actions
              • Unit Group - Remove NightAnimal[1] from Night_Animals.
              • Unit - Create 1 Furbolg Shaman for Player 5 (Yellow) at (Center of Night_Animals_Den <gen>) facing Default building facing degrees
              • Set VariableSet NightAnimal[1] = (Last created unit)
              • Unit - Pause NightAnimal[1]
              • Unit - Hide NightAnimal[1]
              • Unit Group - Add NightAnimal[1] to Night_Animals
            • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (NightAnimal[2] is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NightAnimal_kill_count[2] Equal to 1
            • Then - Actions
              • Unit Group - Remove NightAnimal[2] from Night_Animals.
              • Unit - Create 1 Furbolg Shaman for Player 5 (Yellow) at (Center of Night_Animals_Den <gen>) facing Default building facing degrees
              • Set VariableSet NightAnimal[2] = (Last created unit)
              • Unit - Pause NightAnimal[2]
              • Unit - Hide NightAnimal[2]
              • Unit Group - Add NightAnimal[2] to Night_Animals
            • Else - Actions
        • Else - Actions
      • Trigger - Run Night18 part 2 <gen> (ignoring conditions)
  • AnimalKillCounts
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Dying unit) Equal to DayAnimal[1]
        • Then - Actions
          • Set VariableSet DayAnimal_kill_count[1] = (DayAnimal_kill_count[1] + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Dying unit) Equal to DayAnimal[2]
        • Then - Actions
          • Set VariableSet DayAnimal_kill_count[2] = (DayAnimal_kill_count[2] + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Dying unit) Equal to NightAnimal[1]
        • Then - Actions
          • Set VariableSet NightAnimal_kill_count[1] = (NightAnimal_kill_count[1] + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Dying unit) Equal to NightAnimal[2]
        • Then - Actions
          • Set VariableSet NightAnimal_kill_count[2] = (NightAnimal_kill_count[2] + 1)
        • Else - Actions
 
Back
Top