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

Detect attack type

Status
Not open for further replies.
Level 5
Joined
Sep 1, 2010
Messages
168
Hi folks!
I'm currently trying to make some item ability abuses impossible in a WIP map...
What I need is a consitional check to see what kind of damage a unit is dealt (spells, magic, hero, siege...) to prevent a certain ability (event - triggering unit receives damage) to trigger from the unit being hit by a spell.
Usually I wouldn't mind that much, but there are some spells in the map that deal damage in aoe and that in very short intervalls (meaning every 0.1 seconds). Thus, I want to exclude those spells from triggering the item's effect (a dummy unit casting a shockwave).

Does anybody know a function/system to achieve this? I don't mind it being GUI or JASS (no vJASS though), but I need it GUI.

The usual +rep and credits for help.
If it's impossible I must change back to the abusable 'event - a unit is being attacked' event :thumbs_down:
 
Level 7
Joined
May 13, 2011
Messages
310
Well, I've been looking around, and I can't find a way to detect an attack type dynamically. However, would it be possible to make Unit Type arrays based on attack types? For example, put all Units Types with Normal attack type in NormalAttack, all those with Spell attack type in SpellAttack, etc. Then, later on, you can dynamically check which array the attacking unit is in.

Of course, this would be a bit bothersome since you need to group all the unit types in the map, but it's the only solution I can currently conceive.
So you'd set your arrays similarly to this:

JASS:
local unittype array NormalAttack
set NormalAttack[0] = 'hpea'
set NormalAttack[1] = 'hfoo'
//continue on doing this for all unit types

You put all unit types that have a Normal attack in the NormalAttack array, all those with a Spell attack in SpellAttack, and so forth. In JASS you'll have to refer to them with their raw ID, which you can see by pressing CTRL+D in the Object Editor.

Then once you've got that, you'd do something like this to check out what array the attacking unit is in:

JASS:
local integer i
local integer NumberOfUnits
set i = 0
set NumberOfUnits = 2 //I'm doing 2 because my previous example only had 2 units, you will have many more
loop
    exitwhen i == NumberOfUnits
    if(GetAttacker() == NormalAttack[i]) then
        //do your fancy stuff here
    endif
    //make more if statements for your other Unit Type arrays
    i = i + 1
endloop

That's basically what you'd do. My code all has local variables so you'd have to do it all in one function, but I haven't really got the hang of JASS variable scopes. Maybe you can make them global and put the loops in a different function than the Array declarations, I dunno.

It's not the most convenient solution, but that's the best I can think up right now.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
Puggsoy, that doesn't solve the question "is the attack a spell or a physical attack?", which is basically what he asked according to me.
Also, your JASS is a bit flawed (creating a local after setting a variable + you don't need more loops).

I believe Nestharus once said he was going to create something like this... not sure, but it's worth asking him.

Umm, otherwise you might do: if unit starts the effect of an ability -> set spellAttack = true, wait 0.00 seconds, set spellAttack = false.
If spellAttack is true, then skip the damage event.
This doesn't work for DOT spells though, and it can be bugged (even though a 0.00 wait isn't very long).
 
Level 7
Joined
May 13, 2011
Messages
310
Hmm, from what I understood, he wanted to be able to detect if a unit's attack has the Attack Type value of Spell, Normal, Pierce, Siege, and so forth. That's what he said...

ThaAthael said:
What I need is a consitional check to see what kind of damage a unit is dealt (spells, magic, hero, siege...) to prevent a certain ability (event - triggering unit receives damage) to trigger from the unit being hit by a spell.

So yeah.
However, you are correct about my flaws. I very often forget about JASS's strange variable declaration rules, so thanks for that, and thanks for bringing my attention to not needing multiple loops. I'll go and edit my post straight away.
 
Level 7
Joined
May 13, 2011
Messages
310
Are you sure he means an actual Spell and not a Spell Attack Type? I don't know why else he would refer to all those other types...

ThaAthael said:
...what kind of damage a unit is dealt (spells, magic, hero, siege...) to prevent...
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Yes, I'm sure.
It's a very common problem in damage detection systems: people don't want their effects to activate when damaged by a spell.

ThaAthael said:
Usually I wouldn't mind that much, but there are some spells in the map that deal damage in aoe and that in very short intervalls (meaning every 0.1 seconds). Thus, I want to exclude those spells from triggering the item's effect (a dummy unit casting a shockwave).

Maybe he needs different attack types as well, but he definitely needs to be able to separate spells from actual attacks.
 
Level 7
Joined
May 13, 2011
Messages
310
@ap0calypse: Ah, I see now. :ogre_icwydt:
Yes, you're probably right. Still, as you said, it's possible he wants both.

Whatever the case, he's probably got his answer now. :thumbs_up:
 
Level 5
Joined
Sep 1, 2010
Messages
168
Miraculous - you're out of house a few hours and people get headaches about what my intention is.
Basically, you're right, ap0calypse:
I want to differ between a unit's attack and a DoT spell (like flamestrike) from the same unit that can be active at the same time the unit is attacking.
Unfortunately, wc3 coding uses for spells like flamestrike too the *order unit to damage area/unitsinrange/whatever for xyz damage of type blahblubb badablubb* event.

My problem is, either I detect whether a unit is attacked -> which would bug when a player frequently stops atacking, thus enhancing the chances to trigger the item's spell ability by extrem high start/stop of starting to attack

OR

I use a unit is being damaged - which is done too when a unit is dealt damage via a trigger or any kind of hard coded ability dealing damage (chain lightning, mana burn, DOT spells, autocast additional damage stuff, you get my point).

My problem is I cannot think of any way of excluding the abuses inbetween.
If I were to recode each and every spell of my map (it's an AOS..) I could turn the item's trigger off, damage, turn it on and be happy.. but with like already 50 spells (often just the custom stuff from wc3 engine like crit abilities and so on), I'd have an already almost impossible quest in front of me :(

in short:
(tl;dr)
exclude damage from spells to trigger the item's ability (cast) from triggering, but mundane attacks (whatever type like siege, hero, ...)still triggering the effect -but how?
 
the easiest way would be to make all spells use customized damage (meaning like making a damager unit per player which will deal the damage, and filter it out so that damages coming from that type of unit will not trigger the damage effects)

or you could try to use Nestharus' damage system, though because of the wc3 engine itself, the system bugs when the unit has a bouncing missile attack or artillery attack...

well, you would need to do it, unless you want to scrap the idea of being able to differentiate between physical attack damage and spell damage...
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
[...]

I believe Nestharus once said he was going to create something like this... not sure, but it's worth asking him.

[...]

so far the only system I know which will let you filter normal attack from spells would be Nestharus' Damage system... though it seems like due to the coding of the wc3 engine, it bugs if the unit uses bouncing missiles or artillery attack...
Nestharus is the answer, go seek him out! :p
But, apparently, not the best answer...


Recoding the spells would indeed be a tough job... it'd be the only foolproof way to actually do this I think.
50+ spells may a bit too much though.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
oh my god
nestharus did something similar!
fast! everyone forget about how it we did it when he wasn't there!

just add an orb effect (nestharus is using orb of frost but it seems to have issues with mass attacks) to every unit which is removed per trigger as soon as the unit takes damage
if the damage event fires and the unit has a buff (orb of corruption buff for example) the damage was physical
else it was not

this will break bounce attacks so it would make sense to trigger all ranged attacks (which gives many more possibilities to do fancy effects like deflect and stacking orb effects to just name a few)

and this is like the 10th time I am writing this
does no one ever read what I write?
and why even bother to use the search engine
nobody does anyway
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
oh my god
nestharus did something similar!
fast! everyone forget about how it we did it when he wasn't there!

just add an orb effect (nestharus is using orb of frost but it seems to have issues with mass attacks) to every unit which is removed per trigger as soon as the unit takes damage
if the damage event fires and the unit has a buff (orb of corruption buff for example) the damage was physical
else it was not

this will break bounce attacks so it would make sense to trigger all ranged attacks (which gives many more possibilities to do fancy effects like deflect and stacking orb effects to just name a few)

and this is like the 10th time I am writing this
does no one ever read what I write?
and why even bother to use the search engine
nobody does anyway
I do read what you write, I simply did not know it worked like that.
Excuse me for my ignorance, but you're still overreacting..
 
Level 5
Joined
Sep 1, 2010
Messages
168
Dark gandalf, as you said yourself, the system bugs on attacks like artillery and bouncing attacks... unfortunately, one of them is already in my map, the other is likely to be used as well..

About using the search engine: I treid, but I've been flooded with threads that led into the wrong direction (guess I've simply used the wrong keywords).

Still I appreciate your efforts to help alot... it's just, that your solution won't work for me, unfortunately.. so I'm stuck between chosing 1 system that won't do what I want it to do and another giving me other headaches :S
And won't adding orb effects like orb of corruption interact in unpleasant ways with other orb effects like lifesteal or frost arrows? :eekani:
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Dark gandalf, as you said yourself, the system bugs on attacks like artillery and bouncing attacks... unfortunately, one of them is already in my map, the other is likely to be used as well..

About using the search engine: I treid, but I've been flooded with threads that led into the wrong direction (guess I've simply used the wrong keywords).

Still I appreciate your efforts to help alot... it's just, that your solution won't work for me, unfortunately.. so I'm stuck between chosing 1 system that won't do what I want it to do and another giving me other headaches :S
And won't adding orb effects like orb of corruption interact in unpleasant ways with other orb effects like lifesteal or frost arrows? :eekani:

that's why I said it would make sense to trigger the attack
just make all ranged attacks instant, heal the target when it takes the damage (damage detection system), make a missile which deals the damage instead, trigger orb effects/bounce/multi missile/arc/splash etc.
much more control to make awesome effects
it's some work but it is worth the effort

Excuse me for my ignorance, but you're still overreacting..

how could I overreact
the only thing I have at my disposal is an array of more or less random bits
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Well, also, another problem with orbs is that you need 2 types of orbs, one for detecting splash attacks and the other for detecting all other attacks. This is why orb of frost and frost breath were used, because no other combination seemed to do it.

As was stated, orb of frost does seem to have issues when being hit by mass units. However, when I did use it myself in a hero line wars map (talking about major masses of units here), I didn't see any problems, so I've yet to encounter this issue ; ).

If you are using bouncing or the "attack ground" order with artillery attacks, then you have no choice but to code all of the spells from scratch.
 
Level 5
Joined
Sep 1, 2010
Messages
168
Thank you all for your input, guess I'll have have to recode a bunch of things then :goblin_boom:
Well, seems I'll have to freeze the project again (exams coming up soon).
Thank you all for your help, hope I haven't forgotten to hand out rep to anyone :)
 
Status
Not open for further replies.
Top