Raised This Month: $ Target: $400
 0% 

[Solved]Random doesn't work


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 07-10-2010 , 09:58   Re: Random doesn't work
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Your RandomPlayer function is wrong.

1. You do not need to check if players are connected that were obtained with get_players().
2. Your function does not make much sense because you check a players team just to attempt to select a random player to move to a different team. Why bother checking his team at all if you are doing nothing to him?
3. You are incorrectly trying to get a random player with random_num(0,Player). Valid player indexes range from 1-32 so if 0 is returned you will get that "Player out of range (0)" error you posted above. You cannot obtain random players the way you attempted. Players[ random( Num ) ] will work.
4. get_players() retrieves connected player indexes and populates the array in the order they are found. They will not always be in the order of 1,2,3,4 etc, there is a possibility of an unconnected slot so the array be can 2,3,5,6,12,15 etc. With that said, random_num(0,Player) is giving you an unconnected player index since it is assuming it is ok to return any index from 0 to Player.

Try this, untested
PHP Code:
public RandomPlayerIndex 
{
    new 
Players32 ] , Num id;
    
    
get_playersPlayers Num )
        
    for ( new 
Num i++ )
    {
        
id Players]
            
        if( ( 
id != Index ) && ( cs_get_user_teamid ) == CS_TEAM_SPECTATOR ) )
            
cs_set_user_teamid cs_get_user_teamIndex ) )
    }

Ok,thanks but a question before testing,where you get a random player? id = all players
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
 



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 07:14.


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