Raised This Month: $ Target: $400
 0% 

Get Random Player


Post New Thread Reply   
 
Thread Tools Display Modes
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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2011 , 22:25   Re: Get Random Player
Reply With Quote #2

It looks like all that you are doing there is selecting a random player in the server. You don't check if they are human or otherwise.
__________________
fysiks is offline
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-04-2011 , 22:49   Re: Get Random Player
Reply With Quote #3

I just found what was causing my problem. I thought it was a problem in NewRound but was wrong. I was settings the value of the VIP player variable back to 0 on player death. Then on the next round there was no VIP chosen. I removed that one thing and everything is perfect.

Using flag "c" (skip bots) in get_players should only give me human players right? Or am I misunderstanding that.
__________________
Apollyon is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2011 , 23:17   Re: Get Random Player
Reply With Quote #4

Quote:
Originally Posted by Apollyon View Post
Using flag "c" (skip bots) in get_players should only give me human players right? Or am I misunderstanding that.
Oh, that kind of human lol. I thought you were talking about Zombie Plague type human . You are right.
__________________
fysiks is offline
Reply



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 03:24.


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