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

Automatic Unit Queuing and Training.

Status
Not open for further replies.
Level 7
Joined
Aug 5, 2010
Messages
147
please, can someone tell me how to make a trigger that, when a building has finished constructing, it automatically queues a unit and then starts to train said unit.

(if you dont understand what im asking, if you have played the map castle fight, the system that maps has to create units, that is the type of unit training i am looking for)
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
here's the idea behind that...
- Make a looping trigger for 2 per seconds.
- Make a group variable.
- When building is finished contructing, add that building to the Group.
- In the looping trigger use Pick every unit in Group, then order the building to train,
footman, priest or whatever units you're training.
- When building dies, remove it in the Group.

ofc you'll make conditions as which building is picked by the group, then execute the training of a particular unit.

say...
  • Event
    • Time - every 2 seconds
  • Condition
  • Actions
    • Pick every Unit in the group
      • If picked unit is barracks then
        • Order picked unit to train footman
      • If picked unit is arcane then
        • Order picked unit to train priest
 
- Make a looping trigger for 2 per seconds. Turn it off.
- Make a group variable.
- When building is finished contructing, check if the unit group is empty, and if yes, turn the looping trigger on, then add that building to the Group.
- In the looping trigger use Pick every unit in Group, then order the building to train,
footman, priest or whatever units you're training.
- When building dies, remove it in the Group, then check if the unit group is empty, if yes, turn the looping trigger off.

  • Event
    • Time - every 2 seconds
  • Condition
  • Actions
    • Pick every Unit in the group
      • If picked unit is barracks then
        • Order picked unit to train footman
      • If picked unit is arcane then
        • Order picked unit to train priest
Cannot be the trigger without massives if then else by using hashtables ?
 
Level 7
Joined
Aug 5, 2010
Messages
147
Okay i have no idea how to do this, ive created 3 different unit groups variables:

ArcheryGroup
ArmoursmithGroup
BarracksGroup

Now, im pretty sure that the trigger that adds the constructed buildings to there specified groups works. but just in case heres the trigger im using:


BarracksGroupAdd
Events
Unit - A unit Finishes construction
Conditions
(Unit-type of (Constructed structure)) Equal to Barracks
Actions
Unit Group - Add (Constructed structure) to BarracksGroup

The next part i dont understand, i made a trigger that would make the buildings in the Unit Group train units, but as you know already i dont understand how to do it and the trigger doesn't work. Here is the trigger that i made:

Periodic Unit Spawn
Events
Time - Every 2.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in ArcheryGroup and do (Actions)
Loop - Actions
If ((Unit-type of (Picked unit)) Equal to Archery Range) then do (Unit - Order (Picked unit) to train/upgrade to a Archer) else do (Do nothing

Also, the hashtables that Vladadmamm and Maker mentioned, what are they and how would they help with this problem im having.

Any help would be appreciated.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240

  • Untitled Trigger 042
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set hash = (Last created hashtable)
      • Custom script: call SaveStr(udg_hash, 'hbar', 0, "footman")
      • Custom script: call SaveStr(udg_hash, 'hgra', 0, "gryphonrider")
  • Untitled Trigger 044
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Custom script: if HaveSavedString(udg_hash, GetUnitTypeId(GetConstructedStructure()), 0) then
      • Unit Group - Add (Constructed structure) to group
      • Custom script: endif
  • Untitled Trigger 045
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in group and do (Actions)
        • Loop - Actions
          • Custom script: call IssueImmediateOrder(GetEnumUnit(), LoadStr(udg_hash, GetUnitTypeId(GetEnumUnit()), 0))
In the first trigger, initialize the unit to train for every building type. Hit Ctrl + D in object editor to see raw codes. hbar is barracks and hgra is gryphon aviary for example.

You could add a trigger that removes dying units from the group.
 
Level 7
Joined
Aug 5, 2010
Messages
147

  • Untitled Trigger 042
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set hash = (Last created hashtable)
      • Custom script: call SaveStr(udg_hash, 'hbar', 0, "footman")
      • Custom script: call SaveStr(udg_hash, 'hgra', 0, "gryphonrider")
  • Untitled Trigger 044
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Custom script: if HaveSavedString(udg_hash, GetUnitTypeId(GetConstructedStructure()), 0) then
      • Unit Group - Add (Constructed structure) to group
      • Custom script: endif
  • Untitled Trigger 045
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in group and do (Actions)
        • Loop - Actions
          • Custom script: call IssueImmediateOrder(GetEnumUnit(), LoadStr(udg_hash, GetUnitTypeId(GetEnumUnit()), 0))
In the first trigger, initialize the unit to train for every building type. Hit Ctrl + D in object editor to see raw codes. hbar is barracks and hgra is gryphon aviary for example.

You could add a trigger that removes dying units from the group.



Now im even more confused. :/

EDIT: I have managed to get the buildings to auto-train units by simply using this trigger:

  • Periodic Unit Spawn
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ArcheryGroup and do (Actions)
        • Loop - Actions
          • Unit Group - Order (Units in RedPlayerBuildArea <gen>) to train a Archer
Thanks for the help. +rep
 
Status
Not open for further replies.
Top