| 04-20-2007, 05:57 AM | #1 |
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 |
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 |
Why not.. Any unit is attacked, set attacked unit's hp to 100%. |
| 04-20-2007, 07:38 AM | #4 | |
Quote:
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, 11:54 AM | #6 |
| 04-20-2007, 11:59 AM | #7 |
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 |
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 | |
Quote:
Stop posting simple shit when your method doesn't properly adjust for two key types of damage protection
|
| 04-20-2007, 12:32 PM | #10 |
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 | ||
Quote:
Yes, that is exactly what i'm trying to say. and that is exactly my problem that i'm trying to work around. Quote:
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: That's all i'm working with for now |
| 04-20-2007, 01:40 PM | #12 |
i think its impossible to do it in GUI ... |
| 04-20-2007, 01:47 PM | #13 |
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 |
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 | |
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:
Post it here some time :D |
