1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  5. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Zwiebelchen's Threat System 2.7

Submitted by Zwiebelchen
This bundle is marked as approved. It works and satisfies the submission rules.
What is a threat system?
Basicly, it's a system that takes over Mob AI. The unit that dealt the most damage to the creep will be the one that gets attacked.
Although that is only half the truth, it should be enough to get the idea.

If you ever played World of Warcraft (as a mapper, you should have), chances are you know what a threat system does.
And this is an almost perfect replica of it.


Requirements:
- vJass preprocessor

What is different from this to other systems:
- First of all, this system is almost (if not completely) 100% fail-safe. It does checks on killed AND removed units and clears them automaticly.

- Second, it features a unique camp squad functionality, which ensures that units that are preplaced in camps will always attack and return together. If units return, they will be rendered invulnerable until they reach their original camp position again. If they can not reach their camping position within a certain duration, they will get instantly teleported back.
Like this, there is almost no more kiting or bug-abusing possible, as it was with other systems.

- Third: It does not block other Spellcasting systems. The system will only give orders to units, if the unit either has no order (i.e. auto-engage) or an "attack" order. If you want the unit to use a spell instead of attacking, you can do so whenever you want without having to fear interference of the system.
In fact, there is a special function provided so that people can create their own Spell-AI directly in a custom trigger

- Fourth: It provides a lot of useful functions and Getters (Like ApplyHealThreat or GetCombatState), to make triggering spells even more easy.

- Fifth: It is, by far, the fastest and most flexible threat system out there. I completely remastered the system from the last version and the entire script (except for certain enumerations that can not be avoided) is now O(1) complexity.


Version history:
2.7
- Fixed a bug that sometimes did not properly render units in-combat if pulled again right after returning to camp position

2.6
- Added a new function: ZTS_GetCombatTime, which returns the time an npc unit is currently in combat; returns 0 if the unit is currently out of combat or returning to camp position; does not work on player units

2.5
- Added a new boolean to the ZTS_AddThreatUnit command that determines wether the added unit shall be added to already fighting Creep Camps or only to non-fighting Creep Camps - this is interesting when you create encounters that summon units as you usually don't want those summoned units to create their own Creep Camp but want them to be added to the Boss' Creep Camp
- Fixed a small bug that sometimes caused linked Creep Camps

2.4
- Fixed a bug sometimes rendering units permanently invulnerable, when registering a unit in close range to currently retreating units

2.3
- Changed TriggerActions of dynamic triggers to TriggerConditions, to avoid nasty action leak
- Fixed GetThreatUnitAmount (did not return the correct value)

2.2b
- fixed a small logic bug with GetThreatUnitAmount and GetThreatUnitPosition

2.2
- Now uses "smart" order instead of "attack" to issue attack orders ... it turned out that the "smart" order returns false if the unit can not reach the target (for example when rooted) - weird, as it doesn't work for "attack" for some reason
- because of that, the AddRootAbility function and the Range Setter and Getters were removed, as they have become obsolete

2.1b
- fixed a small logical bug with GetCombatState sometimes returning a false positive

2.1
- rebuilt Update function to avoid some useless enumerations - depending on the number of PlayerUnits registered, the system should now be MULTIPLE TIMES faster - As a side effect, I could also remove some useless variables

2.0
- Initial release

Comments & Discussion:

Why hashtables instead of global arrays and structs?
- hashtables are not limited in terms of max size, unlike and array of structs with a unit array, which reaches the 8000 limit very fast ... this was basicly the most important point on that decision
- hashtables are more flexible and easier to use (Flush functions, etc.)
- hashtables were benchmarked to be only 60-80% slower than getting UnitUserData alone

Where is the sort function?
- version 2.0 and higher does not use sorting anymore; instead, when threat is applied to a unit, it uses an insertion method to keep the order of the list

What is new compared to pre 2.0 versions?
- Aside from the fact that the system now is a dozen times faster than before, I also improved the AI by using the "smart" instead of "attack" order. It turned out that - in a weird way - "smart" is indeed smarter than other orders, as it returns false if the unit can't reach the target (i.e. because of root)
- There is now a way to directly get an Order event by the threat system, to make creating spell-AI easier.

Does it matter how many units are registered to the system at the same time?
- In terms of speed, no; it only affects memory usage, but that should not have an impact on game performance at all, even with tousands of units registered - only the number of currently fighting units affects runtime

I still do not really understand how to use the system...
- just check the demo map and you'll get the idea

Keywords:
threat, aggro, wow, world of warcraft
Contents

Threat System v2.7 (Map)

Reviews
Moderator
17:56, 17th Jan 2010 TriggerHappy: Very good, and you know what my suggestions are. This can be approved in it's current state, though.
  1. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    The Spells I handle manually are only dummy spells - part of custom abilities for the player, but they are not handled by Neutral Hostile. As such, the only time I manually order Neutral Hostile so far, is when I tell them to "Attack Move".
     
  2. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,867
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    You register your units with the wrong function here.

    ZTS_AddPlayerUnit is for player controlled units only. Player units will never receive any orders by the system. Instead, player units are the units that can build up aggro on other the units added by the other registering function.
    For the threat AI to actually control units and have threat lists, you must use ZTS_AddThreatUnit on these units instead.

    Example:
    Player 1 has and controls a hero that can build up threat on units owned by neutral hostile -> ZTS_AddPlayerUnit on that hero
    Player Neutral Hostile controls creeps that have threat tables that Player 1's units can be listed in -> ZTS_AddThreatUnit on that creep

    Also you are not applying any threat anywhere in these triggers. If you just register the units without ever applying threat, nothing is going to happen and the units behave as if they were never added to the system until they receive at least 1 point of threat from any source.
    If you want threat applied by dealing damage, you need a damage detection system and apply threat via ZTS_ModifyThreat for the amount of damage dealt.


    Besides, it's not smart to attack-move units away from their initial registry position. They will eventually return to their original spot if they move too far. From what I see here you have some kind of defense event going on? In that case, make sure the return range is high enough so that the units can move from P1 to P2 without getting out of range of the original spawn location.
     
    Last edited: Sep 27, 2017
  3. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    Thank you for answering.
    You were right of course, about me using the wrong function on the spawned creeps. This was a minor trigger, so I hadn't really noticed the effect - (or lack thereof).
    I am using Bribe's damage detection system, and it works just fine with this as well. Your debug window is really helpful for testing. Also I've kept the issues with move-orders in mind, but in these cases we're talking something like a 400 unit distance, so it's well within the return range.
    Anyway, I guess it's something else I have that interferes with Neutral Hostile AI then, so I'll keep digging at that.
    Thank you for helping me out - and for giving us this system of course.
     
  4. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    So I finally found a way for Neutral Hostile mobs to start using their normal abilities again. I had to change the attack order to "attack" instead of "smart" in your trigger. After doing this, the Neutral Hostile creeps would use their native spells again.
     
  5. Vasialalko

    Vasialalko

    Joined:
    Oct 13, 2018
    Messages:
    7
    Resources:
    0
    Resources:
    0
    Does not work on current patch :(
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,192
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    What doesn't work about it?
     
  7. Solemin

    Solemin

    Joined:
    Aug 18, 2019
    Messages:
    8
    Resources:
    0
    Resources:
    0
    Seems like AoE healing abilities (tested with Replenish and Essence of Blight) aren't registered initially. Attacking / using a different kind of healing spell (e.g. Heal) adds the unit to the registered ones and then continually increases threat when using those AoE healing abilities.

    Any chance to lend a helping hand in how to add such healing abilities to the ApplyHealThreat function?
     
  8. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,867
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Just register the cast event of these abilities and use the HealThreat function once on that unit. It does exactly what you want.
     
  9. Solemin

    Solemin

    Joined:
    Aug 18, 2019
    Messages:
    8
    Resources:
    0
    Resources:
    0
    Easier said than done. Due to the functionality of mentioned abilities (Essence of Blight / Replenish) they do not have a target, but instead are point-blank AoE abilities. And due to not having a specific target, no allies on the threat-list are picked leading to the caster not being added to the threat list.
    So, I'm searching a way to get the caster registered on the threat list even though he's not having an ability-target (ally).

    For now I've done a workaround by dealing 0 damage to all units in radius x around the caster which adds the caster to the threat list. However, I was hoping to find a cleaner way ...
     
  10. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,867
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Use ApplyHealThreat and set the caster for both source and target (as if you used a healing spell on yourself)
    It will apply threat equally to all units currently aggroed.
     
  11. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,867
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    It works fine.