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

Multi Unit Training > Make them properly work with rally points

Status
Not open for further replies.
Level 3
Joined
Aug 9, 2015
Messages
18
hi there!

I'm struggling a bit with having my buildings training multiple units at once. Well not really, that part wasn't hard. What is though, is figuring out, how I get the additional units to behave just like the original, in regards to rally points:

  • Run Mult Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • ((Trained unit) is Mechanical) Not equal to True
      • (Unit-type of (Trained unit)) Not equal to Sharpshooter
      • (Unit-type of (Trained unit)) Not equal to Berserker
      • (Unit-type of (Trained unit)) Not equal to Reaver
      • (Unit-type of (Trained unit)) Not equal to Ancestor Spirit
      • (Unit-type of (Trained unit)) Not equal to Druid
      • (Unit-type of (Trained unit)) Not equal to Runepriest
    • Actions
      • Set TrainingUnitType = (Unit-type of (Trained unit))
      • Set TrainingPlayer = (Owner of (Triggering unit))
      • Set Temp_Point_Train_Rally = (Rally-Point of (Triggering unit) as a point)
      • Set Temp_Point_Train = (Position of (Triggering unit))
      • Unit - Create 1 TrainingUnitType for TrainingPlayer at Temp_Point_Train facing Default building facing degrees
      • Unit - Order (Last created unit) to Right-Click Temp_Point_Train_Rally
      • Unit - Create 1 TrainingUnitType for TrainingPlayer at Temp_Point_Train facing Default building facing degrees
      • Unit - Order (Last created unit) to Right-Click Temp_Point_Train_Rally
      • Custom script: call RemoveLocation (udg_Temp_Point_Train)
      • Custom script: call RemoveLocation (udg_Temp_Point_Train_Rally)
As you can see, I have tried the order "Right-Click" on the rally point. This makes them properly move to it, but when I put the rally point on e.g. a tree, they won't automatically start harvesting.
I'm assuming there is no way to make a newly created unit "copy" the exact orders given to the "trained unit" so I am a bit lost tbh. The only thing that I could think of would be using an if/then/else function to check for destructibles in range or something and then redirect their order to harvest... That sounds pretty complicated though, so yea; I hope someone has a more efficient idea.

Any help would be highly appreciated, especially since this is one of the last few unfilled checkboxes on my road to have a functioning framework for the kind of map I want to create.


€: Ugh, I'm such a doofus. Literally 1 minute after posting I realised that there is a function for targeting the rally point as a destructible. The only problem remaining, is figuring out how to distinguish between what order the unit has to receive when being created, as just switching the right click order with the harvest one, stops them from moving when the rally point is not a tree... ugh... I'll see if I can figure this out and will keep you updated :) Sorry for being a doofus.

€2: Just to clarify: What I am currently lacking, is a way to detect if the trained unit is being sent to a destructible or not, via the rally point of the training structure. I've tried checking for current order of last trained unit but apparently, a unit coming out of training that immediately starts harvesting, uses the "smart" (right click) order string, same as if it just moves to a point.

€3,5: Aight, here to finished, cleaned up (as far as i can tell) version of the trigger for anyone interested

  • Run Mult Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Set TrainingUnit = (Triggering unit)
      • Set TrainedUnit = (Trained unit)
      • Set TrainingUnitType = (Unit-type of (Trained unit))
      • Set TrainingPlayer = (Owner of TrainingUnit)
      • Set Temp_Point_Train_Rally = (Rally-Point of TrainingUnit as a point)
      • Set Temp_Destruct_Rally = (Rally-Point of TrainingUnit as a destructible)
      • Set Temp_Point_Train = (Position of TrainedUnit)
      • Unit - Create 1 TrainingUnitType for TrainingPlayer at Temp_Point_Train facing Default building facing degrees
      • Unit Group - Add (Last created unit) to RallyUnitGroup
      • Unit - Create 1 TrainingUnitType for TrainingPlayer at Temp_Point_Train facing Default building facing degrees
      • Unit Group - Add (Last created unit) to RallyUnitGroup
      • Unit Group - Pick every unit in RallyUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Destruct_Rally Equal to No destructible
            • Then - Actions
              • Unit - Order (Picked unit) to Right-Click Temp_Point_Train_Rally
            • Else - Actions
              • Unit - Order (Picked unit) to Harvest Temp_Destruct_Rally
      • Custom script: call RemoveLocation (udg_Temp_Point_Train)
      • Custom script: call RemoveLocation (udg_Temp_Point_Train_Rally)
      • Unit Group - Remove all units of RallyUnitGroup from RallyUnitGroup
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Using only right click would work as well. If a worker right clicks a tree it harvests from it.
There is also the possibility to select a friendly unit as rally point. You can use the same method as you did for destructible: Rally-Point of TrainingUnit as a unit and comparing it with no unit.
Here you can use right click again or patrol.
cleaned up (as far as i can tell)
No leaks.

This triggermay not work, because variables could be overwritten. Your trigger contains actions that may trigger an event, causing another trigger to fire. For example "Create a unit" can fire the "Enters a region" event and "Order unit to..." can fire a "unit is issued an order..." event.
If you have such triggers, they will overwrite shared variables, because they run directly when this action happens, before your trigger is finished.

Judging from your variable names ("train"), your variables probably won't be shared with other triggers, so you won't have this problem.
This is a common problem with GUI (no local variables) though and people often don't think about the possbility of other triggers running in between their triggers. Whenever a trigger does not work as intended, one should also think if other triggers could run in between and cause the trigger not to work.
 
Status
Not open for further replies.
Top