• 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.

[Trigger] **System Bug Fix**

Status
Not open for further replies.
Level 9
Joined
Aug 1, 2008
Messages
453
I've been working on a TD, and was about to stop because i couldn't find a way to fix some of the bugs in my trigger (The unique part of the game). But before i quit it i decided to ask the fellow members of the hive for some help :grin::grin:.

The 3 bugs I've found.

1. the unit does not move back to the middle of the tower all the time.

2. the unit will chase units down, when they come within the radius and leave, but he'll return when they die.

3. If the unit can keep attacking units nonstop he will keep moving forward, even if they leave the area of the tower.

Here's the triggers that have to do with this part of the system.

  • Create
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to |cff000000a |cffBB9910Lv. 1 Soldier (Building)
    • Actions
      • Unit - Turn collision for (Constructed structure) Off
      • Unit - Set level of Soldier Information (Dummy) for (Constructed structure) to (Point-value of (Constructed structure))
      • Set Int_Towers[(Player number of (Owner of (Constructed structure)))] = (Int_Towers[(Player number of (Owner of (Constructed structure)))] + 1)
      • Set Temp_Pos[1] = (Position of (Constructed structure))
      • Set Customvalue[1] = (Customvalue[1] + 2)
      • Set Positionoftower[(Customvalue[1] - 1)] = (Position of (Constructed structure))
      • Unit - Create 1 |cffBB9910Lv. 1 Soldier (Unit) for (Owner of (Constructed structure)) at Temp_Pos[1] facing Default building facing degrees
      • Unit - Set the custom value of (Last created unit) to Int_Towers[Customvalue[1]]
      • Unit - Set the custom value of (Constructed structure) to Int_Towers[Customvalue[1]]
      • Custom script: call RemoveLocation( udg_Temp_Pos[1] )
  • Tower Limits
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • -------- Level 1 Towers --------
      • -------- Level 1 Towers --------
      • -------- Level 1 Towers --------
      • Set Temp_Group[1] = (Units of type |cff000000a |cffBB9910Lv. 1 Soldier (Building))
      • Unit Group - Pick every unit in Temp_Group[1] and do (Actions)
        • Loop - Actions
          • Set Temp_Unit[1] = (Picked unit)
          • Set Temp_Pos[1] = (Position of (Picked unit))
          • Set Temp_Group[2] = (Units within 600.00 of Temp_Pos[1])
          • Set Temp_Interger = ((Custom value of (Picked unit)) - 1)
          • Unit Group - Pick every unit in Temp_Group[2] and do (Actions)
            • Loop - Actions
              • Set Temp_Pos[2] = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Picked unit)) Equal to (Custom value of Temp_Unit[1])
                  • (Distance between Temp_Pos[1] and Temp_Pos[2]) Greater than or equal to 300.00
                • Then - Actions
                  • Unit - Order (Picked unit) to Move To Positionoftower[Customvalue[Temp_Interger]]
                • Else - Actions
          • Custom script: call DestroyGroup( udg_Temp_Group[2] )
          • Custom script: call RemoveLocation( udg_Temp_Pos[1] )
      • Custom script: call DestroyGroup( udg_Temp_Group[1] )
      • -------- Level 2 Towers --------
      • -------- Level 2 Towers --------
      • -------- Level 2 Towers --------
      • Set Temp_Group[1] = (Units of type |cff000000a |cffBB9910Lv. 2 Soldier (Building))
      • Unit Group - Pick every unit in Temp_Group[1] and do (Actions)
        • Loop - Actions
          • Set Temp_Unit[1] = (Picked unit)
          • Set Temp_Pos[1] = (Position of (Picked unit))
          • Set Temp_Group[2] = (Units within 600.00 of Temp_Pos[1])
          • Set Temp_Interger = ((Custom value of (Picked unit)) - 1)
          • Unit Group - Pick every unit in Temp_Group[2] and do (Actions)
            • Loop - Actions
              • Set Temp_Pos[2] = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of (Picked unit)) Equal to (Custom value of Temp_Unit[1])
                  • (Distance between Temp_Pos[1] and Temp_Pos[2]) Greater than or equal to 300.00
                • Then - Actions
                  • Unit - Order (Picked unit) to Move To Positionoftower[Customvalue[Temp_Interger]]
                • Else - Actions
          • Custom script: call DestroyGroup( udg_Temp_Group[2] )
          • Custom script: call RemoveLocation( udg_Temp_Pos[1] )
      • Custom script: call DestroyGroup( udg_Temp_Group[1] )
  • Lv 1 Soldier Upgrade
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to |cff000000a |cffBB9910Lv. 2 Soldier (Building)
    • Actions
      • -------- Unit lvl 1 --------
      • Set Temp_Group[1] = (Units of type |cffBB9910Lv. 1 Soldier (Unit))
      • Unit Group - Pick every unit in Temp_Group[1] and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Picked unit)) Equal to (Custom value of (Triggering unit))
            • Then - Actions
              • -------- Unit lvl 2 --------
              • Unit - Replace (Picked unit) with a |cffBB9910Lv. 2 Soldier (Unit) using The new unit's max life and mana
              • Unit - Set the custom value of (Last replaced unit) to (Custom value of (Triggering unit))
            • Else - Actions
      • Custom script: call DestroyGroup( udg_Temp_Group[1] )
If you can find a way to fix one of these bugs +REP.

And just to let you know I'm trying to make a unit tower that attacks all units within X AoE of the base tower. And when its done attacking it returns back to the middle of the base tower.
 
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

maybe I found one mistake - look:

  • Unit Group - Pick every unit in Temp_Group[2] and do (Actions)
    • Loop - Actions
      • Set Temp_Pos[2] = (Position of (Picked unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Picked unit)) Equal to (Custom value of Temp_Unit[1])
          • (Distance between Temp_Pos[1] and Temp_Pos[2]) Greater than or equal to 300.00
        • Then - Actions
          • Unit - Order (Picked unit) to Move To Positionoftower[Customvalue[Temp_Interger]]
        • Else - Actions
If guess it would be better if you make:
  • Unit Group - Pick every unit in Temp_Group[2] and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Picked unit)) Equal to Level 1 Soldier (Unit)
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Pos[1] and Picked Unit) Greater than or equal to 300.00
            • Then - Actions
              • Unit - Order (Picked unit) to Move To Temp_Pos[1]
              • == OR ==
              • Unit - Move (Picked Unit) instantly To Temp_Pos[1]
In my way i even understand this trigger and I! dont understand your part in this case. Temp_Pos[1] = The tower - now you pick EVERY Unit in 600 range and set them Temp_Group[2]. After you pick every Unit in this Group - set then Temp_Pos[2] = Picked Unit. I! understand it - because you picked every Unit in range - not just your Unit and so Temp_Pos[2] = all units not just yours.
And the effect of "Set Temp_Interger = ((Custom value of (Picked unit)) - 1)" is in my eyes not needed.

(Bad explanation i know, but my engish -_- and dont know how to explain it - maybe you understand^^)
 
Level 4
Joined
Mar 14, 2009
Messages
98
I'm not sure what you're trying to do. If you're trying to create a unit on top of the tower that goes back to it whenever it's more than 300 range away, then try this:

  • Tower and Soldier Start
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Soldier Level 1 (Building)
    • Actions
      • Unit - Turn collision for (Constructed structure) Off
      • For each (Integer A) from 1 to 3000, do (Actions)
        • Loop - Actions
          • Custom script: exitwhen udg_PositionOfTower[udg_TowerIndex] == null
      • Set TowerArray[Integer A] = (Constructed structure)
      • Set TempTowerPosition = (Position of (Constructed structure))
      • Unit - Create 1 Soldier Level 1 for (Triggering player) at TempTowerPosition facing 0.00 degrees
      • Set SoldierArray[Integer A] = (Last created unit)
      • Custom script: call RemoveLocation(udg_TempTowerPosition)
  • Upgrading Tower
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Soldier Level 2 (Building)
    • Actions
      • For each (Integer A) from 1 to 3000, do (Actions)
        • Loop - Actions
          • Custom script: exitwhen TowerArray[bj_forLoopAIndex] == GetTriggerUnit()
      • Unit - Replace SoldierArray[(Integer A)] with a Soldier Level 2 using The new unit's max life and mana
      • Set SoldierArray[(Integer A)] = (Last replaced unit)
      • Set TowerArray[(Integer A)] = (Triggering unit)
  • Return to Tower
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set ExitLoopFaster = 0
      • For each (Integer A) from 1 to 1000, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TowerArray[(Integer A)] Not equal to No unit
            • Then - Actions
              • Set PickedSoldierPosition = (Position of SoldierArray[(Integer A)])
              • Set PickedTowerPosition = (Position of TowerArray[(Integer A)])
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between PickedSoldierPosition and PickedTowerPosition) Greater than or equal to 300.00
                • Then - Actions
                  • Unit - Order SoldierArray[(Integer A)] to Move To PickedTowerPosition
                • Else - Actions
              • Custom script: call RemoveLocation(udg_PickedSoldierPosition)
              • Custom script: call RemoveLocation(udg_PickedTowerPosition)
              • Set ExitLoopFaster = 0
            • Else - Actions
              • Set ExitLoopFaster = (ExitLoopFaster + 1)
              • Custom script: exitwhen udg_ExitLoopFaster == 50
  • Tower Recycling
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Set ExitLoopFaster = 0
      • For each (Integer A) from 1 to 3000, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TowerArray[(Integer A)] Not equal to No unit
            • Then - Actions
              • Set ExitLoopFaster = 0
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Life of TowerArray[(Integer A)]) Less than 0.41
                • Then - Actions
                  • Set TowerArray[(Integer A)] = No unit
                  • Set TowerArray[(Integer A)] = No unit
                • Else - Actions
            • Else - Actions
              • Set ExitLoopFaster = (ExitLoopFaster + 1)
              • Custom script: exitwhen udg_ExitLoopFaster == 50


This has a limit of 3000 towers, though you can increase/decrease that if you want, just change the loop limit. I guess this is pretty inefficient, as it has to loop through the entire array a thousand times every 0.10 seconds. I've included a method for it to exit the loop when it has looped through fifty times and it keeps getting null values. Although, it would screw up if fifty consecutive soldiers suddenly disappeared. (Sold or died or something.) You can always change the threshold or get rid of it entirely.

On a side note, you can always use custom values for indexes if you aren't already using them for something else and use groups instead of loops for the return to tower trigger.
 
Last edited:
Status
Not open for further replies.
Top