Raised This Month: $32 Target: $400
 8% 

Selecting a random player


Post New Thread Reply   
 
Thread Tools Display Modes
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-20-2017 , 21:05   Re: Selecting a random player
Reply With Quote #11

Quote:
Originally Posted by Halt View Post
Okay so a few questions on Toxins post

PHP Code:
int bFirstZombie 0//Couldnt this be new bFirstZombie?

stock int GetRandomPlayer()
{
    
int Players[MAXPLAYERS]; //Dont understand purpose
    
int MAXPLAYERS 0//Dont understand purpose
    
    
for    (int Client 1Client <= MaxClientsClient++) //Creates loop and what ends it
    
{
        if(
IsClientInGame(Client)) //Check for valid client
            
continue;
        
        if    (
PlayerTeam[Client] != TFTeam_Blue//Check for client on BLU team
            
continue;
        
        if    (
Client == bFirstZombie//Check for is the player was first zombie? A little confused
            
continue;
        
    }
    
    if    (
MAXPLAYERS == 0)
        
bFirstZombie = -1;
    else
        
bFirstZombie Players[GetRandomInt(0MAXPLAYERS 1)];
    return 
bFirstZombie;

Questions are in the block above.

Secondly whats the point of MaxClients/MaxPlayers?


As for hmmmm's post so we are setting i to 0 then each time the loop runs 1 is added to i. Once I equals 5 the loop stops?
If you want to go back and forth quickly feel free to join our discord.

https://discord.gg/smRV8Rq
headline is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-21-2017 , 17:57   Re: Selecting a random player
Reply With Quote #12

Quote:
Originally Posted by Halt View Post
Okay so a few questions on Toxins post

PHP Code:
int bFirstZombie 0//Couldnt this be new bFirstZombie?

stock int GetRandomPlayer()
{
    
int Players[MAXPLAYERS]; //Dont understand purpose
    
int MAXPLAYERS 0//Dont understand purpose also compiler threw an error here says it expected an identifier but found integer.
    
    
for    (int Client 1Client <= MaxClientsClient++) //Creates loop and what ends it
    
{
        if(
IsClientInGame(Client)) //Check for valid client
            
continue;
        
        if    (
PlayerTeam[Client] != TFTeam_Blue//Check for client on BLU team
            
continue;
        
        if    (
Client == bFirstZombie//Check for is the player was first zombie? A little confused
            
continue;
        
    }
    
    if    (
MAXPLAYERS == 0//Threw and error on compile (Redundant code constant expression is zero)
        
bFirstZombie = -1;
    else
        
bFirstZombie Players[GetRandomInt(0MAXPLAYERS 1)];
    return 
bFirstZombie;

Questions are in the block above. The compiler threw a few errors.

Secondly whats the point of MaxClients/MaxPlayers?


As for hmmmm's post so we are setting i to 0 then each time the loop runs 1 is added to i. Once I equals 5 the loop stops?

Also at what point is this Toxins code checking for the client index stored in bFirstZombie and selecting a different client if they were the first zombie last round?
1) MAXPLAYERS must be all in lower case.
2) int x or new x it's the same, just the first one is in the new syntax.
3) I'd suggest to change bFirstZombie to iFirstZombie since it's a integer.
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 09-21-2017 at 17:59.
Papero is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-21-2017 , 22:30   Re: Selecting a random player
Reply With Quote #13

Incase anyone cares this is what we (Headline and myself) ended up using as the solution.

PHP Code:
public Action GetZombieTimer(Handle timer)
{
    
int _FirstZombie GetZombie();
    
    if    (
_FirstZombie && GetClientCount() <= 5)
        
TF2_RespawnPlayer(_FirstZombie);
    if    (
_FirstZombie && GetClientCount() >= 10)
    {
        
int _FirstZombie2 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie2);
    }
    if    (
_FirstZombie && GetClientCount() >= 15)
    {
        
int _FirstZombie3 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie3);
    }
    if    (
_FirstZombie && GetClientCount() >= 20)
    {
        
int _FirstZombie4 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie4);
    }
}

int GetZombie()
{
    
int[] ClientIndexArray = new int[MaxClients 1];
    
int Increments 0;
    
    for    (
int i 1<= MaxClientsi++)
    {
        if    (!
IsClientInGame(i))
        {
            continue;
        }
        if    (
== g_iLastZombie)
        {
            continue; 
        }
        
ClientIndexArray[Increments] = i;
        
Increments++
    }
    if    (
Increments == 0)
    {
        return 
0//Possible Error
    
}
    
    
int SelectedIndex GetRandomInt(0Increments 1);
    
g_iLastZombie ClientIndexArray[SelectedIndex];
    
bIsPlayerZombie[g_iLastZombie] = true;
    
PrintToChat(g_iLastZombie"\x07ff2929[\x0730FF31ZomXR\x07ff2929] - \x07e3f010You've been selected as the first zombie");
    
PrintToChatAll("\x07ff2929[\x0730FF31ZomXR\x07ff2929] - \x07e3f010%N is the zombie leader!"g_iLastZombie);
    
    return 
g_iLastZombie;

If you were picked randomly last time you will not be picked randomly next time. Unless there are multiple players on the server.
Halt is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-21-2017 , 23:02   Re: Selecting a random player
Reply With Quote #14

Quote:
Originally Posted by Halt View Post
Incase anyone cares this is what we (Headline and myself) ended up using as the solution.

PHP Code:
public Action GetZombieTimer(Handle timer)
{
    
int _FirstZombie GetZombie();
    
    if    (
_FirstZombie && GetClientCount() <= 5)
        
TF2_RespawnPlayer(_FirstZombie);
    if    (
_FirstZombie && GetClientCount() >= 10)
    {
        
int _FirstZombie2 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie2);
    }
    if    (
_FirstZombie && GetClientCount() >= 15)
    {
        
int _FirstZombie3 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie3);
    }
    if    (
_FirstZombie && GetClientCount() >= 20)
    {
        
int _FirstZombie4 GetZombie();
        
TF2_RespawnPlayer(_FirstZombie4);
    }
}

int GetZombie()
{
    
int[] ClientIndexArray = new int[MaxClients 1];
    
int Increments 0;
    
    for    (
int i 1<= MaxClientsi++)
    {
        if    (!
IsClientInGame(i))
        {
            continue;
        }
        if    (
== g_iLastZombie)
        {
            continue; 
        }
        
ClientIndexArray[Increments] = i;
        
Increments++
    }
    if    (
Increments == 0)
    {
        return 
0//Possible Error
    
}
    
    
int SelectedIndex GetRandomInt(0Increments 1);
    
g_iLastZombie ClientIndexArray[SelectedIndex];
    
bIsPlayerZombie[g_iLastZombie] = true;
    
PrintToChat(g_iLastZombie"\x07ff2929[\x0730FF31ZomXR\x07ff2929] - \x07e3f010You've been selected as the first zombie");
    
PrintToChatAll("\x07ff2929[\x0730FF31ZomXR\x07ff2929] - \x07e3f010%N is the zombie leader!"g_iLastZombie);
    
    return 
g_iLastZombie;

If you were picked randomly last time you will not be picked randomly next time. Unless there are multiple players on the server.

I'm glad you got something working. It's not perfect, but if you keep learning and getting better you'll revisit this code with things to fix.
headline 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 23:28.


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