• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Damage Detection (is this possible?)

Status
Not open for further replies.
Level 7
Joined
May 15, 2009
Messages
169
I have looked through a lot of damage detection systems, and it seems as though none of them have what I need...

Is it possible to combine "A unit is attacked" with "A unit takes damage"?

Example:
Foul Earth is considered damage; if I set the tick time on it to .2 and I have an ability that heals me when I take damage. I get healed a lot. This is bad.

I have 50% evasion; I am attacked. though 50% of the attacks miss, I still heal on every attack. This is bad.

What I need is something along the lines of checking if after a unit is attacked, he takes damage or not; and to check if the damage is from a spell, or an attack. (Some spells are actually counted as attacks, not sure why, but immo is, if you use "a unit is attacked").

This would be easy; if there wasnt a delay between the time an attack is made; and when the damage is dealt. On long range, slow missile units; this time can be very noticeable.

Anyone got an idea? Is there a system made to detect this that I havent found yet?
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Nestharus and I once thought about this
he required it for his ranged accuracy code snippet in the submission forum of the jass code snippets
didn't hear from it though
he probably has lots of work to do with his lua stuff

orb effects will help you do decide between attack and spell damage
further if you make different orb effects with different buffs and replace them every time a unit attacks you can make quite sure to detect the right attack

but triggering the whole missile stuff should be much easier
make all missiles instant and block the damage
use some missile/projectile system to fire a missile dealing damage equal to the blocked ammount
it also has the nice side effect of total control over everything what your missile does

or you could just trigger evasion but that would be lame
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
ehh...
->I have 50% evasion; I am attacked. though 50% of the attacks miss, I still heal on every attack. This is bad.

I've yet to think up a plausible way to get the damage source properties, but a script is being worked on to get DAMAGE_TYPE. It'll be able to see if the attack was ranged, melee, spell, and retrieve any of the DAMAGE_TYPE stuff associated with it.

And D4RK_G4ND4LF, have you seen my map header stuff? >: )

http://www.hiveworkshop.com/forums/submissions-414/snippet-lua_file_header-186775/

JASS:
//! externalblock extension=lua FileExporter $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i installscript([[function Hello() logf("hi") end]], "1.0", "MyScript")
    //! i dofile("MyScript")
    //! i Hello()
    //! i installjass([[
        //! i struct Tester extends array
            //! i private static method onInit takes nothing returns nothing
                //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "hello world")
            //! i endmethod
        //! i endstruct
    //! i ]], "1.0", "MyScript")
//! endexternalblock

gg
 
Level 20
Joined
Oct 21, 2006
Messages
3,231
If you are GUI noob like I, you could try this:

  • Damage System Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Trigger - Add to Damage System Run <gen> the event (Unit - (Picked unit) Takes damage))
  • Damage System Run
    • Events
    • Conditions
    • Actions
      • -------- Do Stuff --------
Thought you need to trigger every spell.... Because this trigger will run from ANY damage taken.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Not only will that script not work, but checking every spell isn't a good solution.


: P

Simple DamageEvent (best written damage detection)
http://www.hiveworkshop.com/forums/submissions-414/snippet-damageevent-186829/

The other necessary scripts are being worked on and they will be using what I just linked.


edit
As I continue to think about this, I continue to be lost as to a good way to do this ;P.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
personally I think that event leaks are overrated
I doubt that anything will happen unless I reach like 10000 but I would need that many units for it which would be a far greater problem

Thought you need to trigger every spell.... Because this trigger will run from ANY damage taken.

as I said already, orb effects are the solution

And D4RK_G4ND4LF, have you seen my map header stuff? >: )

yeah but I can't find any use for it and all the lua stuff
I stopped making spells and moved to C++ now
will probably make a game someday but I need to learn so many things first...
drawing, making models, all the code stuff and so on
but I should invest my time to study for school so I get damn awesome and not just only awesome grades but everything seems to be so stupid and unworthy to be learned
great anyway if someone needs it
could make lots of things easier I guess
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
->as I said already, orb effects are the solution

They are not...

You don't know which attacks actually hit and which didn't. This means that it's a guessing game and the probability is not even good ;\.

Also you don't need the orb effects. You can do a stack of attacks from a given unit to another unit and pop off the stack as attacks are applied. Again, you don't know which attacks are which unless you have like 500 levels of orb effects >.>.

Furthermore, aren't abilities applied after damage? :eek:.

Well actually, if the effect is applied before the damage, then that would be possible...

edit
Testing

and check out my UnitIndexer installation script before you talk about usefulness ;P

You see how tiny it is now? >: D
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("GetVarObject")
    
    //! i local id = getvarobject("Adef", "abilities", "ABILITIES_UNIT_INDEXER")
    
    //! i createobject("Adef", id)
    //! i makechange(current, "anam", "Unit Indexing")
    //! i makechange(current, "ansf", "(Unit Indexing)")
    //! i makechange(current, "aart", "")
    //! i makechange(current, "arac", "0")
//! endexternalblock

Also, dynamic JASS generation is extremely useful for scripts like SetUnitTypeId that run off of chaos. You have to parse through w3u or wts, retrieve all of the units, and then create a chaos level for each of them and load all of these things into a hashtable ;D.

edit
Do effects go through magic immunity? : o

edit
IT WORKED >: O

JASS:
struct tester extends array
    private static method test takes nothing returns boolean
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10000, I2S(GetUnitAbilityLevel(DamageEvent.target, 'Bfro')))
        call RemoveUnit(DamageEvent.target)
        return false
    endmethod
    private static method onInit takes nothing returns nothing
        call CreateUnit(Player(0), 'hfoo', WorldBounds.centerX, WorldBounds.centerY, 100)
        call CreateUnit(Player(8), 'hpea', WorldBounds.centerX, WorldBounds.centerY, 100)
        call DamageEvent.EVENT.register(Condition(function thistype.test))
    endmethod
endstruct

Where footmen has melee cold damage bonus, 'Bfro' is slowed, and peasant is spell immune >:O
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
->as I said already, orb effects are the solution

They are not...

You don't know which attacks actually hit and which didn't. This means that it's a guessing game and the probability is not even good ;\.

Also you don't need the orb effects. You can do a stack of attacks from a given unit to another unit and pop off the stack as attacks are applied. Again, you don't know which attacks are which unless you have like 500 levels of orb effects >.>.

Furthermore, aren't abilities applied after damage? :eek:.

orb effects work fine to distinguish between spells and attacks
and as long as the missile speed of all units is faster than their movement speed and their range isn't too big it should also work to distinguish beween attacks
but I just got the idea that the orb effect is not bound to the missile but to the unit itself
nevertheless it works fine to check if the damage was either dealt by normal attacks or spells
if I made a map today I would trigger all attacks anyway so it does not matter much

edit
don't these millions of abilities blow up the filesize dramatically?

edit
nice you tested the spell immunity issue
wasn't sure about it
and I am recording some movie on tv which I'll never watch and wc3 in fullscreen will crash everything but testing with JNGP and window mode does throw too many errors for 1 o'clock in the morning
could place the map in the map folder all the time and test from there after I started wc3 in window mode but then I read your post
nevertheless I'd use orb of corruption because it's easier to trigger slow than triggering armor reduction before damage (or probably it isn't but I think there was a problem when I tried it years ago)
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
don't these millions of abilities blow up the filesize dramatically?

Your idea worked... only need 1 ability, but it needs like 500 levels for stability : D.

edit
Already have all the JASS tools i need to make it...

but this will only be able to index attacks ; |... which will work brilliantly!! >: D

this could also easily tell between spell attacks and non-spell because the spell attacks won't have the effects on them... ; |, but then that means spell attacks won't be able to be indexed without their own indexing thing, oh well.

edit
Here's my idea (only requires 50 levels for epic stability ^_^)

2 objects total, works for melee and ranged although melee is faster ;o.

JASS:
    private static constant integer MAX = 50 //50 attacks per unit
    private static hashtable table = InitHashtable()
    private integer attack
    
    //on damage
    private static method test takes nothing returns boolean
        local integer i
        //attaack indexer basic code thus far ;o
        if (GetUnitAbilityLevel(DamageEvent.target, 'Bfro') == 0) then
            call UnitRemoveAbility(DamageEvent.target, 'Bfro')
            set i = GetUnitAbilityLevel(DamageEvent.source, 'Alft')
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(LoadInteger(table, i, DamageEvent.sourceId)))
            if (i == MAX) then
                call SetUnitAbilityLevel(DamgeEvent.source, 'Alft', 1)
            else
                call SetUnitAbilityLevel(DamgeEvent.source, 'Alft', i+1)
            endif
        else
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(thistype(DamageEvent.sourceId).attack))
        endif
        
        
        //call RemoveUnit(DamageEvent.target)
        return false
    endmethod

The attack retrieved would be an attack struct. Whenever a unit makes an attack, an attack struct is allocated, which stores data like damageType or w/e else. The lua script for this will be easy to make, but the problem is retrieving damage types ; O.

So yea, my AttackIndexer will be done probably tonight >: D. The Damage types will be another script.. : |

DamageModify will prob have to run on AttackIndexer and change to AttackModify or something. Hell, we can just get rid of the dern thing entirely, happy I didn't put it up.
 
Last edited:
Level 5
Joined
Nov 30, 2010
Messages
184
Try this:
Event: every 0.01 seconds
Action: if/then/else
--If unit_hp is greater then units hp
--Then show player red the message: you have lost +(real(unit_hp-units hp))+health
--Else
Set unit_hp to units hp

Unit_hp is a real for storing the unit's hp
This trigger goes off 100 times every second to minimize the effect of hp regen.
This is not MUI

I don't know JASS so I don't know what the other posts are saying.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Try this:
Event: every 0.01 seconds
Action: if/then/else
--If unit_hp is greater then units hp
--Then show player red the message: you have lost +(real(unit_hp-units hp))+health
--Else
Set unit_hp to units hp

Unit_hp is a real for storing the unit's hp
This trigger goes off 100 times every second to minimize the effect of hp regen.

Fail, lol.

Considering I'm doing an AttackIndex script, just wait for that. That's going to be your absolute best solution.

edit
My script will hopefully be done tonight. It's almost done, I'm just being lazy about writing it. I'm more wandering about ;O.


The script will be able to tell between spell attacks and physical attacks (two separate events). On physical, it'll be able to tell between ranged and melee (sorta). It just checks unit type and distance > 128 or (not IsUnitType(u, UNIT_TYPE_MELEE_ATTACKER)) for a ranged attack.

set ranged = (distance > 128 or not IsUnitType(unit, UNIT_TYPE_MELEE_ATTACKER))

Yea, it could fail as some attacks may be melee but only target air or some bs, meaning the ranged attack is used over the melee at close range. There are all sorts of issues ; (, but anyways, that's my current detection for checking between ranged and melee, a detection that will likely be commented out because it's so fail >: D.

So what I'm saying is detecting range is fine, but detecting melee is not : O.


edit
Ok, this is getting harder as I work more on it ;o.

For spell attacks, there is no way to detect them w/o triggering them. The reason is because there is no way to retrieve the effecting spell on damage event. Sure, I can store the spell level and etc and I can def detect physical attacks. The problem is that multiple spells may be targeting a unit with delayed effects (storm bolt or w/e, etc). The only way to tell that an attack wasn't a physical is to check to see if a buff is present that's attached to the physical attack. This buff not being present just means that the attack wasn't physical (UnitDamageTarget, slew of spells, and etc). With a possibility of multiple spells and no way to detect which are which, the only thing I can do is EVENT_ATTACKED_UNKNOWN, EVENT_TARGETED_PHYS, EVENT_ATTACKED_PHYS, or something like that.

Furthermore, I can't recycle attacks easily as they could have cleave and etc... I have to recycle previous concluding attacks on a timer to ensure that they are all done being applied. Why can't I do it on the next attack? Units can be ordered to attack, and as such, a unit can be ordered to attack another in between applied damages.

Really, this thing is getting crazy. The lua object script was easy compared to the rest >: D.

Why don't I just recycle as I come back across? With 1000 units on the map and 50 allocated attacks per unit, that's 50000 attacks, which is well over the 8191 array size limit.

But believe me, I WILL index physical attacks even if it kills me >: O. The rest will be up to you guys.

If you guys really wanted indexed spell attacks, I'll try and figure out a way that doesn't involve adding effects to every single spell via lua, rofl rofl =P. In fact, i want indexed spell attacks, so I'll try and figure out a way.

Everyone think with me!! >: D.


So yes, to be clear, atm I have phys attacks working just fine... everything else is unknown >: O.
 
Last edited:
Status
Not open for further replies.
Top