Raised This Month: $ Target: $400
 0% 

Get Players On Server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
icequeenzz
Member
Join Date: May 2008
Old 01-16-2010 , 19:16   Get Players On Server
Reply With Quote #1

i tried creating a plugin that would return me the players that are on the server. pretty easy i tought cuz im a noob @ coding. but it was harder then i tought.

i hoped someone here could say what i did wrong that it doesnt return a couple of things

my code:
PHP Code:
#define PLUGIN_NAME "TF2 Online Players"
#define PLUGIN_VERSION "1.0"

new stringcName[10000];
new 
cId[10000];
new 
stringcIp[10000];
new 
nrClients 0


public 
Plugin:myinfo 
{
    
name PLUGIN_NAME,
    
author "Icequeenzz",
    
description "Prints connected players @ console",
    
version PLUGIN_VERSION,
    
url "http://TFO2.webs.com"
};

public  
OnClientConnected(client)
{
    
GetClientName(clientcName[nrClients], 20);
    
GetClientIP(clientcIp[nrClients], 25);
    
GetClientAuthString(clientcId[nrClients] , 50);
    
nrClients++;
}

public 
OnPluginStart()
{
    
CreateConVar("sm_PlayerPrint"PLUGIN_VERSIONPLUGIN_NAMEFCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
RegConsoleCmd("OnPlayers"Command_Players);
}

public 
Action:Command_Players(clientargs)
{
        
PrintToServer("Players On Server: %s"nrClients);
        for(new 
0nrClients ii++)
        {
            if(
IsClientConnected(cId))
            {
            
PrintToServer("Player: %s, %d, %f"cName[i], cId[i], cIp[i]);
            }
        }

What happens:

it return "players on server: " and then it gives a kinda wingding things O_o.. 1 = smily 2 = coloured smily 3= heart etc..

it then returns the name of the first player well.
but when another player joins it adds the first 4 letters of his name onto the previous player.
it doesnt show the steamid and also not the id.

some help on telling me what i did wrong is appreciated

soz for my bad english

Icequeenzz
__________________

icequeenzz is offline
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 01-16-2010 , 19:27   Re: Get Players On Server
Reply With Quote #2

Use %N instead of converting their name to a string. Dunno how to help you with the others though.
noodleboy347 is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 01-16-2010 , 21:31   Re: Get Players On Server
Reply With Quote #3

status does this well
__________________
almcaeobtac is offline
Bigbuck
Senior Member
Join Date: Jul 2009
Old 01-16-2010 , 23:08   Re: Get Players On Server
Reply With Quote #4

Quote:
Originally Posted by almcaeobtac View Post
status does this well
Either that or HLSW if you want a "neater" look.
Bigbuck is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 01-17-2010 , 02:03   Re: Get Players On Server
Reply With Quote #5

1. Getting SteamID OnClientConnected is a bad idea. Player SteamID validated only some time after connection. Do it on OnClientAuthorized or in the command's callback.
2. Use sm_PlayerPrint_version as version cvar
3. You are using %d and %f for strings instead of %s (ip and SteamID are strings)

%d for integers (also %i)
%f for floats
%s for strings
%N player's name

4. You can loop directly through clients without adding them in array in OnClientConnected. Loop from 1 to MaxClients, and check if IsClientInGame.
5. There is a default function GetClientCount
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 01-17-2010 at 02:18.
exvel is offline
Send a message via ICQ to exvel
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 01-17-2010 , 02:09   Re: Get Players On Server
Reply With Quote #6

All you need... OnClientConnected is not needed.
PHP Code:
public OnPluginStart()
{
    
CreateConVar("sm_PlayerPrint_version"PLUGIN_VERSIONPLUGIN_NAMEFCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
RegConsoleCmd("OnPlayers"Command_Players);
}

public 
Action:Command_Players(clientargs)
{
    
// Simple buffer strings
    
new String:szIP[20];
    new 
String:szSteam[32];
    
    
PrintToServer("Players On Server: %d"GetClientCount());
    
    
// Looping through all clients
    
for (new 1<= MaxClientsi++)
    {
        
// If client is not in game then skip him
        
if (!IsClientInGame(i))
            continue;

        
// Checking client's authorization string (SteamID)    
        
if (IsClientAuthorized(i))
        {
            
GetClientAuthString(iszSteamsizeof(szSteam));
        }
        
// Client is not authorized
        
else
        {
            
Format(szSteamsizeof(szSteam), "Not authorized");
        }
        
        
GetClientIP(iszIPsizeof(szIP));
        
        
// Printing name, ip, SteamID
        
PrintToServer("Player: %N, %s, %s"iszSteamszIP);
    }

__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 01-17-2010 at 02:21.
exvel is offline
Send a message via ICQ to exvel
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 05:09.


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