• 🏆 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-friendly] Combat State Manager

  • Like
Reactions: Spellbound
[GUI-Friendly] Combat State Manager v1.0.0

System Requirements
GUI Unit Event v2.4.0.0 (or any Unit Indexer with an in-scope DeIndex method)​

This system allows you to keep track of which units are in combat, allowing you to create abilities or items that only work outside of combat, for example. The system also keep track of which units a unit has engaged in combat with, allowing you to, for instance, remove a unit from combat after all units it was in combat with are killed.

Due to the modular nature that I wanted to implement, you can specify when or how a unit will enter combat. However, there is no way, for example, to specify how long a unit will remain in combat after it has entered it. Since this is a pretty useful feature, there is an example of how to do this using [GUI-friendly] Timer System that is fully coded in GUI.

Combat States:

A unit can either be in combat or outside of combat. Each unit has its own Combat Group, which contains all units that are currently engaged in combat with it.

There are 2 provided ways for a unit to enter combat:
  1. Engaging with an enemy. When two units engage, both of them are added to each other's Combat Group and are flagged for combat.
  2. Supporting an ally. When an ally supports another ally (you can decide what "support" means), the supporter is engaged with all units that are in combat with the supported unit.


How to Import:
  1. Open World Editor. File -> Preferences -> Tick box for "Automatically create unknown variables (...)"
  2. Follow the instructions to import each of the system's requirements you don't already use
  3. Copy the text in this map header into the map header of your own map
  4. Copy the trigger category "GUI Combat State Manager" into your map
  5. Delte the "GCSM Import" trigger
  6. Done!
Using the System:

Engage Units

Support Unit

Leave Combat

Check Combat State

JASS API


This function engages two units in combat, which will also add each of them to the other's Combat Group. Please notice you should ignore conditions when running "GCSM Main".

GUI-only method:
  • Actions
    • Set GCSM_Target = YourUnit
    • Set GCSM_Source = OtherUnit
    • Trigger - Run GCSM Main <gen> (ignoring conditions)

This function engages a unit with all units in another unit's Combat Group, which is useful for flagging a unit for combat when it "supports" another unit. Please notice you should check conditions when running "GCSM Main".

GUI-only method:
  • Actions
    • Set GCSM_Target = SupportedUnit
    • Set GCSM_Source = Supporter
    • Trigger - Run GCSM Main <gen> (checking conditions)

This function completely removes a unit from combat, removing it from all Combat Groups of the units that are enagaged in combat with and it clearing its own Combat Group. Please notice you should check conditions when running "GCSM Main".

GUI-only method:
  • Actions
    • Set GCSM_Target = SupportedUnit
    • Set GCSM_Source = No unit
    • Trigger - Run GCSM Main <gen> (checking conditions)

This is how you check if a unit is in combat:

  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • GCSM_UnitInCombat[(Custom value of YourUnit)] Equal to True
      • Then - Actions
        • -------- Unit is in Combat --------
      • Else - Actions
        • -------- Unit is NOT in Combat --------

The system is built so it can also be used by calling JASS functions.To use the JASS API, simply move the code between the following tags from the "GCSM Main" trigger to your map header after importing the system. GUI users that want to use Custom Scripts can also follow this guide.

JASS:
////////////////////////////////////////////////////////
//Guhun's Combat State Manager v1.0.0
////////////////////////////////////////////////////////
CODE TO COPY TO MAP HEADER (I recommend including the tags above and below)
////////////////////////////////////////////////////////
//End of Combat State Manager
////////////////////////////////////////////////////////

Provided functions:
JASS:
//This function engages both specified units in combat, adding each to the other's combat group
function GCSM_UnitEnterCombat takes unit target, unit source returns nothing

//This function engages the supporter unit in combat with all units that are in combat with the target unit
function GCSM_UnitAidCombat takes unit target, unit supporter returns boolean

//This function removes a unit from combat, removing it from the combat groups of units in combat with it
//and cleaing its own combat group.
function GCSM_UnitLeaveCombat takes unit target returns nothing

//This function removes the speacified units form eachother's combat groups
function GCSM_UnitLeaveCombatWith takes unit target, unit source returns nothing

//Returns whether a unit is in combat
//You should use the variable udg_GCSM_UnitInCombat[GetUnitUserData(yourUnit)] instead
function GCSM_UnitInCombat takes unit target returns boolean

//Returns whether the target unit is in the source unit's combat group
function GCSM_UnitInCombatWith takes unit target, unit source returns boolean




Test Map:


Command

Action

kill

kills your selected units

combat

shows which units are in combat with your selected units

The test map contains a few units that you can use to test the system and the expanded example that is included in the map. When a unit is in combat, it will have an exclamation mark special effect above its head. You can use the "combat" command to check which units are currently in combat with your selected unit.

Updates and Version History:
v1:
1.0.0 > Initial Release
1.0.0a > Added disabled trigger to import variables, changed cleanup trigger conditional statement
Upcoming:
Credits:

Blizzard -> WoW's combat system (inspiration)
Bribe -> GUI Unit Event
Contents

Guhun's Combat State Manager (Map)

Reviews
Dr Super Good
Comments and Suggestions: Detects combat reasonably accurately. Could be useful for people who want specific mechanics or to disable abilities in combat. Could do with some better examples such as the sort of thing one would expect using this system...
Level 12
Joined
Jun 12, 2010
Messages
413
Does this control combat state automatically or do you have to place them in this state manually? For instance, if I just import the library and then call GCSM_UnitInCombat() on a unit that is currently fighting, will it return true?

Nope, you have to manually code the situations you want to have units enter combat. This is to make the system for flexible, since users can define "combat" however they wish for their own purposes.

The testmap example was designed so people that use GUI Damage Engine can easily import it though, and it handles combat in a very similar way to WoW's combat (since it's usually RPG maps that employ these combat systems). You just have to delete the lines related to special effetcs, since they're probably unwanted. This way you can just import the testmap example if you don't want to code your own combat rules.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
Comments and Suggestions:
Detects combat reasonably accurately. Could be useful for people who want specific mechanics or to disable abilities in combat.

Could do with some better examples such as the sort of thing one would expect using this system in a production map.

Units could be registered as in combat upon trying to attack or be attacked rather than when they deal or take damage. Especially with ranged units there is a period of time between attacking and the missile landing during which they could still use out of combat mechanics.​
 
Top