• 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.

Spawn attack

Status
Not open for further replies.
Level 2
Joined
Apr 4, 2023
Messages
4
Hello all

how do I make it so that when I spawn

EX:
4 peons player 9 attack player 1
4 peons player 10 attack player 2
" "player 11 go attack player 3 4

(it's for a map like zombie survival I want the defenders to defend with the same number of monsters, and I'll have a computer that will attack a player at random) << that u can forget is juste for u see why i want that
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Do you know how to create units? After a Unit is created using the Create Unit action you'll be able to access it using the (Last created unit) Event Response:
  • Actions
    • Unit - Create 1 Footman...
    • Unit - Order (Last created unit) to Attack-Move to (Center of some region)
You can choose from a Region, a Point variable, a Position of a unit, and many more functions as your destination.

But if you want to create multiple units at once:
  • Actions
    • Unit - Create 10 Footman...
You'll only be able to reference one of these Units with (Last created unit), so you'll need another method.

That's where you can use the (Last created unit group) Event Response:
  • Actions
    • Unit - Create 10 Footman...
    • Unit Group - Order (Last created unit group) to Attack-Move to (Center of some region)
This is a somewhat limited function and not really an ideal solution (I believe it's limited to 12 units at a time).

Instead you can use a Unit Group variable which gives you full control over your unit group:
  • Actions
    • Unit - Create 50 Footman...
    • Set Variable MyUnitGroup = (Units matching (Unit-type of (Matching unit) Equal to Footman)
    • Unit Group - Pick every unit in MyUnitGroup and do actions:
      • Loop - Actions
        • Unit - Add Critical Strike to (Picked unit)
        • Unit - Order (Picked unit) to Attack-Move to (Center of some region)
Here we've created 50 Footman, stored them in a Unit Group, then used the Pick Every Unit action to interact with all 50 of them at once. In this case we're Adding the Critical Strike ability to our units and ordering them to attack somewhere.

Now let's focus on our unit's destination. I would recommend using Point array variables as a way to track different areas in the map. These areas are where you want your units to attack towards. You could also use Region array variables if you wanted a bit more randomness as you could get a Random point from within a region.

Here's how you can do this using Point array variables which you set during the loading screen (before the game starts):
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set Variable AttackPoint[1] = (Center of Player1BaseRegion)
    • Set Variable AttackPoint[2] = (Center of Player2BaseRegion)
    • Set Variable AttackPoint[3] = (Center of Player3BaseRegion)
    • Set Variable AttackPoint[4] = (Center of Player4BaseRegion)
You can then reference these Points whenever you want, and do so randomly using the Random Integer Number math function:
  • Actions
    • Unit - Create 1 Footman...
    • Unit - Order (Last created unit) to Attack-Move to AttackPoint[(Random integer number between 1 and 4)]
This rolls a random number between 1 and 4 and then references either AttackPoint[1], [2], [3], or [4] depending on it's outcome. In this case it will make the unit have an equal chance to attack towards one of our four player's bases.
 
Last edited:
Level 2
Joined
Apr 4, 2023
Messages
4
ohh whaouuuu thank you so much for the time you spent writing this, yes I knew how to create units but your way is 100 times better I will put this in place.
Thank you again.
 
Status
Not open for further replies.
Top