HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Any unit takes damage

02-12-2006, 10:48 AM#1
Thunder_Eye
Hi all, I've been trying to add the "Any unit takes damage" to the normal WEU and I think ive succeded. Though my question is.
I want so when a unit is damages it sets it life to what is were before it got hit. How to do that? I cant seem to find the
"Set life of "Damaged unit" to (Life of Damaged unit + Damage Taken)

EDIT: (Im not fully sure the "unit takes damage" event really works, so can someone tell me how to implent it?)
02-12-2006, 11:43 AM#2
Captain Griffen
I think it might be " unit - set property" or something.
02-12-2006, 12:42 PM#3
Thunder_Eye
yeah Ive tested it but I dont know what to put in, only thing I can find is "Damage Source" and that is the attacking unit I think, so what is the damaged unit? "Attacked Unit"?
02-12-2006, 01:01 PM#4
Jacek
Damaged unit is the one which you put into event


Event
Blood Mage 0000 <gen> takes damage
02-12-2006, 01:45 PM#5
Azazel_
Example Solution to Main Question

Collapse JASS:
Event
call TriggerRegisterUnitEvent( gg_trg_YourTrigger, YourUnit, EVENT_UNIT_DAMAGED )

Action
local unit u = GetTriggerUnit()
if (GetUnitState(u,UNIT_STATE_LIFE) > 0) then //check that it's not dead
    call SetUnitLifeBJ( u, ( GetUnitStateSwap(UNIT_STATE_LIFE, u) + GetEventDamage() ) )
endif
set u = null

One questions the purpose of such a trigger. Perhaps it is better to give it Hardened Skin with 1000 damage absorption, as well as Resistant Skin if desired. The latter is a better alternative for general purposes unless there is a specific requirement in your map to achieve intended results.

-----

Unit Event Damage
The event triggers each time a unit receives damage from a unique source, be it triggered damage, spells or combat damage. It is important to note that it fires in response to buffs that cause you to lose HP as well. In Aftermath, I had a buff called Open Wounds that causes the unit to lose 2 hp every second. I use the unit damaged event to record the total number of hits a Marine has taken throughout the course of the game. What happened, the hits taken increased by 1 every second due to Open Wounds. As a corrective measure, I added the condition if (GetEventDamage() > 5) then, since all other sources of damage from the game generally exceed 5.

The advantage of Unit Event Damage over Unit is Attacked is that it fires only when the unit receives actual damage. In combat situations, units may miss and you may not wish for the trigger to fire. It is also more timely, depending on your desired usage.

Implementation for Specific Unit
For World Editor users, there are 2 ways of implementing it :
- preplacing the unit at the start of the game, using GUI to set the event
- Use a custom script line to insert the event for the unit. You will want to define your unit either with a local or global variable prior to this.

Collapse JASS:
call TriggerRegisterUnitEvent( gg_trg_YourTrigger, YourUnit, EVENT_UNIT_DAMAGED )
02-12-2006, 02:32 PM#6
Thunder_Eye
Well I need the "Any unit takes damage"
and not a special one.

I think the event is the problem, Its a copy of the one used in WEU and somehow it doesnt work, I dont know why though.
02-12-2006, 02:48 PM#7
Azazel_
Noted. Any unit takes damage is unique to WEU and I do not use WEU.
02-12-2006, 03:08 PM#8
Jacek
use WEU's Any Unit is Damaged. Convert it to JASS so we can look how it works.
02-12-2006, 03:19 PM#9
Thunder_Eye
It calls an function from the mapscript.
"AnyDamageEvent" is the function.
02-12-2006, 03:21 PM#10
Jacek
But it is WEU function.
02-12-2006, 03:24 PM#11
Thunder_Eye
Yeah and Ive copied it in the map-script.
Ive done this with several other functions but I dont know why this one doesnt work.
02-12-2006, 06:15 PM#12
Anitarf
Try using Vexorian's attack detect engine.
02-12-2006, 06:34 PM#13
Thunder_Eye
Well I rather not have to implent the whole caster system and the attackdetect system, isnt there any simpler way?
02-15-2006, 03:52 PM#14
Mystic Prophet
The Problem with unit takes damage events is that they can only be used for specific units. So this is what I did for my map.

First off, if all your units are created by triggers then your set. If not, you'll have to pick all the preplaced units on the map and replace them with triggers. in that same trigger add to any trigger you want to use it the event "entering unit takes damage" This will make it so the trigger will work on any unit. causes some problems with the object manager and placing droppable items, but those can be done with triggers as well.
02-16-2006, 01:37 PM#15
Thunder_Eye
Yeah I know about that solution to. But from what Ive heard there is a limit on the events and also it lags alot with to many events.
This wont work because I will probably create and kill many units and that woul be many events.

Any other solution?