Gameplay::getRandomIntInRange: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
No edit summary
 
Line 1: Line 1:
Another extremely useful native.<br><br>You can use it simply like:<br>if (GAMEPLAY::GET_RANDOM_INT_IN_RANGE(0, 2))<br><br>and the if-statement will count it as false only if the random int is 0. That means there is a one in three chance of it being false. Put a '!' in front and it means there is a one in three chance of it being true.
{{ClientsideJsFunction}}
{{JSContainer|
Gets a random number from the range passed in.
 
===Required Values===
*'''min:''' {{RageType|number}}
*'''max:''' {{RageType|number}}
 
===Return value===
*''' {{RageType|number}} '''
 
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">mp.game.gameplay.getRandomIntInRange(startRange, endRange);</syntaxhighlight>
<syntaxhighlight lang="javascript">
=== Required Arguments ===
mp.game.gameplay.getRandomIntInRange(min, max);
*'''startRange:''' int
</syntaxhighlight>
*'''endRange:''' int
 
===Return value===
*'''int'''
==Example==
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// todo
const randomNumber = mp.game.gameplay.getRandomIntInRange(0, 9999);
mp.console.logInfo(`Random number is ${randomNumber}`);
</syntaxhighlight>
</syntaxhighlight>
}}
==See also==
==See also==
{{Gameplay_s_function_c}}
{{Gameplay_definition_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Latest revision as of 10:06, 29 April 2024

Client-Side
Function

 JavaScript



JavaScript Syntax

Gets a random number from the range passed in.

Required Values

  • min: number
  • max: number

Return value

  • number

Syntax

mp.game.gameplay.getRandomIntInRange(min, max);

Example

const randomNumber = mp.game.gameplay.getRandomIntInRange(0, 9999);
mp.console.logInfo(`Random number is ${randomNumber}`);


See also