IndeedPete 1038 Posted December 12, 2013 Hi there, maybe i scripted total crap here but i'm a little confused right now by the handelDamage event handler. Here's my code: {_x addEventHandler [ "HandleDamage", { _unit = _this select 0; _damage = _this select 2; _damageRed = _damage * 0.05; if (IP_TESTMODE) then {hint format ["Target: %1\nDamage: %2\nReduced Damage: %3\nHealth: %4", _unit, _damage, _damageRed, (1 - (damage _unit))];}; _damageRed } ]; } forEach [saunders, kowalsky]; This is supposed to make those two guys have 20-times more "life" than they actually have. But some glitch makes them invincible, i.e. their health refills after some hits. Feel free to try it yourself on some units; hopefully i made a mistake and it is no problem with the handler itself. I'm running latest DevBranch. Share this post Link to post Share on other sites
IndeedPete 1038 Posted December 13, 2013 I'm sorry to bump this one but maybe someone has another workaround if there's a problem with the handleDamage EH? To clarify: in my mission, the Player has to flee from enemy cars & helos by a sportscar. It is not armored and can therefor be destroyed by a few shots. So I made the car invincible but the Player can still be killed by bullets through the windows etc. It would be too easy to just make the Player invicible and it's way too hard right now, because there's not a hint of armor to protect the driver from bullets. So I figured I could just alter the incoming damage and by this giving the Player "more health" to make the escape playable but still challenging. Any help is gladly appreciated! :) Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 Does the hint display? If it does you know for sure the event handler is triggering. You can try _x removeAllEventHandlers "HandleDamage"; before adding the event handler to make sure yours is the only one attached to the player. The issue with the HandleDamage event handler is that it is triggered multiple times for each time you take damage. If you look at the event handlers page you can see an example of this that I copied below: "T=11692.9 : [b Alpha 2-2:1,"head",0.0179969,<NULL-object>,"B_65x39_Caseless"]""T=11692.9 : [b Alpha 2-2:1,"",0.850484,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11692.9 : [b Alpha 2-2:1,"",0.850484,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11692.9 : [b Alpha 2-2:1,"head",0.0179969,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11692.9 : [b Alpha 2-2:1,"body",0.0939217,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11692.9 : [b Alpha 2-2:1,"hands",0.109993,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11694.8 : [b Alpha 2-2:1,"head",0.899007,<NULL-object>,"B_65x39_Caseless"]" "T=11694.8 : [b Alpha 2-2:1,"",0.346781,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11694.8 : [b Alpha 2-2:1,"",1.19727,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" "T=11694.8 : [b Alpha 2-2:1,"head",0.899007,B Alpha 1-1:1 (KK),"B_65x39_Caseless"]" In the preceding example, the unit was shot two times. The event handler triggers for each body part hit. It also seems to trigger twice for overall damage (selection = "") and head damage (selection = "head"). The second time the overall damage triggers it seems to be a sum of total damage incurred thus far. When you return a value from the event handler, that is the damage the unit will take. So if you get shot in the head and take 1 damage to the head, and 1 damage to the body, the event handler will trigger 4 times. Twice for the head damage, and twice for the overall damage. The total damage you will take will be 4 * (1 * 0.05) = 0.2 damage. This does reduce the damage, but not by quite as much as you intend. If more body parts are affected, by and explosion for example, the event handler will trigger more times and your will take even more damage. You can check the selection type, and only allow damage when the selection type is "". This can give you a more accurate result, but it still wont be perfect. Share this post Link to post Share on other sites
IndeedPete 1038 Posted December 13, 2013 Thanks for your reply. Well, the hint works. Funny thing is only that the health "recharges". These four screenshots were taken a row. 1st Shot: 2nd Shot: 3rd Shot: 4th Shot: Take a look at the unit's health. It's decreasing at first and then increasing later. :confused: I've tried just to pass the plain damage as well without reducing it; same outcome. Is there another way to deal with damage and catch it before it actually hits? Or maybe i'll play around with the selections later... Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 Are you modifying a mission, or are there not many other scripts running? Seems odd that the unit would gain health unless there is another script or event handler that is interfering. What ever you return from the event handler should be the damage the unit will take. If you return 0, the unit should not take any damage, making him invulnerable. This can allow you to do your own damage processing, wither have a variable keep track of the damage taken and kill the unit once it gets to a certain point, or use setDamage to set units damage. For example, you can keep track of the total damage taken so far in a variable, and use setDamage to set the unit's damage to that variable. Then return 0 so the unit does not take additional damage. This can allow you to control when the unit takes damage. This in conjunction with checking the selections could give you additional control. There is also a function setHit that will allow you to set the damage to a particular part. When uned on a body you can set damage to the legs, and once it gets to a certain threshold they can no longer run. You can also use this in the event handler to damage parts of the body without adding to the overall damage to the unit. Share this post Link to post Share on other sites
jw custom 56 Posted December 13, 2013 HandleDamage seems screwed up both in stable and dev! Share this post Link to post Share on other sites
f2k sel 164 Posted December 13, 2013 (edited) 12 shots in the back to kill the unit, this seems to work for me. this addEventHandler ["HandleDamage",{damage (_this select 0)+((_this select 2)/8)}]; it looks like your resetting the damage every shot _damageRed = _damage * 0.05; Edited December 13, 2013 by F2k Sel Share this post Link to post Share on other sites
jw custom 56 Posted December 13, 2013 12 shots in the back to kill the unit, this seems to work for me. this addEventHandler ["HandleDamage",{damage (_this select 0)+((_this select 2)/8)}]; it looks like your resetting the damage every shot _damageRed = _damage * 0.05; Ahh yeah you need to add "old damage" to result :o Share this post Link to post Share on other sites
albertfish 11 Posted December 13, 2013 12 shots in the back to kill the unit, this seems to work for me. this addEventHandler ["HandleDamage",{damage (_this select 0)+((_this select 2)/8)}]; it looks like your resetting the damage every shot _damageRed = _damage * 0.05; Good call. I thought it summed it up, but after checking I see that it does not. Share this post Link to post Share on other sites
jw custom 56 Posted December 13, 2013 I'm getting different results based on visuals only. this addEventHandler [ "handleDamage", { _unit = _this select 0; _dmg = _this select 2; _oldDmg = damage _unit; _dmg = _oldDmg + (_dmg / 10); _dmg } ]; Share this post Link to post Share on other sites
conroy 13 Posted December 13, 2013 handleDamage will always give you the new total damage value for that selection. You need to do some calculations with the current damage values of the unit, before letting the eventhandler return the new damage player addeventhandler ["HandleDamage",{ _unit = _this select 0; _selection = _this select 1; _passedDamage = _this select 2; _source = _this select 3; _projectile = _this select 4; _oldDamage = 0; switch(_selection)do{ case("head"):{_oldDamage = _unit getHitPointDamage "HitHead";}; case("body"):{_oldDamage = _unit getHitPointDamage "HitBody";}; case("hands"):{_oldDamage = _unit getHitPointDamage "HitHands";}; case("legs"):{_oldDamage = _unit getHitPointDamage "HitLegs";}; case(""):{_oldDamage = damage _unit;}; default{}; }; _return = _oldDamage + ((_passedDamage - _oldDamage) / 20); _return }]; Give this a try and see if it works for you. 1 2 Share this post Link to post Share on other sites
IndeedPete 1038 Posted December 14, 2013 Thanks man! That seems to work like a charm. I knew I had something wrong. :) Share this post Link to post Share on other sites