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

[JASS] Recreating Damage Event Trigger

Status
Not open for further replies.
Level 2
Joined
Oct 25, 2014
Messages
12
Hello.

I have been meaning to implement a damage detection system in my map that is Hero centric; i.e every player will have 1 Hero, and only damage dealt to the Heroes or their targets will trigger the event. I am not good at Jass Coding or any of the sort, I just use it whenever I need to (removing leaks, etc), so bear with me.

So the rough idea is that every time a Hero is ordered targeting an enemy unit (or automatically acquires one through AI, though not yet implemented in the trigger to come), that target of issued order will added as an "Event - Specific unit (target of issued order) takes damage" to a brand new trigger newly created (HeroAttack...). This trigger HeroAttack... will be destroyed when the same Hero is issued an order targeting a new unit. This is to prevent an endless amount of event stacking on top of a single damage detection event.

Stage%201%20Target%20Trigger.png


However, I am running into issues creating the actions for the new HeroAttack... trigger. The actions should essentially be the following:

Stage%202%20Target%20Trigger.png


All I want for this event is to set which target is attacked and who is the attacker. The trigger "Hero Attack Damage" is then run with the variables already set, where the actual damage bonuses/mitigation happens.

However, I just can't seem to get the function names right, or I get whatever other error there is from messing around with the custom script. If it is possible to add the actions of "Damage Detect Pre" to the newly created "HeroAttack[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))])" through custom scripts in "Target", this would make it come together. But I don't know Jass.

Here was one attempt, which lead to a Syntax Error:

Stage%203%20Target%20Trigger.png


I appreciate any help, and I hope I've explained my intentions and issues well enough.
 
It is possible that the arrangement of your script caused such a malfunction. If the handler function exists, it could be below the script calling such function.

Damage Event Triggers are created usually on the initialisation of the map (via A unit enters the World Region, combined with a For Group call.) You don't need to dynamically create a damage event every time an attack order is issued, since that would just be wasting resources.

What most Damage Event Triggers do is to take advantage of the initialisation process involving units, registering them to it once they have entered.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
It is possible that the arrangement of your script caused such a malfunction. If the handler function exists, it could be below the script calling such function.
This is usually the case. I've found that the only real way to get around this is to make a dummy function in the Custom Script section and then use it to ExecuteFunc() your trigger actions. This is really not a good solution. As MyPad suggested, Damage Detection Systems are very optimized nowadays and you're actually causing more work for the game by creating and destroying triggers on every attack than it would be to have an event for every unit on the map on the same trigger. It is much more efficient to just install a DDS (for GUI I recommend this one, there are other JASS ones too if you're comfortable with that) and filter out damage events that aren't caused by heroes or that damage heroes. The system I linked can even differentiate between attack damage, spell damage, and code damage!

If you insist on doing it your way this is what you need to do:
JASS:
//put this in your map's custom script section

function PleaseDontButOkay takes nothing returns nothing
    //Might need to set some global variables here first
    //Triggering Unit will work in the Executed function but not sure about Damage Source or anything else

    //If you type the name of a function that doesn't exist or change the name of your trigger and don't update this the ExecuteFunc will crash the game
    call ExecuteFunc("Trig_Damage_Detect_Pre_Actions")
endfunction

//In the trigger you posted change the last part of the call to match the function name above
call TriggerAddAction(... , function PleaseDontButOkay)
 
Level 2
Joined
Oct 25, 2014
Messages
12
Thank you both for your help. I am a bit obsessed with keeping it my own code, as I want kind of complete understanding and control of things, but I will give these damage engines a try if they allow the map to run smoother. Rep for the both of you.
 
The error in your script should be the "()" around the function name.
Also when your map head script is empty the jass checker throws errors, if you point to functions from other triggers. JassHelper does not care about this pointing problem.
You might look at this to more simple post triggers: How To Post Your Trigger

Edit: But your Trigger Leaks 1 TriggerAction per targeting with that beeing quite heavy.
 
Last edited:
Level 38
Joined
Feb 27, 2007
Messages
4,951
I am a bit obsessed with keeping it my own code, as I want kind of complete understanding and control of things
That's the whole point of the systems having good documentation and there being a thread you can post in to ask questions about how the system works if you can't understand it. And the code section is curated by the moderators to make sure things don't do unexpected stuff or have map-breaking bugs in them.
 
Status
Not open for further replies.
Top