[Solved] Need a little help working with Unit Indexer for Tower Defense Game

Level 9
Joined
Mar 17, 2016
Messages
153
Hello,

I think I have a very simple question and need help with this. I have Bribe's Unit Indexer and am hoping to have it help me accomplish this easily.

I'm making a TD and I want it so that every time a unit enters a region the system will track the amount of regions they have been in with a variable.
Basically, if someone blocks and the units decide to attack, I want to be able to reset their paths independently. So Ideally every time they enter a new region(checkpoint) they will get +1 attached to them, and when someone blocks and they attack, when the units kill the blocking tower they will all get picked and ordered to move to "Point[Array]" and the array being aligned with the tracking number (+1) I was referring to. Meaning they will resume travelling on their designated paths.

I know this is easy with like a hashtable or maybe just an array but I do not know how to do it.


Edit: Maybe im overthinking it and there's an easier way, if this is the case I hope someone tells me
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
That's pretty simple, you detect when a unit enters a Region and assign them a number based on it:
  • Events
    • Unit - A unit Enters (Region Red1 <gen>)
  • Conditions
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CV = (Custom value of MyUnit)
    • Set Variable Unit_Destination[CV] = 2
    • Unit - Order MyUnit to Move-To Red_Point[Unit_Destination[CV]]
Red_Point is a Point array variable which would track the center of all of Player 1 (Red)'s regions:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set Variable Red_Point[1] = (Center of Red1 <gen>)
    • Set Variable Red_Point[2] = (Center of Red2 <gen>)
    • Set Variable Red_Point[3] = (Center of Red3 <gen>)
I think it's best to SET the Unit_Destination to a specific value rather than using Arithmetic to increase it, just in case the units somehow enter the same region more than once.

Then at any point in time you can do something like this to update their current order:
  • Actions
    • Unit Group - Pick every unit in RedEnemyUnits and do (Actions)
      • Loop - Actions
        • Set Variable MyUnit = (Picked unit)
        • Set Variable CV = (Custom value of MyUnit)
        • Unit - Order MyUnit to Move-To Red_Point[Unit_Destination[CV]]
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Thank you very much! seems to be working great so far. As always thank you for the help! :grin:
No problem.

On second thought, you could change Unit_Destination from an Integer array to a Point array. Then assign a reference to the Point directly:
  • Events
    • Unit - A unit Enters (Region Red1 <gen>)
  • Conditions
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CV = (Custom value of MyUnit)
    • Set Variable Unit_Destination[CV] = Red_Point[2]
    • Unit - Order MyUnit to Move-To Unit_Destination[CV]
  • Actions
    • Unit Group - Pick every unit in EnemyUnits and do (Actions)
      • Loop - Actions
        • Set Variable MyUnit = (Picked unit)
        • Set Variable CV = (Custom value of MyUnit)
        • Unit - Order MyUnit to Move-To Unit_Destination[CV]
This is more generic and thus more flexible since now every single enemy unit, regardless of whose "lane" they belong to, can be given the order without issue.
 
Top