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

[GUI] Auto-Train System v1.1

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
  • Like
Reactions: StoPCampinGn00b
229063-albums7387-picture84941.png

When you build a structures under of this System, the structure will be train automatically

Trigger Function

  • AT Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- ======================== --------
      • -------- A U T O T R A I N S Y S T E M --------
      • -------- By: GywGod133 --------
      • -------- ======================== --------
      • -------- > Structures --------
      • Set AT_Structures[1] = Barracks - [|cffffcc00Level 1|r]
      • Set AT_Structures[2] = Barracks - [|cffffcc00Level 2|r]
      • Set AT_Structures[3] = Barracks - [|cffffcc00Level 3|r]
      • Set AT_Structures[4] = Barracks - [|cffffcc00Level 4|r]
      • Set AT_Structures[5] = Barracks - [|cffffcc00Level 5|r]
      • Set AT_Structures[6] = Arcane Sanctum
      • -------- > Units --------
      • Set AT_UnitTrain[1] = Footman - Barracks (Level 1)
      • Set AT_UnitTrain[2] = Captain (Barracks - Level 2)
      • Set AT_UnitTrain[3] = Blood Elf Lieutenant (Barracks - Level 3)
      • Set AT_UnitTrain[4] = Jailor Kassan (Barracks - Level 4)
      • Set AT_UnitTrain[5] = Knight (Barracks - Level 5)
      • Set AT_UnitTrain[6] = Priest (Arcane Sanctum)
      • -------- > Count Structures and Units --------
      • Set AT_Count = 6
      • -------- ======================== --------
      • -------- > Train Count --------
      • -------- NOTE: Maximum Train is only 7 --------
      • Set AT_Train = 2
      • -------- ======================== --------
      • -------- Boolean Function: --------
      • -------- > Removing Rally Ability --------
      • Set AT_BeginConstruct = True
      • Set AT_Constructed = True
      • Set AT_BeginUpgrade = True
      • Set AT_Upgraded = True
      • Set AT_Cancelled = True
      • -------- > Changing Owner --------
      • -------- NOTE: Only one changing owner player per allied --------
      • Set AT_WantChangeColor = True
      • Set AT_1Player[1] = True
      • Set AT_1Player[2] = True
      • -------- ======================== --------
      • -------- Rally Point Function: --------
      • -------- > Without using rally ability, set the point and when the units trained, automtically attack-move --------
      • -------- NOTE: Only one point per allied --------
      • Set AT_2Player[1] = (Player 2 (Blue) start location)
      • Set AT_2Player[2] = (Player 1 (Red) start location)
      • -------- ======================== --------
      • -------- Wait Function: --------
      • Set AT_Wait = 1.00
      • -------- ======================== --------
      • -------- Destroy This Trigger --------
      • Custom script: call DestroyTrigger( GetTriggeringTrigger())
      • -------- ======================== --------
Structures Function

  • AT Contructing
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • AT_BeginConstruct Equal to True
    • Actions
      • Set AT_TempUnit = (Triggering unit)
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of AT_TempUnit) Equal to AT_Structures[AT_TempLoop1]
            • Then - Actions
              • Unit - Remove Rally from AT_TempUnit
            • Else - Actions
  • AT Constructed
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • AT_Constructed Equal to True
    • Actions
      • Set AT_TempUnit = (Triggering unit)
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of AT_TempUnit) Equal to AT_Structures[AT_TempLoop1]
            • Then - Actions
              • Unit - Remove Rally from AT_TempUnit
              • -------- ======================== --------
              • -------- Start to Train a Unit --------
              • -------- > NOTE: Maximum Train only 7 units --------
              • For each (Integer AT_TempLoop) from 1 to AT_Train, do (Actions)
                • Loop - Actions
                  • Unit - Order AT_TempUnit to train/upgrade to a AT_UnitTrain[AT_TempLoop1]
            • Else - Actions
  • AT Upgrading
    • Events
      • Unit - A unit Begins an upgrade
    • Conditions
      • AT_BeginUpgrade Equal to True
    • Actions
      • Set AT_TempUnit = (Triggering unit)
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of AT_TempUnit) Equal to AT_Structures[AT_TempLoop1]
            • Then - Actions
              • Unit - Remove Rally from AT_TempUnit
            • Else - Actions
  • AT Upgraded
    • Events
      • Unit - A unit Finishes an upgrade
    • Conditions
      • AT_Upgraded Equal to True
    • Actions
      • Set AT_TempUnit = (Triggering unit)
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of AT_TempUnit) Equal to AT_Structures[AT_TempLoop1]
            • Then - Actions
              • Unit - Remove Rally from AT_TempUnit
              • -------- ======================== --------
              • -------- Start to Train a Unit --------
              • -------- > NOTE: Maximum Train only 7 units --------
              • For each (Integer AT_TempLoop) from 1 to AT_Train, do (Actions)
                • Loop - Actions
                  • Unit - Order AT_TempUnit to train/upgrade to a AT_UnitTrain[AT_TempLoop1]
            • Else - Actions
  • AT Trained
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • -------- ============================================================== --------
      • -------- PLEASE DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING!! --------
      • -------- ============================================================== --------
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Trained unit)) Equal to AT_UnitTrain[AT_TempLoop1]
            • Then - Actions
              • -------- ======================== --------
              • -------- Turn On the Trigger Loop: --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • AT_Y Equal to 0
                • Then - Actions
                  • Trigger - Turn on AT Periodic <gen>
                • Else - Actions
              • -------- ======================== --------
              • -------- Increase Y size: --------
              • Set AT_Y = (AT_Y + 1)
              • -------- ======================== --------
              • -------- Save All Data --------
              • -------- > Save Structures --------
              • Set AT_Structure[AT_Y] = (Triggering unit)
              • -------- > Save Trained Unit --------
              • Set AT_TrainedUnit[AT_Y] = (Trained unit)
              • -------- > Set / Save Wait Duration --------
              • Set AT_WaitDuration[AT_Y] = 0.00
              • -------- ======================== --------
              • -------- Trained Unit Function: --------
              • For each (Integer AT_TempLoop2[AT_Y]) from 1 to 12, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • AT_1Player[AT_TempLoop2[AT_Y]] Equal to True
                      • (AT_TrainedUnit[AT_Y] belongs to an ally of (Player(AT_TempLoop2[AT_Y]))) Equal to True
                    • Then - Actions
                      • -------- ======================== --------
                      • -------- Changing Owner / Attack Move Function: --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • AT_WantChangeColor Equal to True
                        • Then - Actions
                          • -------- > Changing Owner --------
                          • Unit - Change ownership of AT_TrainedUnit[AT_Y] to (Player(AT_TempLoop2[AT_Y])) and Change color
                          • -------- > Attack-Move --------
                          • Unit - Order AT_TrainedUnit[AT_Y] to Attack-Move To AT_2Player[AT_TempLoop2[AT_Y]]
                        • Else - Actions
                          • -------- > Attack-Move --------
                          • Unit - Order AT_TrainedUnit[AT_Y] to Attack-Move To AT_2Player[AT_TempLoop2[AT_Y]]
                    • Else - Actions
              • -------- ======================== --------
            • Else - Actions
  • AT Cancelled
    • Events
      • Unit - A unit Cancels construction
      • Unit - A unit Cancels an upgrade
    • Conditions
      • AT_Cancelled Equal to True
    • Actions
      • -------- When the Structure cancelled, automatically added a rally point in Triggering Unit --------
      • Set AT_TempUnit = (Triggering unit)
      • For each (Integer AT_TempLoop1) from 1 to AT_Count, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of AT_TempUnit) Equal to AT_Structures[AT_TempLoop1]
            • Then - Actions
              • Unit - Remove Rally from AT_TempUnit
            • Else - Actions
  • AT Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • -------- ============================================================== --------
      • -------- PLEASE DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING!! --------
      • -------- ============================================================== --------
      • For each (Integer AT_X) from 1 to AT_Y, do (Actions)
        • Loop - Actions
          • -------- ======================== --------
          • -------- Duration Function: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AT_WaitDuration[AT_X] Greater than or equal to (AT_Wait + 0.03)
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (AT_Structure[AT_X] is alive) Equal to True
                • Then - Actions
                  • -------- ======================== --------
                  • -------- Train unit in the structure --------
                  • Unit - Order AT_Structure[AT_X] to train/upgrade to a (Unit-type of AT_TrainedUnit[AT_X])
                • Else - Actions
              • -------- ======================== --------
              • -------- RecycleIndex --------
              • Set AT_Structure[AT_X] = AT_Structure[AT_Y]
              • Set AT_TrainedUnit[AT_X] = AT_TrainedUnit[AT_Y]
              • Set AT_WaitDuration[AT_X] = AT_WaitDuration[AT_Y]
              • Set AT_X = (AT_X - 1)
              • Set AT_Y = (AT_Y - 1)
              • -------- ======================== --------
              • -------- Turn the trigger again off if the Y is below 0... --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • AT_Y Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
              • Set AT_WaitDuration[AT_X] = (AT_WaitDuration[AT_X] + 0.03)
Changelog
v1.0
- I submitted this resource

v1.1
- Add TempUnit
- Fixing AT Trained
Keywords:
AT, Auto-Train, AKA.GywGod133
Contents

[System] Auto-Train (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 21:51, 10th Jul 2014 BPower: http://www.hiveworkshop.com/forums/spells-569/gui-auto-train-system-v1-1-a-251331/#post2554611

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

21:51, 10th Jul 2014
BPower:
http://www.hiveworkshop.com/forums/spells-569/gui-auto-train-system-v1-1-a-251331/#post2554611
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
well, must be useful for AI system if one structure can auto-train more than 1 unit types

  • Set AT_StructuresCount = 6
  • Set AT_UnitTrainCount = 6
if they can only auto-train one unit type so those two variable will always has a same value, so better stick them to one variable.

  • -------- > Without using rally ability, set the point and when the units trained, automtically attack-move --------
I think rally point is not important, it has not any relation with "auto-train"

  • (Unit-type of (Triggering unit)) Equal to (==) AT_Structures[AT_TempLoop1]
store (Triggering unit) into variable first

those are the major things, and....

where is your importing instructions? :v
 
Level 13
Joined
Jul 16, 2012
Messages
679
well, must be useful for AI system if one structure can auto-train more than 1 unit types

  • Set AT_StructuresCount = 6
  • Set AT_UnitTrainCount = 6
if they can only auto-train one unit type so those two variable will always has a same value, so better stick them to one variable.

  • -------- > Without using rally ability, set the point and when the units trained, automtically attack-move --------
I think rally point is not important, it has not any relation with "auto-train"

  • (Unit-type of (Triggering unit)) Equal to (==) AT_Structures[AT_TempLoop1]
store (Triggering unit) into variable first

those are the major things, and....

where is your importing instructions? :v

:grin: Well.. i need know to fix xD Thanks for reviewing
 
Hihi... training only 1 unit type, and set each type in config is just much work and actually it's not dynamic enough, I think. (as Dalvengyr mentioned already)

Also what could be useful is working with death_event. If my food limit is reached for example, the training stops.
But I would want my building to continue training if food limit allows is again.

I doubt the periodic trigger is really needed. It doesnt seem very clean this way.

Try to learn about hashtable, it could simplify code... and you would not need loops to check unitType.

In "AT Trained" trigger - following can be outside your very last If/Then/Else:
  • Unit - Order AT_CopyTrainedUnit[AT_Y] to Attack-Move To AT_2Player[AT_TempLoop2[AT_Y]]

I think this can be very ueful for an auto-train system.

If you read the API, you will see the functionality. You may use things like GetLastTrainId and so you can easily make your buildings be able to train different unit types at once, without any pre-config or loops to check the index.

You also can use these API function via custom script, excample you want get the unitType of last trained unit for your building:
  • Custom script: local integer i = GetLastTrainId(GetTriggerUnit())

Overall I think an auto-train system can be useful for certain maps, but first you should try to make it more dynamic and as easy as possible.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
This would be more efficient using a hashtable. All of the loops to check if unit type of triggering unit is in the system is very slow and costly.
Also checking like this.
  • (Unit-type of (Triggering unit)) Equal to AT_Structures[AT_TempLoop1]
only allows for one unit type in the system which really isn't good.

Also anything used twice or more should be stored into a variable and the variable should be used.
Even when looping.
All your triggers should store triggering unit and (Unit-type of (Triggering unit)) before they loop through everything.
 
Top