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

Auto battle

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
I'm thinking about making an auto battle map, in example, Dota 2 Autochess, league TFT etc. But i'm having trouble trying to figure out the best possible way to save each players unit and their items and re-creating them each round. Can i get som help on how you do that?
 
Last edited:

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,560
If the units are all Heroes then you don't really need to worry about too much. You can use the Revive function to bring them back from the dead and Heroes already retain their Items and what not when they die.

For the positions of these units think of the player's area as a grid that consists of tiles, basically like a Chess board. You could then use Point variables or Regions in order to store the center of each tile, this way you can easily move your units around on these tiles.
  • Unit - Move some unit instantly to center of Player1_Tile[5]

You'd use a Hashtable to store these Regions or Points so that you don't have to create a separate array for each player. Instead you would save the Regions/Points in the Hashtable using the Player's number as the Parent key. This type of design allows you to create one trigger that works for every player instead of having to rely on multiple triggers for each player or a long list of If Then Else statements -> Is it player 1's tile? Is it player 2's tile? etc.

You would then use Hashtables to link the Regions/Points to the units (Unit Indexing (link in my signature) is possible as well). This data would be stored directly to the unit so that as long as you have access to a unit you also have access to which Region/Point it originally started on. When you move a unit to a new Region/Point during the "setup" phase you would update this saved data so that they're no longer linked to their old Region/Point and instead linked to their new Region/Point.

Edit: On second thought you'd probably just want to use Regions instead of Points since these are easier to work with. It's a bit annoying placing so many Regions and storing them to Variables but Regions allow you to do things like check if a Point is within one, which is useful for moving units around the grid.

I would probably use Events to interrupt the unit's orders during the "setup" phase. This way you can still select your units, level up their abilities, equip items, etc. but you can't cast their spells or anything like that. You would also want to detect when the player wants to move the unit to a different tile, which could be done using an Ability or with the Move/Smart order. You may have to Silence the units in order to prevent them from casting spells.

I'm writing this trigger from memory so it will look weird:
  • Events:
  • Unit - A unit is issued an order targeting a point
  • Conditions:
  • SetupPhase[player number of (Owner of Triggering unit)] Equal to True
  • (Issued order) Equal to "move" OR "smart"
  • Actions:
  • Set Variable TargetPoint = Target point of issued order
  • Get the closest Region/Point to where you issued the order (TargetPoint) -> Instantly move the unit there -> Link this new Region/Point to the unit
Getting the closest Region/Point can be a little tricky. For Regions you can enumerate over an array of Regions, checking if the target point of issued order is within each one. If the target point is within the Region then you've found your Region and can proceed from there.

Since controlling units during the "battle" phase is prohibited you would probably want to change the Owner of the units to a computer player that is allied to the user and hostile towards their opponents. The trick here would be to design your systems around these computers so that gold/rewards are distributed to the player and not their cpu AI ally.

This is just a rough idea, there's a lot of tricks and techniques that can be used to achieve this type of game. I would look into how to design a game like Castle Fight or Legion TD, I'm sure there's some posts on Hive about this.

Some random things that can be useful for this type of game:
  • Ward Classification -> Prevents you from accessing a unit's command card.
  • Allied Shop Sharing (I think this is the name of the ability?) -> Should allow you to select allied units (computer) and view their command card.
  • Pause/Unpause action -> Allows you to completely disable/enable a unit.
    • Custom script: call BlzPauseUnitEx(udg_YourUnit, true)
    This is a triggered Stun, true = stun unit, false = unstun unit. udg_YourUnit would be a Unit variable. You can rename this variable to whatever you want but make sure to update the custom script to match it.
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
If the units are all Heroes then you don't really need to worry about too much. You can use the Revive function to bring them back from the dead and Heroes already retain their Items and what not when they die.

For the positions of these units think of the player's area as a grid that consists of tiles, basically like a Chess board. You could then use Point variables or Regions in order to store the center of each tile, this way you can easily move your units around on these tiles.
  • Unit - Move some unit instantly to center of Player1_Tile[5]

You'd use a Hashtable to store these Regions or Points so that you don't have to create a separate array for each player. Instead you would save the Regions/Points in the Hashtable using the Player's number as the Parent key. This type of design allows you to create one trigger that works for every player instead of having to rely on multiple triggers for each player or a long list of If Then Else statements -> Is it player 1's tile? Is it player 2's tile? etc.

You would then use Hashtables to link the Regions/Points to the units (Unit Indexing (link in my signature) is possible as well). This data would be stored directly to the unit so that as long as you have access to a unit you also have access to which Region/Point it originally started on. When you move a unit to a new Region/Point during the "setup" phase you would update this saved data so that they're no longer linked to their old Region/Point and instead linked to their new Region/Point.

Edit: On second thought you'd probably just want to use Regions instead of Points since these are easier to work with. It's a bit annoying placing so many Regions and storing them to Variables but Regions allow you to do things like check if a Point is within one, which is useful for moving units around the grid.

I would probably use Events to interrupt the unit's orders during the "setup" phase. This way you can still select your units, level up their abilities, equip items, etc. but you can't cast their spells or anything like that. You would also want to detect when the player wants to move the unit to a different tile, which could be done using an Ability or with the Move/Smart order. You may have to Silence the units in order to prevent them from casting spells.

I'm writing this trigger from memory so it will look weird:
  • Events:
  • Unit - A unit is issued an order targeting a point
  • Conditions:
  • SetupPhase[player number of (Owner of Triggering unit)] Equal to True
  • (Issued order) Equal to "move" OR "smart"
  • Actions:
  • Set Variable TargetPoint = Target point of issued order
  • Get the closest Region/Point to where you issued the order (TargetPoint) -> Instantly move the unit there -> Link this new Region/Point to the unit
Getting the closest Region/Point can be a little tricky. For Regions you can enumerate over an array of Regions, checking if the target point of issued order is within each one. If the target point is within the Region then you've found your Region and can proceed from there.

Since controlling units during the "battle" phase is prohibited you would probably want to change the Owner of the units to a computer player that is allied to the user and hostile towards their opponents. The trick here would be to design your systems around these computers so that gold/rewards are distributed to the player and not their cpu AI ally.

This is just a rough idea, there's a lot of tricks and techniques that can be used to achieve this type of game. I would look into how to design a game like Castle Fight or Legion TD, I'm sure there's some posts on Hive about this.

Some random things that can be useful for this type of game:
  • Ward Classification -> Prevents you from accessing a unit's command card.
  • Allied Shop Sharing (I think this is the name of the ability?) -> Should allow you to select allied units (computer) and view their command card.
  • Pause/Unpause action -> Allows you to completely disable/enable a unit.
    • Custom script: call BlzPauseUnitEx(udg_YourUnit, true)
    This is a triggered Stun, true = stun unit, false = unstun unit. udg_YourUnit would be a Unit variable. You can rename this variable to whatever you want but make sure to update the custom script to match it.
Thank you very much for the detailed "introduction". This will help me a lot, although, my knowledge for hashtable is very poor since i've never used it before while maping. So i gues my start will be to learn about them and proceed from there. :)
 
Last edited:
Status
Not open for further replies.
Top