Raised This Month: $ Target: $400
 0% 

Get Random Player


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-04-2011 , 20:10   Get Random Player
Reply With Quote #1

Is there a better way to do this? Sometimes it doesn't select a player.

What I'm trying to do is select a random human player at the start of each round to be the VIP. The way the server is set up, humans are on 1 team with bots on the other. Would this code cause any problems if there was only 1 human on the server?

PHP Code:
new g_iVIPid 0;
new 
CsTeams:g_VIPteam;


public 
plugin_init()
{
    
register_event("HLTV""NewRound""a""1=0""2=0");
}

public 
NewRound()
{
    new 
vPlayers[32], vPlayerNumvName[32];
    
get_players(vPlayersvPlayerNum"ac");
    
g_BombPlanted false;
    
    if(
vPlayerNum)
    {
        
g_iVIPid vPlayers[(vPlayerNum 1) ? random(vPlayerNum) : 0]; //Set random human player to VIP
        
        
g_VIPteam cs_get_user_team(g_iVIPid); //Get team VIP is on
        
        
get_user_name(g_iVIPidvNamecharsmax(vName));
        
ColorChat(0,RED"[%s] ^4%s ^1is VIP this round. Stick together team!"PrefixNamevName);
    }

__________________
Apollyon 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 04:27.


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