1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. The long-awaited results for Concept Art Contest #11 have finally been released!
    Dismiss Notice
  3. The mythological era has spawned some interesting characters around. Check them out and be sure to vote for them in the 30th Poll of the Texturing Contest.
    Dismiss Notice
  4. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  5. Hivers united and created a bunch of 2v2 melee maps. Vote for the best in our Melee Mapping Contest #4 - Poll!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice

[GUI-friendly] Combat State Manager

Submitted by _Guhun_
This bundle is marked as approved. It works and satisfies the submission rules.
[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:


  • 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.

    Code (vJASS):

    ////////////////////////////////////////////////////////
    //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:
    Code (vJASS):

    //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...
  1. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    314
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Well, I had said the last one would be the last system I posted for a while, but since this concept was in System Reinventing and IcemanBo told me I should post it, here it is.
     
  2. Spellbound

    Spellbound

    Joined:
    Jan 9, 2005
    Messages:
    1,909
    Resources:
    15
    Skins:
    5
    Spells:
    9
    JASS:
    1
    Resources:
    15
    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?
     
  3. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    314
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    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.
     
  4. ssbbssc2

    ssbbssc2

    Joined:
    Aug 20, 2015
    Messages:
    108
    Resources:
    0
    Resources:
    0
    i did something like that in my map... with one timer and few variables \o/
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,200
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.​