Raised This Month: $170 Target: $400

Solved Random Player

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Join Date: Nov 2016
Old 06-10-2018 , 20:04   Random Player
Reply With Quote #1

hi, i want to get a random player who doesn't have freeday.

freeday native : is_user_freeday(id)

PHP Code:
players[32], pnum;
    if( !
pnum ) return -1;

Last edited by Suntox; 06-11-2018 at 14:24.
Suntox is offline
Veteran Member
Join Date: Jun 2016
Location: Catlands
Old 06-11-2018 , 02:46   Re: Random Player
Reply With Quote #2

RandomPlayer() {     static id;     new players[32], pnum;     do     {         get_players(players, pnum);             if( !pnum ) return -1;         id = players[random(pnum)];     }       while (is_user_freeday(id));     return id; }
Somelike half working this?

I had to repeat the loop if the random player had freeday so it proceeds again and choses a new one.
Have A Relaxing Day | Wiki

Last edited by Relaxing; 06-11-2018 at 02:48.
Relaxing is offline
Join Date: Nov 2016
Old 06-11-2018 , 14:23   Re: Random Player
Reply With Quote #3

Thanks, it's works.
Suntox is offline
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2018 , 20:11   Re: Random Player
Reply With Quote #4

Beware that Relaxing's method is non-deterministic and can freeze your server for an amount of time. It will also be an infinite loop if all players have free day (which will look like your server freezes permanently).

Here is a version that has a maximum execution time (32 iterations) and therefore will never cause an infinite loop. If no player no player is found, it will return zero.

PHP Code:
public random_nonfreeday_player()
iPlayers[32], iPlayersNumindex
iRandomIndex random(iPlayersNum)
    for( new 
0iPlayersNumi++ )
index = (iRandomIndex i) % iPlayersNum
if( !is_user_freeday(iPlayers[index]) )


Last edited by fysiks; 06-12-2018 at 20:14.
fysiks is offline

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 15:32.

Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode