Alert23 215 Posted June 3, 2019 Hey, can someone help me with a code? i'am trying to make the player unkillable and Prevent death but still take damage and in the same time increase his health, because i want to create a custom deathscene where if the damage of the player reaches 0.8 or 0.9 he will fall in unconsciousness and then my code follows. i tried like this: player addEventHandler [ "handleDamage", { 0.9;}]; this works, but i cant add a code to increase the health in the same time, tried like this: player addEventHandler [ "handleDamage", { 0.9; _unit = _this select 0; _dmg = _this select 2; _oldDmg = damage _unit; _dmg = _oldDmg + (_dmg / 50); _dmg; } ]; this increases the health but now the player isent unkillable and my code dosent fire because player dies. Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 if I understood ur situation then this could work: player addEventHandler ["handleDamage", { _dmg = _this select 2; (_dmg * 0.9) }]; 1 1 Share this post Link to post Share on other sites
Alert23 215 Posted June 3, 2019 5 minutes ago, sarogahtyp said: if I understood ur situation then this could work: player addEventHandler ["handleDamage", { _dmg = _this select 2; (_dmg * 0.9) }]; this worked thank you ! Share this post Link to post Share on other sites
Alert23 215 Posted June 3, 2019 50 minutes ago, Alert23 said: this worked thank you ! hmm, sry. somehow it dosent work. player gets still killed if hit by a tankshell. what i try to achive is that nothing can kill the player but player can still take damage. Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 in this case just do a check if damage value is bigger than 0.9 and return 0.9 in that case. can not show it cause i m on mobile now Share this post Link to post Share on other sites
Alert23 215 Posted June 3, 2019 Just now, sarogahtyp said: in this case just do a check if damage value is bigger than 0.9 and return 0.9 in that case. can not show it cause i m on mobile now yes i tried it with two triggers: trigger 1: Condition: damage player >= 0.8 ONAC: some code trigger 2: Condition: damage player >= 0.9 ONAC: player setdammage 0.8 but if player gets hit by a tankshell he will still die. Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 not in a trigger. in the event handler code Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 tested and working for me: d = this addEventHandler ["handleDamage", { _dmg = (_this select 2) * 0.9; if (_dmg > 0.9) then {0.9} else {_dmg}; }]; 1 Share this post Link to post Share on other sites
Alert23 215 Posted June 3, 2019 26 minutes ago, sarogahtyp said: tested and working for me: d = this addEventHandler ["handleDamage", { _dmg = (_this select 2) * 0.9; if (_dmg > 0.9) then {0.9} else {_dmg}; }]; yes indeed this does work thanks so far 👍 but i want to add another HandleDamage EH which increases players Health: increase health: player addEventHandler [ "handleDamage", { _unit = _this select 0; _dam = _this select 2; _oldDmg = damage _unit; _dmg = _oldDmg + (_dmg / 50); _dmg; } ]; now if i add both then the first one will be ignored. Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 try this: d = this addEventHandler ["handleDamage", { _dmg = (_this select 2) * 0.02; if (_dmg > 0.9) then {0.9} else {_dmg}; }]; damage can be 0.0 (full health) upto 1.0 (dead) factor 0.2 is calculated by 1 / 50 = 0.2 this should reduce the taken damage by factor 50 and stops getting damage at 0.9 EDIT: not working, damage gets reduced to much. damage has to get stored in a global variable... Share this post Link to post Share on other sites
engima 327 Posted June 3, 2019 Note that this eventhandler is broken for JIP. So use in SP only (unless preventing JIP). Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 SARO_global_damage = 0; d = this addEventHandler ["handleDamage", { _dmg = _this select 2; SARO_global_damage = SARO_global_damage + ( _dmg - SARO_global_damage) * 0.02; if (SARO_global_damage > 0.9) then {0.9} else {SARO_global_damage}; }]; this should work 1 1 Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 3, 2019 4 minutes ago, engima said: Note that this eventhandler is broken for JIP. So use in SP only (unless precenting JIP). any reference for this? Share this post Link to post Share on other sites
engima 327 Posted June 3, 2019 21 minutes ago, sarogahtyp said: any reference for this? I ran into problems myself a couple of weeks ago when I tried to create a similar script. When I googled I found this, which was somewhat close. 2 Share this post Link to post Share on other sites
engima 327 Posted June 3, 2019 What I found more precicely was that it seems to work when player is local to - and when EH is executed on - the server. But on client (local unit and EH fires on client), when JIPing and EH returning 0.99, the EH fires, but the damage dealt to the unit is not the value being returned from the EH. Thus, the unit often dies. 1 Share this post Link to post Share on other sites
Alert23 215 Posted June 3, 2019 39 minutes ago, sarogahtyp said: SARO_global_damage = 0; d = this addEventHandler ["handleDamage", { _dmg = _this select 2; SARO_global_damage = SARO_global_damage + ( _dmg - SARO_global_damage) * 0.02; if (SARO_global_damage > 0.9) then {0.9} else {SARO_global_damage}; }]; this should work yes this does work thank you Saro. 43 minutes ago, engima said: Note that this eventhandler is broken for JIP. So use in SP only (unless preventing JIP). yes this is for SP Share this post Link to post Share on other sites
killzone_kid 1326 Posted June 3, 2019 1 hour ago, engima said: Note that this eventhandler is broken for JIP How are you supposed to use it for JIP? Share this post Link to post Share on other sites
engima 327 Posted June 3, 2019 3 hours ago, killzone_kid said: How are you supposed to use it for JIP? What do you mean? Why would there be a difference? I wanted to control the damage dealt to a player, no matter if he is a JIP or not. Share this post Link to post Share on other sites
killzone_kid 1326 Posted June 4, 2019 7 hours ago, engima said: What do you mean? Why would there be a difference? I wanted to control the damage dealt to a player, no matter if he is a JIP or not. You claim it is broken specifically for JIP, so I’m asking how do you test it, how does one use this EH for JIP that is different from other uses? Share this post Link to post Share on other sites
engima 327 Posted June 6, 2019 Two Steam accounts. One assigned a slot from start, and the other enters the server later. (A dedicated server). The EH is added in the same way, from init.sqf: player addEventHandler ["HandleDamage", ... ]; I tried to prevent players from dying, and always enter inconsiousness. But soon I noticed that some died instantly, and after some research i found this issue. (I assume this should work, i.e. the eventhandler should be local to the player. But anyway I tried some more, like adding the EH on server, which did not work either.) Share this post Link to post Share on other sites
killzone_kid 1326 Posted June 6, 2019 Well, only the last EH can override the damage, if you added your EH too soon, then EH added after yours will override it. And BI also adds own HandleDamage EH, so it must have been added later than yours 1 Share this post Link to post Share on other sites
engima 327 Posted June 11, 2019 On 6/6/2019 at 7:58 PM, killzone_kid said: Well, only the last EH can override the damage, if you added your EH too soon, then EH added after yours will override it. And BI also adds own HandleDamage EH, so it must have been added later than yours Ok, tanks, that's interesting. Then I will try again. How do I know when BI adds own HandleDamage EH (for JIPs)? waitUntil { ... }; ? Share this post Link to post Share on other sites
killzone_kid 1326 Posted June 11, 2019 when you add EH and returned index is 1 then you are adding it after the one BI added, if index is 0 you are the first one. Dunno if you can waitUntil for something, but you can give a good sleep to your script to make sure 1 Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 11, 2019 6 hours ago, engima said: Ok, tanks, that's interesting. Then I will try again. How do I know when BI adds own HandleDamage EH (for JIPs)? waitUntil { ... }; ? you could try to add the eh by a post init function or check for that bis init variable to be true. i forgot its name but it should be mentioned on wikis init order page 2 Share this post Link to post Share on other sites