Raised This Month: $12 Target: $400
 3% 

[SOLVED]Pick random player of server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-15-2012 , 15:00   [SOLVED]Pick random player of server
Reply With Quote #1

I need to get all round a random player, I tried a few ways posted, but none works.

Thanks.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 04-15-2012 at 16:42. Reason: Solved
rodrigo286 is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 04-15-2012 , 15:56   Re: Pick random player of server
Reply With Quote #2

You can store the potential clients in an array, and then use GetURandomInt and modulus to select a random one.

Spoiler

Last edited by TheAvengers2; 04-15-2012 at 16:15.
TheAvengers2 is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 04-15-2012 , 16:23   Re: Pick random player of server
Reply With Quote #3

Same concept, but you can also use new client = numClients ? iClients[GetRandomInt(0, (numClients - 1))] : -1 as opposed to GetURandomInt.
__________________

Last edited by thetwistedpanda; 04-15-2012 at 16:23.
thetwistedpanda is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-15-2012 , 16:24   Re: Pick random player of server
Reply With Quote #4

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)
{
    
GetRndClient();
}

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. :)
    
}

    
GivePlayerItem(numClients"weapon_hegrenade");

Thanks.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
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
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-15-2012 , 16:41   Re: Pick random player of server
Reply With Quote #6

Thanks works perfectly.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
Reply


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 11:45.


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