View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-16-2024 , 20:36   Re: Choosing a random player
Reply With Quote #12

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
random() will select a random value from 0 to the specified max value.

random(7) -> {0,1,2,3,4,5,6,7}
No, random(7) = {0,1,2,3,4,5,6}

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
which sometimes, will lead to this:

iRandom = iPlayers [ 0 ]

Valid client entity indexes are from 1 to 32.
This is fine as you are not using the random number as the player index, you are using it as an index to the iPlayers array, which get_players() fills with all valid player id's.. The iPlayers[ 0 ] slot will contain a valid player id if iNum is > 0.
Quote:
Originally Posted by WATCH_D0GS UNITED View Post
As an additional note, there are two more issues which are related to the use of get_players() native which we will not point out here,
but we are pretty sure that if someone knows how entity index slots works in the game this person will understand why.
There is no issues with the code I posted above to get a random player.

Please don't try to help others if you are not confident in what you are saying.
__________________

Last edited by Bugsy; 04-16-2024 at 20:37.
Bugsy is offline