sarogahtyp 1108 Posted June 9, 2016 I d like to know if my way to copy the partial damage from one object to another works and if it can be optimized. fnc_get_hp_damage = { params ["_object"]; _hp_all_info = getAllHitPointsDamage _object; [_hp_all_info select 1, _hp_all_info select 2] }; fnc_set_hp_damage = { params ["_object", "_hp_all_info"]; private _hp_selection_names = _hp_all_info select 0; private _hp_damage_values = _hp_all_info select 1; { _object setHitPointDamage [_x, (_hp_damage_values select _forEachIndex)]; } forEach _hp_selection_names; }; params [["_vec_or_unit1", objNull, [objNull]], ["_vec_or_unit2", objNull, [objNull]]]; if ((isNull _vec_or_unit1) or (isNull _vec_or_unit2)) exitWith {true}; _hp_info = _vec_or_unit1 call fnc_get_hp_damage; [_vec_or_unit2, _hp_info] call fnc_set_hp_damage; Share this post Link to post Share on other sites
R3vo 2654 Posted June 9, 2016 I d like to know if my way to copy the partial damage from one object to another works and if it can be optimized. fnc_get_hp_damage = { params ["_object"]; if (isNull _object) exitWith {true};//Isn't that obsolete since you check that before the function is called? _hp_all_info = getAllHitPointsDamage _object; [_hp_all_info select 1, _hp_all_info select 2] }; fnc_set_hp_damage = { params ["_object", "_hp_all_info"]; private _hp_selection_names = _hp_all_info select 0; private _hp_damage_values = _hp_all_info select 1; { _object setHitPointDamage [_x, (_hp_damage_values select _forEachIndex)]; } forEach _hp_selection_names; }; params [["_vec_or_unit1", objNull, [objNull]], ["_vec_or_unit2", objNull, [objNull]]]; if ((isNull _vec_or_unit1) or (isNull _vec_or_unit2)) exitWith {true};//Should return false?!? Because function failed _hp_info = _vec_or_unit1 call fnc_get_hp_damage; [_vec_or_unit2, _hp_info] call fnc_set_hp_damage; Looks good to me. I added some notes/question in the script 1 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 9, 2016 Looks good to me. I added some notes/question in the scriptupdated first post without the obsolete exitWith no it should not return false. somewhere (I forgot where, I think it was the wiki) I read that all functions should return true in any case except they return an otherwise needed value. Since I read that I always return true. dont ask me why but i think it doesnt matter... Share this post Link to post Share on other sites
R3vo 2654 Posted June 9, 2016 no it should not return false. somewhere (I forgot where, I think it was the wiki) I read that all functions should return true in any case except they return an otherwise needed value. Since I read that I always return true. dont ask me why but i think it doesnt matter... I don't blame you, I usually also only return true, to make sure the function was executed properly. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 9, 2016 okay, i found what I read:Functions Library (Arma 3) i dont feel blamed, I appreciate every advise :-) Share this post Link to post Share on other sites
R3vo 2654 Posted June 9, 2016 params [["_unit", objNull, [objNull]], ["_target", [0, 0, 0], [[], objNull], [2, 3]]];if (!alive _unit) exitwith {["Unit %1 must be alive.", _unit] call BIS_fnc_error; false}; _unit doWatch _target;true 2nd line is what I meant earlier, though admittedly it's not necessary. 1 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 9, 2016 (edited) 2nd line is what I meant earlier, though admittedly it's not necessary. idk but I think u posted that in the wrong topic because thats not my code... what u meant in this topic was this: if (isNull _object) exitWith {true};//Isn't that obsolete since you check that before the function is called? and I deleted that line from first post Edited June 9, 2016 by sarogahtyp Share this post Link to post Share on other sites
R3vo 2654 Posted June 9, 2016 That was copied from the Wiki, my fault for not mentioning the source. I just wanted to point out that returning false in case the function was exited (like in line 2) is done some times. Anyway, if your script works, I'd use it like this. Is that for your script based spawning project? Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 9, 2016 That was copied from the Wiki, my fault for not mentioning the source. I just wanted to point out that returning false in case the function was exited (like in line 2) is done some times. Anyway, if your script works, I'd use it like this. Is that for your script based spawning project? Yes it is. I was at work and I can't Test anything there. Therfore i check my thoughts here sometimes and the code is stored for use at home then. Share this post Link to post Share on other sites
killzone_kid 1331 Posted June 9, 2016 Maybe you are overthinking it.. {_objTarget setHitIndex [_forEachIndex, _x]} forEach (getAllHitPointsDamage _objSource select 2); 2 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 10, 2016 Maybe you are overthinking it.. {_objTarget setHitIndex [_forEachIndex, _x]} forEach (getAllHitPointsDamage _objSource select 2); Thx. I didnt think about setHitIndex. That's good. But I can't use ur one Liner because I didn't tell that I can't get from öne object and set to another at the same time because of Caching the information in between. Share this post Link to post Share on other sites
kylania 568 Posted June 10, 2016 Why not just cache the damage values as well and apply on respawn? Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 10, 2016 Do u mean the damage and setDamage commands? I already use them but I ve another question with them. Does setDamage overwrite setHitIndex or Vice versa? Share this post Link to post Share on other sites
kylania 568 Posted June 10, 2016 No, just save this value as a variable and reapply it with the KK code above when you uncache the units. // Save this with whatever other info you're saving. _previousDamage = getAllHitPointsDamage _oldUnit select 2; // Mystical cachey stuff // Then use the variable later {_newUnit setHitIndex [_forEachIndex, _x]} forEach _previousDamage; 1 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 10, 2016 No, just save this value as a variable and reapply it with the KK code above when you uncache the units. // Save this with whatever other info you're saving. _previousDamage = getAllHitPointsDamage _oldUnit select 2; // Mystical cachey stuff // Then use the variable later {_newUnit setHitIndex [_forEachIndex, _x]} forEach _previousDamage; yeah thats exactly what i want to do after i read kks post. that shiny functions in my first post were just some requisits for this post. but do u know about that overwriting stuff i asked about in my last post? will setHitIndex and setDamage conflict each other? or is setDamage obsolete when using setHitIndex? Share this post Link to post Share on other sites
kylania 568 Posted June 10, 2016 Kamikaze's note for setDamage: Using this possible overrides individual hit damages such as setHitPointDamage ["HitHead", _value]; if you're having issues try setting hitdamage after setdamage Also note Pierre's comments from damage: The returned value depends on the couple target/ammo fired. This value has no correlation with the sum of all hitpoints damage status and the effective status of the object. Firing bullets on cars often lead to weird results. For example: damage returns zero while a Hunter is fired at will with an .50 HMG! Hunter can be almost destroyed with zero damage for this function. If you script, use instead the getHitPointDamage function. 1 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted June 10, 2016 (edited) Kamikaze's note for setDamage: Also note Pierre's comments from damage: thx a lot all of u. I ve no likes left so i ll do that later. topic is solved, implementing hitpoints damage now :-) EDIT: it works like charm :-) Edited June 10, 2016 by sarogahtyp Share this post Link to post Share on other sites