Reassigning Unit Arrays (the efficient way) - A little help!

Razed

New Member
Reaction score
44
Dear thehelper.net members,

In my map I have a central base for players. A "safe-haven". Therefore the settlement is guarded by friendly unit, whom become hostile once you wage war in the city (and WILL attack you until your death (or theirs)). I can imagine that when player progress in my level, they may become powerful enough to take down some guards for the fun of it. Therefore I created a revival trigger for the guards (see below).

The trigger works fine, the first time a guard dies... but apparently the two times "Set Variable" after creating the unit fail to do their job. Because if that same guard dies another time, it's a permanent one - poor guard :(. I thought this was way more efficient than to set the variable for each guard separately, but I guess I missed something at the reassigning of the units when they "revive".

Thoughts?

Code:
Guard Revival
    Events
        Unit - A unit owned by Player 6 (Orange) Dies
    Conditions
    Actions
        For each (Integer A) from 0 to 22, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Dying unit) Equal to Guards_Unit_First[(Integer A)]
                    Then - Actions
                        Set Temp_Point = Guards_Return_Point[(Integer A)]
                        Unit - Create 1 (Unit-type of (Dying unit)) for Player 6 (Orange) at Temp_Point facing 270.00 degrees
                        Custom script:   call RemoveLocation (udg_Temp_Point)
                        Set Guards_Unit_First[(Integer A)] = (Last created unit)
                        Set Guards_Return_Point[(Integer A)] = (Position of (Last created unit))
                        Set Temp_Point = Guards_Return_Point[(Integer A)]
                        Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
                        Special Effect - Destroy (Last created special effect)
                        Custom script:   call RemoveLocation (udg_Temp_Point)
                    Else - Actions

Variables:
Guards_Unit_First [Array] = Each guard assigned to an array at the map initialization (23 guards in total as you can see).
Guards_Return_Point [Array] = The static position of each guard, also assigned at initialization.

Above variables all line up perfectly, for the sake of order. So for example:
Guard 1 has Guards_Unit_First[0] and Guards_Return_Point[0]
Guard 2 has Guards_Unit_First[1] and Guards_Return_Point[1]
 

Kayoss666

Member
Reaction score
7
Trigger:
  • Guard Revival
    • Events
      • Unit - A unit owned by Player 6 (Orange) Dies
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 22, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Dying unit) Equal to Guards_Unit_First[(Integer A)]
            • Then - Actions
              • Set Temp_Point = Guards_Return_Point[(Integer A)]
              • Unit - Create 1 (Unit-type of (Dying unit)) for Player 6 (Orange) at Temp_Point facing 270.00 degrees
              • Custom script: call RemoveLocation (udg_Temp_Point)
              • Set Guards_Unit_First[(Integer A)] = (Last created unit)
              • Set Guards_Return_Point[(Integer A)] = (Position of (Last created unit))
              • Set Temp_Point = Guards_Return_Point[(Integer A)]
              • Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
              • Special Effect - Destroy (Last created special effect)
              • Custom script: call RemoveLocation (udg_Temp_Point)
            • Else - Actions


sorry wanted to see it in trigger form

okay i have made a lot of revive triggers and this should work. unless the problem is in the custom scripts i just got the position of each at the beginning of the game and used those to avoid remove location.

but i would also change
Trigger:
  • EventPart
    • Events
      • Unit - A unit owned by Player 6 (Orange) Dies
    • Conditions
to
Trigger:
  • EventPart
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Dying unit)) Equal to Player 6 (Orange)
 

Razed

New Member
Reaction score
44
Kayoss666, thank you for replying.

I tried your option as well. Same result.

I can confirm that the reassigning works like intended (through other triggers where I also use the unit arrays). So that leaves us with the problem that the "reviving" doesn't work the second time. This is really so confusing, I don't know how to fix it..
 

Kayoss666

Member
Reaction score
7
Well unless i am just over looking it this revive works. unless somewhere in the rest of your code you change Guards_Unit_First[NUMBER] i really say that this code should work
 

Razed

New Member
Reaction score
44
Problem solved! After trial and error I noticed that everything worked fine, expect for the "Guards_Return_Point[(Integer A)]". It didn't create a new unit because it couldn't find the location to do so (it seems "call RemoveLocation (udg_Temp_Point) also clears Guards_Return_Point from its value). Therefore I added the last line to my trigger (see below) and everything works like intended!

Thanks for the help Kayoss666, +rep.

Code:
Guard Revival
    Events
        Unit - A unit Dies
    Conditions
        (Owner of (Dying unit)) Equal to Player 6 (Orange)
    Actions
        For each (Integer A) from 0 to 22, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Dying unit) Equal to Guards_Unit_First[(Integer A)]
                    Then - Actions
                        Set Temp_Point = Guards_Return_Point[(Integer A)]
                        Unit - Create 1 (Unit-type of Guards_Unit_First[(Integer A)]) for Player 6 (Orange) at Temp_Point facing 270.00 degrees
                        Custom script:   call RemoveLocation (udg_Temp_Point)
                        Set Guards_Unit_First[(Integer A)] = (Last created unit)
                        Set Guards_Return_Point[(Integer A)] = (Position of (Last created unit))
                        Set Temp_Point = Guards_Return_Point[(Integer A)]
                        Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
                        Special Effect - Destroy (Last created special effect)
                        Custom script:   call RemoveLocation (udg_Temp_Point)
                        Set Guards_Return_Point[(Integer A)] = (Position of (Last created unit))
                    Else - Actions
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top