• 🏆 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!

[Solved] units wont attack-move location

Status
Not open for further replies.
Level 4
Joined
Sep 11, 2018
Messages
74
It works for leader[1] but not leader[2]. For leader[2], followers won't attack move target location.
  • attackground
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to attacklocation dummy
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Casting unit) Equal to leader[(Integer A)]
            • Then - Actions
              • Set tempattackmoveloc[(Integer A)] = (Target point of ability being cast)
              • Unit Group - Pick every unit in followers[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Unit - Order (Picked unit) to Attack-Move To tempattackmoveloc[(Integer A)]
              • Custom script: call RemoveLocation( udg_tempattackmoveloc[bj_forLoopAIndex])
            • Else - Actions
 
That would be because the location is removed before the second time the loop executes. My guess is that
  • (Target point of ability being cast)
generates a handle once per spell event, and in subsequent calls to that function, it will return the same handle, at least for that thread.

In short, the location is referenced, destroyed and referenced again, and at that point, it practically does not exist by the time leader[2] is around.
 
Things like group, unit, boards, etc etc, need to be created before they can be used.

For GUI arrays, the default setting is to create up to index 1, so unit group variable followers[0], and followers[1] would be normal useable.
But when working with a not-yet created group, like followers[2], it won't work, because followers[2] is literally null. It would be like trying order a unit "No Unit" to attack something, and just nothing will happen.

So the solution is to create a group for the array followers[] variable, if it does not exist, yet. Otherwise units can't be added properly, and you can't use it as a group.
One solution would to use a short custom script line, example:
  • Custom script: if udg_followers[2] == null then
  • Custom script: set udg_followers[2] = CreateGroup()
  • Custom script: endif
^this would be need done before you add units to the group, somewhere at map start or so. It would create followers[2] group.
 
Last edited:
Level 4
Joined
Sep 11, 2018
Messages
74
If you mean addgroup trigger then here it is:
  • addgroup
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to addunittogroup dummy
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Casting unit) Equal to leader[(Integer A)]
            • Then - Actions
              • Set tempfollower[(Integer A)] = (Target unit of ability being cast)
              • Special Effect - Create a special effect attached to the overhead of tempfollower[(Integer A)] using Effect_MechanicGear1.mdl
              • Set tempfx[(Integer A)] = (Last created special effect)
              • Special Effect - Destroy tempfx[(Integer A)]
              • Unit - Change ownership of tempfollower[(Integer A)] to Player 2 (Blue) and Change color
              • Unit Group - Add tempfollower[(Integer A)] to followers[(Integer A)]
              • Unit - Order tempfollower[(Integer A)] to Right-Click leader[(Integer A)]
            • Else - Actions
 
Level 4
Joined
Sep 11, 2018
Messages
74
  • init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set leader[1] = Paladin 0023 <gen>
      • Set leader[2] = Archmage 0025 <gen>
      • Game - Set the time of day to 12.00
      • Game - Turn the day/night cycle Off
      • Custom script: if udg_followers[2] == null then
      • Custom script: set udg_followers = CreateGroup()then
      • Custom script: endif
This gives me syntax error unexpected "then"?
 
Level 4
Joined
Sep 11, 2018
Messages
74
After renaming it to Custom script: set udg_followers[2] = CreateGroup() it works. What if there are more groups? Let's say 7 followers groups. Do I need to do this 5 more times? O r do I use 'For each integer A' in script form? I got no idea how to do that.
 
Level 4
Joined
Sep 11, 2018
Messages
74
I used this and it works. Thanks for the help!
  • For each (Integer A) from 2 to 3, do (Actions)
    • Loop - Actions
      • Custom script: if udg_followers[bj_forLoopAIndex] == null then
      • Custom script: set udg_followers[bj_forLoopAIndex] = CreateGroup()
      • Custom script: endif
 
You're welcome. Using the CreateGroup() inside a if == null block is actually also only a tequnique if you create/destroy groups dynamically, randomly during the game. If you never destroy and recreate the groups, you can just come along with no extra checks:
  • For each (Integer A) from 2 to 3, do (Actions)
  • Loop - Actions
    • Custom script: set udg_followers[bj_forLoopAIndex] = CreateGroup()
.. and the "== null" extra check would prevent to run the group creation, if a group already exists.

Edit:

Or then, if you really already know the exact number, like for example up to index [3], then you might increase the setting of the variable to initialisize up to "3", then it would work, too. Inside the variable settings in variable editor, for your variable.
Most of time this is not best solution, but for this case if you always need only 3, and never destroy them, it would work good, too.
 
Status
Not open for further replies.
Top