HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple JASS Question

06-14-2006, 06:19 AM#1
Pheonix-IV
Pretty simple question, i'm not quite at the learning JASS stage yet, but i'm definitely looking at it.

Concerning the Event - Unit Takes Damage, in GUI its a specific unit event, with JASS, can i make an Any Unit Takes Damage event? Is this possible (or feasable) without adding huge numbers of events each time a unit appears on the map. Or not?
06-14-2006, 06:37 AM#2
PipeDream
http://www.wc3jass.com/viewtopic.php?t=2608

There's a little problem with that though. Since TriggerRemoveAction blocks the rest of the thread*, rearrange RemoveDamageTriggers like so:
Collapse JASS:
function DestroyTriggerLater_cb takes nothing returns nothing
    local timer oTimer = GetExpiredTimer()
    local trigger oTrig = GetHandleTrigger(oTimer,"trigger")
    call DestroyTimer(oTimer)
    call FlushHandleLocals(oTimer)
    set oTimer = null
    call DestroyTrigger(oTrig)
    call FlushHandleLocals(oTrig)
    set oTrig = null
endfunction

function DestroyTriggerLater takes integer iTrig returns nothing
    local timer oTimer = CreateTimer()
    call SetHandleInt(oTimer,"trigger",iTrig)
    call TimerStart(oTimer,0.,false,function DestroyTriggerLater_cb)
    set oTimer = null
endfunction

function ItoTrig takes integer i returns trigger
    return i
    return null
endfunction

function RemoveDamageTriggers takes nothing returns nothing
    local integer iTrig = GetHandleInt(GetTriggerUnit(),"TakeDamageTrigger")
    call DestroyTriggerLater(iTrig)
    call TriggerRemoveAction(ItoTrig(iTrig),GetHandleTriggerAction(ItoTrig(iTrig),"action"))
endfunction
06-14-2006, 06:37 AM#3
Blade.dk
You will need one event per unit in JASS too. The A Unit Takes Damage Event only exists as a single-unit event. But using JASS might make setting it up take less time.
06-14-2006, 09:23 AM#4
Pheonix-IV
Darn, would such a trigger cause noticable lag in SP assuming i fix up any leaks and make it as effecient as possible? I ask because i'd rather use "Takes damage" than "Is Attacked" for various triggered passives, as it means the passive actually fires upon impact rather than when the attack occurs.

As for pipes code, what do i actually need to change to make that work?
Lets say i have a trigger that picks a random interger between 1 and 100 and if its below or equal to 15 it causes the attacking unit to deal 20 damage to the targeted unit. Can you give me some code that allows me to just call the trigger i want to call and stores the Damageing Unit and Damaged Unit in unit variables for use by other triggers? I tend to learn better when i get code that i can modify slightly on my own.
06-14-2006, 12:03 PM#5
Captain Griffen
In single player, unless you have tens of thousands of units, it won't lag.
06-14-2006, 04:24 PM#6
Rising_Dusk
Quote:
...fires upon impact rather than when the attack occurs.

That's untrue.
The 'when damaged' event fires whenever a unit takes damage, period.
That damage might be a spell or it might be an attack, with just that even there's no way to tell.

What you're looking for is a attack damage detection system.
There are a couple ways of making one, but I believe in Vex's caster system he used one with orb effects.
06-14-2006, 06:32 PM#7
blu_da_noob
Yes, the most accurate way of differentiating between attacks and spells is having all units have an orb ability which leaves a buff, and have a check in the damage trigger. If the damaged unit has the buff, it was an attack (also remove the buff here), otherwise it was some other source.
06-15-2006, 12:15 AM#8
Rising_Dusk
One question about that though.
Will the buff ever be seen by the person getting attacked? Or is it quick enough to remove before it's ever seen?
06-15-2006, 12:34 AM#9
harshateja
Im guessing that it will be seen for a split second if at all. In anycase, you could just replace the buff's image with a black blp so if it does show up, it won't be noticable for that split second unless the user randomly places their cursor over it that second.

I might be wrong on this but orb abilities do not stack and so if you use that technique, you might run into some problems. The way I would do it is have both an "any unit takes damage" event (which this whole thread is about so there is enough information about that) and have an "any unit is attacked". Store a variable in both cases and if the same unit takes damage and is attacked, then it is attacked but if it takes damage and the unit is attacked event does not fire, then it is from a spell or trigger. Also, remeber if you do it this way, check if the unit is atttacked but does not take damage because if that is the case, then the attack has been evaded (physically moved out of the way of an artillery attack) and you might wanna keep that inc onsideration. This techinique has its own host of problems but it is what I use so...
06-15-2006, 01:03 AM#10
Rising_Dusk
Nah, if you use your idea and you have target homing on and the enemy you attacked is running away, it's very likely they may take damage from another source before your attack hits or misses, causing huge errors in the system.
Also, there is no "any unit takes damage" event. (Don't we wish there was)

And the orb effects dont have to stack.
If you want to make an orb effect with Vex's system, trigger it.
Since you already know if a unit takes damage from an attack, just run % chances based on items in the damager's inventory for other effects (Done via dummies and triggers, obviously).
06-15-2006, 03:32 AM#11
harshateja
Quote:
Originally Posted by Rising_Dusk
Nah, if you use your idea and you have target homing on and the enemy you attacked is running away, it's very likely they may take damage from another source before your attack hits or misses, causing huge errors in the system.
I don't see how you would get errors there. As long as the number of units attacking the same unit at anymoment is less than or equal to 256 (the gamecache limit), you will be fine.

Quote:
Originally Posted by Rising_Dusk
Also, there is no "any unit takes damage" event. (Don't we wish there was)
Even if there was, it would do a similar thing as creating a trigger and registering a new event for each unit and (hopefully!) cleaning it up when the unit is removed or killed.
06-15-2006, 03:55 AM#12
Rising_Dusk
To be fair though, I think you can agree that a Player Event for it would be more efficient than a retardedly large amount of specific unit events.

And with regards to how you did it, what if an enemy is running away and your homing attack is chasing, then while its chasing you cast a damaging spell on that unit?
06-15-2006, 04:00 AM#13
Pheonix-IV
I'm not looking for a debate about the possibilities in the system, i'm asking what i need to modify in the bit of code pipe gave me to store the damaging unit and the damaged unit in variables and how to call other triggers when that occurs. Let me worry about how i'll detect if its an attack or not, that i can handle.
06-15-2006, 04:41 AM#14
harshateja
Collapse JASS:
function AnyUnitTakesDamage takes nothing returns nothing
    // your actions here
    // Sample Damage display:
    // call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction
Add all the stuff you want there. Course, it will have to be in jass but since you plan to learn, what better way than experiment.
06-15-2006, 07:31 AM#15
Pheonix-IV
Wuh? If i can just do that and call other triggers in there, why did pipe post so much O_o

Now i'm really confused.