AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get Random Player (https://forums.alliedmods.net/showthread.php?t=156346)

Apollyon 05-04-2011 20:10

Get Random Player
 
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);
    }



fysiks 05-04-2011 22:25

Re: Get Random Player
 
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.

Apollyon 05-04-2011 22:49

Re: Get Random Player
 
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. :shock:

fysiks 05-04-2011 23:17

Re: Get Random Player
 
Quote:

Originally Posted by Apollyon (Post 1463443)
Using flag "c" (skip bots) in get_players should only give me human players right? Or am I misunderstanding that. :shock:

Oh, that kind of human lol. I thought you were talking about Zombie Plague type human :). You are right.


All times are GMT -4. The time now is 04:27.

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