Memorizing Locations and Units

Status
Not open for further replies.
Level 1
Joined
Jan 24, 2014
Messages
6
Hey everyone,

I'm trying to create a situation like this. For example I have a Builder unit and I order him to build a Tower. After the Tower is finished a Footman is spawned (created by triggers of course) near the Tower. What I want is that both the Unit (Footman) and the Building (Tower) would be memorized so I could issue an order to the Footman later via trigger, for all testing purposes by ESC button or chat message, to return to the Tower he was created near. But I want this to be dynamic in a way that If I create another Tower and another Footman is spawned, later when I issue an order they both go back, no matter where they are on the map, to their respective Towers. I tried doing this by playing with arrays. For example first Footman would be Unit[IntA] and the Tower Building[IntA]. The default value for integer IntA would be 1 (So they both would be Unit[1] and Building[1]). After they both would be created I would increase IntA by one. So if I build another Tower, another Footman is spawned and they, at least in theory, should be Unit[2] and Building[2] because IntA integer is increased etc.

  • Testing Create
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to (==) Scout Tower
    • Actions
      • Set Building[IntA] = (Triggering unit)
      • Unit - Create 1 Footman for (Owner of Building[IntA]) at (Position of Building[IntA]) facing Default building facing (270.0) degrees
      • Set Unit[IntA] = (Last created unit)
      • Set IntA = (IntA + 1)
And I'm not sure how to call them so I did something like this:

  • Testing Order Back
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer IntA) from 1 to 10, do (Actions)
        • Loop - Actions
          • Unit - Order Unit[IntA] to Right-Click Building[IntA]
I'm not sure if this is the way to do it. 'Cause in this case only the Footman that was created first time seems to respond. And If I build the Tower again and again, second and third Footmen do not respond to this at all and yes, there are leaks here but I'm just testing the idea itself.

If there would be any suggestions on how to make it would be helpful. Both regular Triggers and Jass are OK. :)
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
This is essentially an indexing task.
I recommend getting a unit indexer. It changes the custom value of every unit to something unique when the unit is created. You can use those values as array indexes to do something like:
set owner[footman] to peasant
set owner[peasant] to footman

The owner array is just an example. It could be anything. I hope you get the idea.
 
Level 14
Joined
Aug 30, 2004
Messages
909
You can do the indexing yourself. When you create the footman and tower, use the action that says "Set Unit's Custom Value" or something like that. Set the custom value to the integer, e.g. your first peasant and tower would be 1.

Later, to reference the footman you can look up their custom value, e.g. set TempInteger = custom value of (triggering unit) or whatever.

The only problem is that if you have a ton of towers and peasants the counter can get very high. There are ways around that, but if you don't have 1000 towers I wouldn't worry about it.
 
Status
Not open for further replies.
Top