This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Finding a random player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-21-2015 , 15:24   Finding a random player
Reply With Quote #1

How do I find random player?
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
Icetea16
Member
Join Date: Jul 2015
Location: France
Old 07-21-2015 , 15:30   Re: Finding a random player
Reply With Quote #2

if you have smlib:
PHP Code:
Client_GetRandom(CLIENTIFILTER_ALIVE); 
else

PHP Code:
int random GetRandomInt(1GetMaxPlayers());

if (
IsClientInGame(random) && IsPlayerAlive(random))
{
    
PrintToChatAll("The player %N was randomly choosed."random);

__________________
I'm French, sorry for my bad english...
Icetea16 is offline
R1KO
Member
Join Date: Sep 2013
Old 07-21-2015 , 15:37   Re: Finding a random player
Reply With Quote #3

PHP Code:
new iClient GetRandomClient(); 
if (
iClient

    
// code



GetRandomClient() 

    
decl iClients[MaxClients], iClientsNumi;
    
iClientsNum 0
    for (
1<= MaxClients; ++i
    { 
        if (
IsClientInGame(i))
        {
            
iClients[iClientsNum++] = i
        }
    } 
    if (
iClientsNum 0)
    {
        return 
iClients[GetRandomInt(0iClientsNum-1)]; 
    }
    return 
0
R1KO is offline
Send a message via Skype™ to R1KO
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-21-2015 , 15:40   Re: Finding a random player
Reply With Quote #4

Quote:
Originally Posted by Icetea16 View Post
if you have smlib:
PHP Code:
Client_GetRandom(CLIENTIFILTER_ALIVE); 
else

PHP Code:
int random GetRandomInt(1GetMaxPlayers());

if (
IsClientInGame(random) && IsPlayerAlive(random))
{
    
PrintToChatAll("The player %N was randomly choosed."random);

I need GetMaxPlayers() Method.

Quote:
Originally Posted by R1KO View Post
PHP Code:
new iClient GetRandomClient(); 
 if (
iClient
 { 
     
// code
 



 
GetRandomClient() 
 { 
     
decl iClients[MaxClients], iClientsNumi;
     
iClientsNum 0
     for (
1<= MaxClients; ++i
     { 
         if (
IsClientInGame(i))
         {
             
iClients[iClientsNum++] = i
         }
     } 
     if (
iClientsNum 0)
     {
         return 
iClients[GetRandomInt(0iClientsNum-1)]; 
     }
     return 
0
PHP Code:
new iClient GetRandomClient(); 
Error:
plugin.sp(1 : error 010: invalid function or declaration
plugin.sp(1 : error 008: must be a constant expression; assumed zero
__________________
SourcePawn, C# and C++ Programmer.

My plugin list

Last edited by TheUnderTaker; 07-21-2015 at 15:51.
TheUnderTaker is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-21-2015 , 16:16   Re: Finding a random player
Reply With Quote #5

Someone help?
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-21-2015 , 16:40   Re: Finding a random player
Reply With Quote #6

Quote:
Originally Posted by TheUnderTaker View Post
Someone help?


You need to stop bumping posts as it is in violation of the rules
headline is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-21-2015 , 18:03   Re: Finding a random player
Reply With Quote #7

PHP Code:
public int GetRandomClient()  
{  
    
int iClients[MaxClients]; // or int iClients[MAXPLAYERS]?
    
int iClientsNumi;
    for (
1<= MaxClients; ++i)  
    {  
        if (
IsClientInGame(i)) 
        { 
            
iClients[iClientsNum++] = i;  
        } 
    }  
    if (
iClientsNum 0
    { 
        return 
iClients[GetRandomInt(0iClientsNum-1)];  
    } 
    return 
0;

Potato Uno is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-22-2015 , 03:20   Re: Finding a random player
Reply With Quote #8

Quote:
Originally Posted by Potato Uno View Post
PHP Code:
public int GetRandomClient()  
{  
    
int iClients[MaxClients]; // or int iClients[MAXPLAYERS]?
    
int iClientsNumi;
    for (
1<= MaxClients; ++i)  
    {  
        if (
IsClientInGame(i)) 
        { 
            
iClients[iClientsNum++] = i;  
        } 
    }  
    if (
iClientsNum 0
    { 
        return 
iClients[GetRandomInt(0iClientsNum-1)];  
    } 
    return 
0;

Thanks, I will try and I think it's MAXPLAYERS +1, i'm not sure...

EDIT: It's MAXPLAYERS.
__________________
SourcePawn, C# and C++ Programmer.

My plugin list

Last edited by TheUnderTaker; 07-22-2015 at 03:27.
TheUnderTaker is offline
Dr. Api
BANNED
Join Date: Mar 2015
Location: France
Old 07-22-2015 , 04:03   Re: Finding a random player
Reply With Quote #9

for theam
PHP Code:
/***********************************************************/
/*********************** RANDOM PLAYER *********************/
/***********************************************************/
stock int GetRandomPlayer(int team
{
    
int[] clients = new int[MaxClients];
    
int clientCount;
    for (
int i 1<= MaxClientsi++)
    {
        if (
Client_IsIngame(i) && (GetClientTeam(i) == team))
        {
            
clients[clientCount++] = i;
        }
    }
    return (
clientCount == 0) ? -clients[GetRandomInt(0clientCount-1)];

all

PHP Code:
/***********************************************************/
/*********************** RANDOM PLAYER *********************/
/***********************************************************/
stock int GetRandomPlayer() 
{
    
int[] clients = new int[MaxClients];
    
int clientCount;
    for (
int i 1<= MaxClientsi++)
    {
        if (
Client_IsIngame(i))
        {
            
clients[clientCount++] = i;
        }
    }
    return (
clientCount == 0) ? -clients[GetRandomInt(0clientCount-1)];

Dr. Api is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-22-2015 , 04:31   Re: Finding a random player
Reply With Quote #10

Quote:
Originally Posted by Dr. Api View Post
for theam
PHP Code:
/***********************************************************/
/*********************** RANDOM PLAYER *********************/
/***********************************************************/
stock int GetRandomPlayer(int team
{
    
int[] clients = new int[MaxClients];
    
int clientCount;
    for (
int i 1<= MaxClientsi++)
    {
        if (
Client_IsIngame(i) && (GetClientTeam(i) == team))
        {
            
clients[clientCount++] = i;
        }
    }
    return (
clientCount == 0) ? -clients[GetRandomInt(0clientCount-1)];

all

PHP Code:
/***********************************************************/
/*********************** RANDOM PLAYER *********************/
/***********************************************************/
stock int GetRandomPlayer() 
{
    
int[] clients = new int[MaxClients];
    
int clientCount;
    for (
int i 1<= MaxClientsi++)
    {
        if (
Client_IsIngame(i))
        {
            
clients[clientCount++] = i;
        }
    }
    return (
clientCount == 0) ? -clients[GetRandomInt(0clientCount-1)];

Full of errors, Are you sure you know syntax? I want Get Random Player and move him to blue team.
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker 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 09:55.


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