• 🏆 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] Random wildlife

Status
Not open for further replies.
Level 2
Joined
Feb 27, 2014
Messages
18
Hello people of hive! I have problems with random wild life spawn.

I need animals to spawn randomly all over the map. I know how to make them spawn, but i also want them to despawn again.

My spawn trigger looks like this, if you're curious:
  • Spawning animals
    • Events
      • Game - The in-game time of day becomes Equal to 6.00
    • Conditions
    • Actions
      • Unit - Create 30 Wolf for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
      • Unit - Create 30 Deer for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
      • Unit - Create 30 Rabbit for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
Wietlol's question is actually quite fundamental. Nevertheless the easiest would certainly be creating a loop and creating the animals one by one and attaching an expiration time to each of them. It leaks anyway at the moment, so it is not worse.

Guess, we have to wait for the details first though.
 
Level 3
Joined
Oct 27, 2016
Messages
34
Firstly, if you do it like that, all of the animals will spawn in the exact same place. The "random location" picks one location to spawn all thirty. You'll want to have many different actions creating one animal each at the same time in random locations (exactly what you already did, but multiples of each one with much smaller numbers).

Secondly, if you want them to despawn, you'll probably want to do a "pick all units and do action/multiple actions" trigger. It's under the "Unit Group" category in the Action menu. Once you do that, you can "remove picked unit" and it will remove every unit you told it to pick. You can pick by unit type, which player owns the unit, by being a unit rather than a structure, or even what area the unit is in, all from this trigger. Good luck!

EDIT: there are much more complex and robust ways to do a despawn that will create more dynamic and, dare I say, emergent game play, but I'll leave you with a simple start for now.
 
Level 6
Joined
Dec 6, 2009
Messages
168
Here you go. A Animal spawn trigger and a despawn one.

  • Animal Spawn
    • Events
      • Game - The in-game time of day becomes Equal to 6.00
    • Conditions
    • Actions
      • Custom script: set udg_Group = CreateGroup()
      • For each (Integer A) from 1 to 30, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Rabbit for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Group
      • For each (Integer A) from 1 to 30, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Sheep for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Group
      • For each (Integer A) from 1 to 30, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Chicken for Neutral Hostile at (Random point in (Playable map area)) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Group


  • Animal Despawn
    • Events
      • Game - The in-game time of day becomes Equal to 5.50
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Group and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
          • Unit Group - Remove (Picked unit) from Group
      • Custom script: call DestroyGroup(udg_Group)
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
Instead of despawning units just for them to instantly respawn, consider only spawning replacements for those that were removed.

This stops the annoying time during gameplay where you just found/nearly kill a unit for it to be despawned and new ones are spawned possibly nowhere near you due to RNG. Instead the unit should remain unchanged, with only those that were removed (killed etc) being respawned.
 
Status
Not open for further replies.
Top