I must admit, this has been asked and requested many times and I was too lazy to publish something about it… But, today, I’m in holiday and have some free time to do it… The concept is pretty simple, it increases the fuel uptake taking into account the speed of the player vehicle. This script is […]
code
Return a random value between min and max. Note that if #0 > #1, the function will swap vars. If the random result is lower than min, it returns the min. Same for the max value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/* Author: Tom_48_97 Description: Return a random value between min and max. Note that if #0 > #1, the function will swap vars. If the random result is lower than min, it returns the min. Same for the max value. Parameter(s): #0 NUMBER - The minimal value #1 NUMBER - The maximum value #2 BASE - Random result type: "round", "floor", "ceil", "float". Any other value will return a float Example of use: this setFuel ([0.2, 0.5] call tm4_fnc_random); this setPosATL [(getPosATL player select 0) + ([5, 10, "floor"] call bis_fnc_random), (getPosATL player select 1) + ([3, 7, "floor"] call bis_fnc_random), 0.1]; Returns: NUMBER - Integer or float */ private["_this", "_min", "_max", "_base", "_return"]; _min = [_this, 0, 0, [0]] call bis_fnc_param; _max = [_this, 1, 1, [0]] call bis_fnc_param; _base = toLower([_this, 2, "float", ["round", "floor", "ceil", "float"]] call bis_fnc_param); if !(typeName _min == typeName 0) exitWith { ["#0: Must be a NUMBER"] call bis_fnc_error; }; if !(typeName _max == typeName 0) exitWith { ["#1: Must be a NUMBER"] call bis_fnc_error; }; if (_min > _max) then { private ["_tmp1", "_tmp2"]; _tmp1 = _min; _tmp2 = _max; _max = _tmp1; _min = _tmp2; }; _return = random _max; if (_base == 'round') Then { _return = round(_return); }; if (_base == 'floor') Then { _return = floor(_return); }; if (_base == 'ceil' ) Then { _return = ceil(_return); }; if (_return < _min) Then { _return = _min + (random (_max - _min)); }; _return |