HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Takes Damage Event Restore Hp's = Damage Taken Problem!

04-20-2007, 05:57 AM#1
Brash
I made a trig that activates on the event of a unit taking damage.. then i tell it to take that damage amount and give the unit that much in life back.. and this works fine except one thing.. (the idea of the trigger is to make the unit seem invulnerable yet absorb damage)

When the trigger detects the event of a unit taking damage and runs through all the functions it is before the game ever has deducted the hit points to match that damage which causes a problem for when the unit is full in health.


it happens in this order:
1. full hit point unit is targetted
2. My trigger runs and looks at damage being done.. then gives that much back...
3. game then updates the units hitpoints and sets it to whatever it would be as if my trigger never executed.


the only times my trigger works is if the unit is already missing some health.. then it gives the health back.. then the game updates it's health by deducting the health again.. coming out even.

like so:
lets say unit is 200 of 300 health currently
then it takes damage of 50.
trigger goes off and gives 50.. making it's health 250 of 300
then the game updates itself and deducts 50.. making it back at 200 of 300

that is what i want except when the unit is full, you can't add health and then take it away.. you can only take it away so it unbalances.

it would work perfectly if the game updated the units health first.. just as my trigger detects the damage.

any idea of a way to get around this?
04-20-2007, 06:54 AM#2
Chocobo
Damage with Event for Damage = Damage is done after the event

The possible way is ExecuteFunc or a Timer of 0.00 that handles the damage, the target, and the source. (handle vars or structs)
04-20-2007, 07:03 AM#3
Funness
Why not.. Any unit is attacked, set attacked unit's hp to 100%.
04-20-2007, 07:38 AM#4
Brash
Quote:
Originally Posted by Chocobo
Damage with Event for Damage = Damage is done after the event

The possible way is ExecuteFunc or a Timer of 0.00 that handles the damage, the target, and the source. (handle vars or structs)



what exactly is ExecuteFunc? never used that before

and does a timer of 0 actually triger?

btw, would it be solid concidering this map has a LOT of units that may be damaging that unit and needs to have every little bit of damage restored perfectly?
04-20-2007, 08:35 AM#5
Zwan
hm, well its hard to guesstimate without seeing the trigger, but I dont see that adding life to a full unit is a problem.

You can use arithmetic to do a max life + 50 action which will add to its max life.

Trigger:
Life
Events
Conditions
Collapse Actions
-------- // Max Life// --------
Unit - Set life of (Triggering unit) to ((Max life of (Triggering unit)) + 50.00)
-------- // Current Life // --------
Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 50.00)
-------- // % Life // --------
Unit - Set life of (Triggering unit) to ((Percentage life of (Triggering unit)) + 50.00)


If you post the trigger someone might be able to offer a different approach. I think a real variable tracking the damage taken would be easiest for starters. But calling an event every time a unit is damaged just seems like overkill.

You can mimic an invuln with a periodic trigger.

Trigger:
Mimic Time Array
Collapse Events
Unit - A unit Learns a skill
Collapse Conditions
(Learned Hero Skill) Equal to Your Skill
Collapse Actions
-------- //this sets the length of time that the caster will be invuln, match the numbers to the duration of the spell for each level of the spell// --------
Set Mimic_Time[1] = 20.00
Set Mimic_Time[2] = 25.00
Set Mimic_Time[3] = 30.00

Trigger:
Mimic Set Up
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Your Skill
Collapse Actions
Set Inlvuln_Caster = (Casting unit)
Set Life = (Life of Inlvuln_Catser)
Countdown Timer - Start Mimic_Timer as a One-shot timer that will expire in Mimic_Time[(Level of Your Skill for (Invuln_Caster))] seconds
Trigger - Turn on Mimic Invuln <gen>


Trigger:
Mimic Invuln
Collapse Events
Time - Every 0.50 seconds of game time
Conditions
Collapse Actions
Unit - Set life of Inlvuln_Caster to Life

Trigger:
Mimic Expire
Collapse Events
Time - Mimic_Timer expires
Conditions
Collapse Actions
Trigger - Turn off Mimic Invuln <gen>


But like I said, without knowing all the info of the spell its hard to guess. These triggers asume you are absorbing all damage and dont take into account specifics of spells and damage types.
04-20-2007, 11:54 AM#6
Chocobo
http://www.thehelper.net/forums/showthread.php?t=55478
04-20-2007, 11:59 AM#7
tamisrah
Or if you dont want to do it yourself you could use shadow1500's shield system :http://www.wc3campaigns.net/showthread.php?t=80544
04-20-2007, 12:26 PM#8
Toink
Stop posting crazy shit if you guys don't understand him.

You need the 'Event - Unit Takes Damage' then for the actions use 'Set life of <your unit> to (life of <your unit>+ Damage Taken)'
04-20-2007, 12:32 PM#9
Rising_Dusk
Quote:
You need the 'Event - Unit Takes Damage' then for the actions use 'Set life of <your unit> to (life of <your unit>+ Damage Taken)'

Stop posting simple shit when your method doesn't properly adjust for two key types of damage protection
  • What if the damage taken is greater than max life?
  • What if the damaged unit is near max life and simply adding to it won't counterbalance damage?
04-20-2007, 12:32 PM#10
akolyt0r
this doesnt work if the unit has FULL HP

READ FIRST

EDIT:yeah dusk was faster :D

The main reason why it's not that easy (it is ...but you will need gamecache or attacheable vars or perhaps something of the new vJass -.- or some globals), is that the damage is registered BEFORE it is inflicted ...
04-20-2007, 01:09 PM#11
Brash
Quote:
Originally Posted by Rising_Dusk
Stop posting simple shit when your method doesn't properly adjust for two key types of damage protection
  • What if the damage taken is greater than max life?
  • What if the damaged unit is near max life and simply adding to it won't counterbalance damage?

Yes, that is exactly what i'm trying to say. and that is exactly my problem that i'm trying to work around.


Quote:
Originally Posted by akolyt0r
The main reason why it's not that easy (it is ...but you will need gamecache or attacheable vars or perhaps something of the new vJass -.- or some globals), is that the damage is registered BEFORE it is inflicted ...

Yep, that's what i've noticed. the health is updated afterwards so it screws things up.

i've made a lot of trigs in my life but never have bothered with gamecache before.. how would something like this be tapped?

attachable vars? isn't that any variable?

i know nothing of jass or vjass. my map is 95% gui.. with a few one-line custom scripts thrown in here and there.

----------------

Here is one of the codes i've been trying to fix that are based on this:

Trigger:
Limiter
Collapse Events
(Unit - (Unitname) Takes damage)
Conditions
Collapse Actions
Set Var_AttackedU = (Attacked unit)
Set Var_DamageTaken = (Damage taken)
Unit - Set life of Var_AttackedU to ((Life of Var_AttackedU) + Var_DamageTaken)

That's all i'm working with for now
04-20-2007, 01:40 PM#12
akolyt0r
i think its impossible to do it in GUI ...
04-20-2007, 01:47 PM#13
Vexorian
It is just lame to do it in GUI not impossible.

But really this is what I do (and btw ExecuteFunc is simply out of the question)

- Attach unit and current life of unit to timer.
- Check "Would damage kill the unit?" If that's true then add a life bonus to the unit, something like 1000.
- Start timer, expiration of 0.
- When timer expires, set the attached unit's life to the attached life value, remove life bonus if necessary.

...
I once made a cool time stop spell in which the units won't die until the time stop wears out of the area. hehe.
04-20-2007, 01:47 PM#14
Zwan
If you want to track damage and explicitly absorb damage then check out Chocobo's link. Apparently there is a delay on the damage events, so setting health takes place before damage is resolved, requiring the use of a timer.
04-20-2007, 01:49 PM#15
Toink
Ok, I've reread the first post and..

First, my method, which you are using, is fine. But we will need to fix the possible bugs that will happen with Dusk's comments.

Steps:

1.] Make the trigger with the event, store the damaged unit and damage taken.
2.] Arithmethic. First, store the current hp of the unit, add the damage taken and current hp, then set the unit's life to current hp + damage taken. Check if the sum of both is higher than it's max hp, if it is then subtract the max hp from the current hp and store that into a real variable. I will call this "Variable A"
EDIT: Forgot to mention, you need to check if the damage taken will kill the unit.
3.] Create a timer and attach "Variable A" then start it using [jass]function TimerStart(<yourtimer>, <expiration time>, <repeating? true/false>, <code/function name>)
4.] When the timer expires, I will call the function it calls "Function A". Now when the timer expires it calls Function A, and in Function A, with the variable attached to the timer, which is Variable A Do a 'Unit - Set Life of <your unit> to (Life of <your unit> - Variable A).

Example of what will happen with this method:

My unit has 100 hp, and he currently has 75 hp. He takes 50 damage, with my method it will add 50 damage, which will set the unit's life to 100 instead of 125. The damage taken and the current hp is bigger than the max hp, so I subtract 100 from 75, the difference is 25. Now when you add 25 and 75 you get 100, which is what you got from adding 50 to it's hp, but the problem if you don't use my method is if you will take it away, you will take away 50 hp, which is more than what you got healed for. But with my method, it will take away 25 hp because we subtracted. It's easy logic.

EDIT:
Quote:
Originally Posted by Sexy Vex
I once made a cool time stop spell in which the units won't die until the time stop wears out of the area. hehe.

Post it here some time :D