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. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  5. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  6. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  7. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  8. 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. Sunchips

    Sunchips

    Joined:
    Jul 23, 2009
    Messages:
    872
    Resources:
    123
    Models:
    112
    Icons:
    4
    Packs:
    7
    Resources:
    123
    Sounds just about right. Chill chill.
     
  2. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Updated to 2.7:
    - Fixed a bug that sometimes did not properly render units in-combat if pulled again right after returning to camp position
     
  3. Sunchips

    Sunchips

    Joined:
    Jul 23, 2009
    Messages:
    872
    Resources:
    123
    Models:
    112
    Icons:
    4
    Packs:
    7
    Resources:
    123
    [​IMG]
     

    Attached Files:

  4. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,162
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Just wanted to leave this here for anyone looking to use this system with DamageEngine/UnitIndexer
     

    Attached Files:

  5. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Thanks for the above contribution. I pretty much already use it in combination with UnitIndexer for my purposes, but I never made that build public.

    At some point in the future, I might completely rewrite this to use a cleaner struct syntax approach. While the current implementation is very effective from a performance point-of-view, it couldn't hurt updating it for better readability.
     
  6. GIMLI_2

    GIMLI_2

    Joined:
    Mar 21, 2011
    Messages:
    1,370
    Resources:
    2
    Maps:
    2
    Resources:
    2
    hi, i dont get the AI part to work. if the NPC does not change its attack target, it wont receive a new order and wont cast the spell again, and i have no clue how to fix that in an easy way
     
  7. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Post the code if you want help. Make sure to check out the demomap properly first; it has an example for spell AI.
     
  8. GIMLI_2

    GIMLI_2

    Joined:
    Mar 21, 2011
    Messages:
    1,370
    Resources:
    2
    Maps:
    2
    Resources:
    2
    • Events
      • Unit - A unit owned by Neutral feindlich Erhält einen auf ein Objekt zielenden Befehl
      • Unit - A unit owned by Neutral feindlich Erhält einen Befehl ohne Ziel
    • Conditions
      • (Unit-type of (Triggering unit)) equal to Snowpaw
    • Actions
      • -------- Use ZTS_IsEvent in combination with Order Events to issue special orders (for example spells) --------
      • -------- Ordinary Wc3 spells will be used randomly be creeps even with the threat system active --------
      • -------- so you only need this when you want to manually order certain things --------
      • Custom script: if not ZTS_IsEvent() then
      • Custom script: return
      • Custom script: endif
      • Unit - Order (Triggering unit) to Orc-Troll-Berserker - 'Berserk'


    it works just like in the test map, the event fires once the unit enters combat, but then it waits for a new order (which only happens if someone else takes over aggro)
     
  9. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Maybe its something with the spell you're using. Can you post what it does?

    What you can do to troubleshoot is trying to periodically get the current order of the unit after issueing the berserk order once. Does it go back to none, "smart" or "attack"? If not, then the system will not reissue any orders. It will only apply new orders if the unit has no order, a smart or an attack order. Even move orders will interrupt any automatic orders by ZTS.
     
  10. GIMLI_2

    GIMLI_2

    Joined:
    Mar 21, 2011
    Messages:
    1,370
    Resources:
    2
    Maps:
    2
    Resources:
    2
    It is just a basic spell that i used for testing. I think the first one was 'spawn ghost wolves' and the second 'berserk'. The unit immediately goes back to smart order after casting an ability. The thing is, it has the same result in your test map. There are 2 units that spawn ghostboars.(this is the example trigger for AI), but they also cast it only once when entering combat (or, as i said, when changing aggro target). Maybe it has sth to do with the new sharpcraft editor?
     
  11. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Add a text message to your trigger to see if it runs periodically. This way you can find out if its something with your spell or with your trigger.
     
  12. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    I love this system. But I seem to have run into a problem.
    My Neutral Hostile units won't cast their standard spells when registered in the Threat-System. If I try to remove them in-game, they will cast their spells regularly again.

    From what I understand, they are still supposed to be casting regular spells when, even when they are controlled by your system. Do you have any idea what could be causing this?
     
  13. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Neutral hostile will never cast regular non-autocast spells. Only computer players will.
     
  14. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    Usually I don't have any problem making Neutral Hostile cast spells based on abilities like Blizzard (Neutral Hostile), Frostbolt, Roar, etc.
    And as I mentioned - whenever I remove a Creep from the system with your "call ZTS_RemoveThreatUnit(unit npc)" function. They will cast their spells at random again.

    I just hoped the system wouldn't interfere, since you also wrote in your demo-map:

    "Ordinary Wc3 spells will be used randomly by creeps even with the threat system active"
     
  15. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Just to go sure: do you issue any orders manually in your game? I'm asking that because even with neutral hostile AI being different from computer player AI, neutral hostile should still occasionally use certain spells.

    What spells are you using here? Remember that neutral hostile will not spam spells like Blizzard or Frost Bolt. The AI will only use them when the requirements are met (like having a cluster of attacking units for Blizzard, etc).
     
    Last edited: Sep 25, 2017
  16. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    I have some spells being handled manually. None that involve the units I'm trying to create here though.

    So if I want threat-registered neutral hostile mobs to cast spells - I need to script them individually?
    I suppose the solution would be to assign them to a computer player then, I just really would like the level of the mob to be easily visible in this map, the way they are on Neutral Hostile.
     
  17. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Post your manual control triggers. Neutral hostile should use certain spells just fine.
     
  18. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    I don't think I have any triggers that interfere with neutral hostile behaviour actually.

    Could I send you the map? In case you have access to the World Editor right now. I've set it up so it's immediately visible where the problem lies.
     
  19. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,832
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    You said you "have some spells being handled manually". Post these triggers.
     
  20. Guineafowl

    Guineafowl

    Joined:
    Jun 20, 2009
    Messages:
    15
    Resources:
    0
    Resources:
    0
    These are the kind I have. Triggered by events. But they haven't even fired yet when I test the creep behaviour.





    Murloc Spawn.jpg Spider Spawn.jpg