View Single Post
TheAvengers2
BANNED
Join Date: Jul 2011
Old 04-15-2012 , 16:30   Re: Pick random player of server
Reply With Quote #5

Quote:
Originally Posted by rodrigo286 View Post
I tried but did not work, one player is randomly chosen and win the HE.

PHP Code:
#include <sourcemod>
#include <cstrike>

public OnPluginStart()
{
    
HookEvent("round_start"round_start);
}

public 
Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
rndClient GetRndClient();
    if (
rndClient > -1)
    {
        
GivePlayerItem(rndClient"weapon_hegrenade");
    }
}

GetRndClient()
{
    
decl iClients[MaxClients];
    new 
numClients;
    
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsClientSourceTV(i))
        {
            
iClients[numClients++] = i;
        }
    }
    
    if (
numClients)
    {
        return 
iClients[GetURandomInt() % numClients];
    }
    else
    {
        return -
1// no clients? let's not divide by zero. :)
    
}

Thanks.
Quote:
Originally Posted by thetwistedpanda View Post
Same concept, but you can also use new client = numClients ? iClients[GetRandomInt(0, (numClients - 1))] : -1 as opposed to GetURandomInt.
That'll work too.

Could also do:
Code:
return (numClients) ? iClients[GetURandomInt() % numClients] : -1;
But, I like my comment.

Last edited by TheAvengers2; 04-15-2012 at 16:43.
TheAvengers2 is offline