Kydoimos 916 Posted September 18, 2014 Hi all - should be quite a simple one this, though my scripting skills are sadly lacking and not quite up to the task! Basically, I'd like to add a "Hit" eventhandler to an object, but have a random chance of it actually firing and activating the code, each time it's hit. I'm guessing I'd need to use the 'if' command in the .sqf script - but I'm not quite sure how to use the 'random' command. So: if ( // some sort of code needed!) then {nul =[] execVM "myScript.sqf}. Any ideas? Thanks! Share this post Link to post Share on other sites
jshock 513 Posted September 18, 2014 I think you will have to pass into your script via the EH, and then have the script to some sort of randomized variable value, then have just one value that would leave the script at true, and execute the rest of the way: this addEventHandler ["Hit", {nul = [] execVM "myscript.sqf}]; myscript.sqf: _randomnumber = random 5; //if my thoughts are correct you should get a 20% chance of the script firing. if (_randomnumber == 2) then { code........ } else exitWith {}; Share this post Link to post Share on other sites
SilentSpike 84 Posted September 18, 2014 (edited) Remember to use floor JShock, random will return a decimal value (or use < 1 instead of == 2) Alternatively: if ((random 1) < 0.2) then {}; Edited September 18, 2014 by SilentSpike Share this post Link to post Share on other sites
jshock 513 Posted September 18, 2014 Remember to use floor JShock, random will return a decimal value (or use < 1 instead of == 2)Alternatively: if ((random 1) < 0.2) then {}; Thanks Spike, I swear I might be a good scripter if I could just remember all these details....ugh.... Share this post Link to post Share on other sites
Kydoimos 916 Posted September 18, 2014 Lovely guys! Thanks ever so! :cool: I also see how the random command works now, brill! Share this post Link to post Share on other sites