creartan 10 Posted October 31, 2014 i want to put this into unit(unplayable ai) initialization via script how? so i just need to copy the script into each unit init, how? sorry im new to scripting, usually do it inside the editor, please help me. can you guys tell me the step to do it? this allowfleeing courage; this enablefatigue false; this addEventHandler ["HandleDamage", { _object = _this select 0; _damage = _this select 2; if((damage _object) + _damage > 0.9) then {0.9} else {_damage}; }]; Share this post Link to post Share on other sites
jshock 513 Posted October 31, 2014 (edited) Are you applying this to all units or just a single unit? For all units: //put this in the init.sqf { _x allowfleeing 0;//should be a number between 0 and 1, 0 being never flee, 1 being flee, not a word _x enablefatigue false; _x addEventHandler ["HandleDamage", { if((damage (_this select 0)) + (_this select 2) > 0.9) then {0.9} else {_this select 2}; }]; } forEach allunits; Actually what are you trying to do with the EH, because the way you have it, I'm not too sure what's going on, especially in the if statement? Edited October 31, 2014 by JShock Share this post Link to post Share on other sites
creartan 10 Posted October 31, 2014 (edited) hey thanks jshock for the quick response, i have 2 kind of unit the playable and the ai so.. maybe can we create it only for one unit? first can we create a custom init that can be run for each unique unit? i mean like can we do, init1.sqf that i will put it later only to unit 1 and init2.sqf for unit2 init3.sqf for unit3 and so on..? because i have many diffrent unit role. second and if can how to put it down into unit initialization? the if statemen is to make the unit never died but will deal with damage Edited October 31, 2014 by creartan Share this post Link to post Share on other sites
jshock 513 Posted October 31, 2014 Well depending on what is "unique" about each unit you could have a series of if statements with the forEach loop, executing something different depending on the unit, and you don't need to worry about unit initialization, as these commands run whenever you exectute them, no need to put them in the initialization of the unit. //put this in the init.sqf { if (vehicleVarName == "unit1") then { _x allowfleeing 0;//should be a number between 0 and 1, 0 being never flee, 1 being flee, not a word _x enablefatigue false; _x addEventHandler ["HandleDamage", { if((damage (_this select 0)) + (_this select 2) > 0.9) then {0.9} else {_this select 2}; }]; }; if (vehicleVarName == "unit2") then { _x allowfleeing 0;//should be a number between 0 and 1, 0 being never flee, 1 being flee, not a word _x enablefatigue false; _x addEventHandler ["HandleDamage", { if((damage (_this select 0)) + (_this select 2) > 0.9) then {0.9} else {_this select 2}; }]; }; //etc. } forEach allunits; Share this post Link to post Share on other sites
creartan 10 Posted October 31, 2014 owh.. so that mean its applied for global then, right? okay, thank you jshock Share this post Link to post Share on other sites
dreadedentity 278 Posted November 1, 2014 (edited) 1. You should be able to just copy/paste that to the unit init line. Did it not work? What was the error? 2. In this line, I'm not sure it will do what you want it to do: if((damage _object) + _damage > 0.9) then {0.9} else {_damage}; I'll explain, the value for (_this select 2) already returns the resulting amount of damage after the unit has been hit. Returning the base damage of a shot is a different matter altogether and you need an extra line of code or two. If I translated this code into English, as closely and literally as possible, it would say "If the current damage of the object plus the resulting damage of the object after this shot is greater than 0.9 return 0.9, if not, return the resulting damage of the object after this shot." The effect you were most likely looking for is: if (_damage > 0.9) then {damage (_this select 0)} else {_damage}; This will make the unit invulnerable. I think. It's been weeks since I played with the HandleDamage EH. Edited November 1, 2014 by DreadedEntity Share this post Link to post Share on other sites
creartan 10 Posted November 1, 2014 (edited) its not working the if (_damage > 0.9) then {damage (_this select 0)} else {_damage}; yeah its wierd, i got that from around the forum but it did the job, maybe the + thing is to make more time for the calculation if inserted just if (_damage > 0.9) theres no more calculation can be made when the unit is already dead, maybe? i dont know i got that from another guy around the forum though Edited November 1, 2014 by creartan Share this post Link to post Share on other sites
jshock 513 Posted November 1, 2014 (edited) So are you trying to make the unit invulnerable then? And I'm still confused as to why your using the _damage when all you should need is (_this select 2), unless I'm mistaken, but it just seems redundant to assign it a variable that is already defined. Sorry but I'm just kind of lost with this, maybe due to my lack of use of the HandleDamage EH, when you return a value in it does that overwrite the current value of damage on the unit? And if you are going for invulnerable couldn't you just do a check on the damage of the unit and then just do a (_this select 0) setDamage 0? Or just put "_x allowDamage false"? Edited November 1, 2014 by JShock Share this post Link to post Share on other sites
dreadedentity 278 Posted November 1, 2014 So are you trying to make the unit invulnerable then? And I'm still confused as to why your using the _damage when all you should need is (_this select 2), unless I'm mistaken, but it just seems redundant to assign it a variable that is already defined. Sorry but I'm just kind of lost with this, maybe due to my lack of use of the HandleDamage EH, when you return a value in it does that overwrite the current value of damage on the unit? And if you are going for invulnerable couldn't you just do a check on the damage of the unit and then just do a (_this select 0) setDamage 0? Or just put "_x allowDamage false"? Yes, whatever you return from HandleDamage EH is what the game will setDamage for that unit. Share this post Link to post Share on other sites