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

Commander System v1.00

This system makes it so, that there's 2 unit groups - Commanders and Troops.
Every troop needs to have a commander nearby or it turns neutral.
Commanders can also be troops, but don't have to.
A commander that is not a troop is almost like a normal unit.

Note: I know there's leak(s). Just not where atm.

Requirements:
Any unit indexer that changes custom value of unit.
Half a brain to import this.

How to use?
1. Make sure you have "Create unknown variables" ticked.
2. Copy all triggers.
3. Make the TroopStatus and CommanderStatus abilities(they can be based on anything)
4. Set TroopStatusAbil and CommanderStatusAbil to the corresponding abilities.
5. Profit!

v1.0
Changed leave event to death event in TroopLeave trigger.
v0.01Merged init triggers.
Slightly improved unit selection at map init
Replaced triggering unit/picked unit with TempUnit variables.
Made CommanderDeath trigger work(it tried to use picked unit instead of triggering unit)
Avoided counting units in a group through using integer variables.


  • TroopInit
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Configurables --------
      • Set MaxTroopDistance = 1280.00
      • Set MaxTroops = 6
      • Set TroopGetRange = 256.00
      • Set TroopStatusAbil = TroopStatus
      • Set CommanderStatusAbil = CommanderStatus
      • -------- Picking all previously placed units --------
      • Set TempPointA = (Point(0.00, 0.00))
      • Custom script: call DestroyGroup(udg_Troops)
      • Set Troops = (Units within 90000.00 of TempPointA matching ((Level of TroopStatus for (Matching unit)) Greater than 0))
      • Custom script: call DestroyGroup(udg_Commanders)
      • Set Commanders = (Units within 90000.00 of TempPointA matching ((Level of CommanderStatus for (Matching unit)) Greater than 0))
      • Custom script: call RemoveLocation(udg_TempPointA)
      • -------- All done. Display debug message to prove it. --------
      • Game - Display to (All players) the text: Commander System In...
  • TroopEnter
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Set TempUnitA = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnitA is in Commanders) Equal to False
          • (Level of CommanderStatusAbil for TempUnitA) Greater than 0
        • Then - Actions
          • Unit Group - Add TempUnitA to Commanders
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnitA is in Troops) Equal to False
          • (Level of TroopStatusAbil for TempUnitA) Greater than 0
        • Then - Actions
          • Unit Group - Add TempUnitA to Troops
        • Else - Actions
      • Set TempUnitA = No unit
  • TroopLeave
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set TempUnitA = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnitA is in Commanders) Equal to True
        • Then - Actions
          • Unit Group - Remove TempUnitA from Commanders
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnitA is in Troops) Equal to True
        • Then - Actions
          • Unit Group - Remove TempUnitA from Troops
        • Else - Actions
  • CommanderCheck
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Commanders and do (Actions)
        • Loop - Actions
          • Set TempUnitA = (Picked unit)
          • Unit Group - Pick every unit in CommanderTroops[(Custom value of TempUnitA)] and do (Actions)
            • Loop - Actions
              • Set TempUnitB = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of TempUnitB) Not equal to (Owner of TempUnitA)
                • Then - Actions
                  • Unit Group - Remove TempUnitB from CommanderTroops[(Custom value of TempUnitA)]
                  • Set CommanderTroopCount[(Custom value of TempUnitA)] = (CommanderTroopCount[(Custom value of TempUnitA)] - 1)
                  • Set UnitCommander[(Custom value of TempUnitB)] = No unit
                • Else - Actions
  • TroopGet
    • Events
      • Time - Every 0.59 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Commanders and do (Actions)
        • Loop - Actions
          • Set TempUnitA = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in CommanderTroops[(Custom value of TempUnitA)]) Less than MaxTroops
            • Then - Actions
              • Set TempPointA = (Position of TempUnitA)
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units within TroopGetRange of TempPointA) and do (Actions)
                • Loop - Actions
                  • Set TempUnitB = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • CommanderTroopCount[(Custom value of TempUnitA)] Less than MaxTroops
                      • UnitCommander[(Custom value of TempUnitB)] Equal to No unit
                      • TempUnitB Not equal to TempUnitA
                      • (Level of TroopStatusAbil for TempUnitB) Greater than 0
                    • Then - Actions
                      • Unit - Change ownership of TempUnitB to (Owner of TempUnitA) and Change color
                      • Unit Group - Add TempUnitB to CommanderTroops[(Custom value of TempUnitA)]
                      • Set CommanderTroopCount[(Custom value of TempUnitA)] = (CommanderTroopCount[(Custom value of TempUnitA)] + 1)
                      • Set UnitCommander[(Custom value of TempUnitB)] = TempUnitA
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_TempPointA)
            • Else - Actions
  • CommanderDeath
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in Commanders) Equal to True
    • Actions
      • Set TempUnitA = (Triggering unit)
      • Unit Group - Remove TempUnitA from Commanders
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in CommanderTroops[(Custom value of TempUnitA)] and do (Actions)
        • Loop - Actions
          • Unit Group - Remove (Picked unit) from CommanderTroops[(Custom value of TempUnitA)]
          • Set CommanderTroopCount[(Custom value of TempUnitA)] = (CommanderTroopCount[(Custom value of TempUnitA)] - 1)
  • TroopCheck
    • Events
      • Time - Every 3.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Troops and do (Actions)
        • Loop - Actions
          • Set TempUnitA = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of UnitCommander[(Custom value of TempUnitA)]) Equal to No unit-type
              • UnitCommander[(Custom value of TempUnitA)] Not equal to No unit
            • Then - Actions
              • Unit - Change ownership of TempUnitA to Neutral Passive and Change color
              • Set UnitCommander[(Custom value of TempUnitA)] = No unit
            • Else - Actions
          • Set TempPointA = (Position of TempUnitA)
          • Set TempPointB = (Position of UnitCommander[(Custom value of TempUnitA)])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between TempPointA and TempPointB) Greater than MaxTroopDistance
            • Then - Actions
              • Unit Group - Remove TempUnitA from CommanderTroops[(Custom value of UnitCommander[(Custom value of TempUnitA)])]
              • Set CommanderTroopCount[(Custom value of UnitCommander[(Custom value of TempUnitA)])] = ((Custom value of UnitCommander[(Custom value of TempUnitA)]) - 1)
              • Unit - Change ownership of TempUnitA to Neutral Passive and Change color
              • Set UnitCommander[(Custom value of TempUnitA)] = No unit
            • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPointA)
          • Custom script: call RemoveLocation(udg_TempPointB)
Contents

Commander System v1.0 (Map)

Reviews
13:25, 19th Jul 2013 PurgeandFire: Changes made! Approved. Cool system!

Moderator

M

Moderator

13:25, 19th Jul 2013
PurgeandFire: Changes made! Approved. Cool system!
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
- Compress your TroopInt and TroopConfig
- Pick units in palyable map area and make level equal to zero
- In TroopEnter and leave, put the other condition in the else part
- Counting units in a group is very slow, use integers instead, every unit that is added to a group, add it, then subtract if removed
- You dont need to null globals
 
What Unit Indexer is this?

For GUI Resources, you should be using Bribes Indexer or any other approved Indexer on this site.

If you made your own, consider using Bribes. It's better for a resource to rely on external libraries. The reasons are countless and I have already explained this a million fucking times.

http://www.hiveworkshop.com/forums/2346203-post73.html
^Check the part in which I explain how making a system extend off another one is good.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
http://www.hiveworkshop.com/forums/submissions-414/spell-submission-rules-230362/

Since you don't explicitly mention using Bribe's indexer, I presume that you use custom value and violate one of the rules.

I forgot to mention the requirements.

1. leak in the init trigger
2. combine the two init triggers

else I cant find any flaws.

however, aint this system very limited, you know it's only useful in a low ammout of maps. but gj anyways 4/5
Which leak do you mean? I did fix one, but I'm almost sure you mean something else.
Combined.

Recently I thought of 2 map ideas that would require a system like this. It could be used for pets. Or it could be used for a wargame where assasinating a high-ranking officer causes chaos.
Later I'll add support for converting entire groups through commanders(take over commander and you take over everything he controlled)
for efficiency and speed anything u use twice or more should be stored into a variable and u should use the variable. example u use picked unit a lot.
Done.
- Compress your TroopInt and TroopConfig
- Pick units in palyable map area and make level equal to zero
- In TroopEnter and leave, put the other condition in the else part
- Counting units in a group is very slow, use integers instead, every unit that is added to a group, add it, then subtract if removed
- You dont need to null globals
-Compressed.
-No. The conditions must stay separate, because a commander can also be a troop(chain of command).
-Made it keep track of how many units a group has, to avoid counting.
-Where?
@Doomlord
Actually, I think he is using a Unit Indexing system,because I can't see any Set Custom Value funcs.
Yep, Bribe's, but this works with pretty much any indexer.
version 0?
I will change version number to 1 when and if it gets approved.
What Unit Indexer is this?

For GUI Resources, you should be using Bribes Indexer or any other approved Indexer on this site.

If you made your own, consider using Bribes. It's better for a resource to rely on external libraries. The reasons are countless and I have already explained this a million fucking times.

http://www.hiveworkshop.com/forums/2346203-post73.html
^Check the part in which I explain how making a system extend off another one is good.
Bribe's atm, but it's not necessary to use this one. Anything works really.

EDIT: Uploaded new version.
 
Last edited:
Level 29
Joined
Mar 10, 2009
Messages
5,016
-No. The conditions must stay separate, because a commander can also be a troop(chain of command).
-Made it keep track of how many units a group has, to avoid counting.
-Where?
- your method checks 2 every time, while mine checks only 1 time, if it returns false, it will go to the else part...
- the CountUnitsInGroup has a counter inside but it's too slow, best to have a counter directly, for efficiency's sake...
- Set UnitCommander[(Custom value of TempUnitB)] = No unit
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
- your method checks 2 every time, while mine checks only 1 time, if it returns false, it will go to the else part...
- the CountUnitsInGroup has a counter inside but it's too slow, best to have a counter directly, for efficiency's sake...
- Set UnitCommander[(Custom value of TempUnitB)] = No unit

- If I made it like this, then it would turn impossible to have a chain of command.
- Alright, this has been fixed.
- This is somewhat about clearing variables, but it also makes sure that the unit truly doesn't have a commander anymore, because elseway it could create problems(same unit owned by multiple commanders).
 
Sorry for the late review. This looks pretty good overall.

- You initialize CommanderTroopCount[] to 0 on initialization. Global integer arrays are already initialized as 0 when you first reference them.
- In "TroopLeave", you use "A unit leaves playable map area". That doesn't fire unless someone is moved into the black area on the edges of the map. You may have to use a deindex event or the event "a unit dies", or something similar (or perform checks if a unit exists in your group iterations or w/e)

Aside from that, everything has been pretty much said. It looks good.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Sorry for the late review. This looks pretty good overall.

- You initialize CommanderTroopCount[] to 0 on initialization. Global integer arrays are already initialized as 0 when you first reference them.
- In "TroopLeave", you use "A unit leaves playable map area". That doesn't fire unless someone is moved into the black area on the edges of the map. You may have to use a deindex event or the event "a unit dies", or something similar (or perform checks if a unit exists in your group iterations or w/e)

Aside from that, everything has been pretty much said. It looks good.

-I'm not entirely sure if it's also like this in GUI; but in JASS it is not possible to increment an integer before setting it to a value, so I worked off of that assumption. (trying to read an unitialized integer gives 0, but the actual value would be null, so thread breaks)
-Leaves playable area is supposed to detect when a unit is removed from the game. If I make it use a deindex event, then I'll have to increase requirements a bit, but I guess it can be deemed worth it
 
-I'm not entirely sure if it's also like this in GUI; but in JASS it is not possible to increment an integer before setting it to a value, so I worked off of that assumption. (trying to read an unitialized integer gives 0, but the actual value would be null, so thread breaks)

You can, whether it is GUI or JASS. Non-array integers do not have a default value of 0 (which is why they crash), but array integers do. Just try it out, and it will work. :)

This is pretty handy to know for coding. Boolean arrays default false as well (just a random, handy tip).

-Leaves playable area is supposed to detect when a unit is removed from the game. If I make it use a deindex event, then I'll have to increase requirements a bit, but I guess it can be deemed worth it

I wish it did. :\ Anyway, at the moment it is up to you whether you want to supplement that part. I was just telling you that it does nothing at the moment (unless a unit is moved outside the playable map area). If you don't want to have a deindex event, then you can probably find some makeshift way to detect if a unit has been removed. For example, when you are doing the "Pick every..." actions, you can just check if the unit's ID is equal to 0. If so, then it was removed/dead/ or w/e and needs to be removed from the group. (There are other methods as well.. its handle ID will be 0, its race's handle ID will be 0, etc.)
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
You can, whether it is GUI or JASS. Non-array integers do not have a default value of 0 (which is why they crash), but array integers do. Just try it out, and it will work. :)

This is pretty handy to know for coding. Boolean arrays default false as well (just a random, handy tip).



I wish it did. :\ Anyway, at the moment it is up to you whether you want to supplement that part. I was just telling you that it does nothing at the moment (unless a unit is moved outside the playable map area). If you don't want to have a deindex event, then you can probably find some makeshift way to detect if a unit has been removed. For example, when you are doing the "Pick every..." actions, you can just check if the unit's ID is equal to 0. If so, then it was removed/dead/ or w/e and needs to be removed from the group. (There are other methods as well.. its handle ID will be 0, its race's handle ID will be 0, etc.)

Alright. Changes made now. There's still some borderline cases like resurrection/animate dead, but I am not yet sure how to fix them.
 
Level 5
Joined
Oct 16, 2013
Messages
81
This system very good for my map. :D
I guess my map is one of the rare maps using this system.
Thanks, Xonok! ^^
 
Top