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

Problems with GetClientName


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EmJay88
Junior Member
Join Date: Sep 2020
Old 11-16-2020 , 07:34   Problems with GetClientName
Reply With Quote #1

Hello everyone,

i'm new in programming and i think i use the GetClientName function the wrong way. The ID is different but the name is always the same. What can i do to print all Names? I need this for a more complex plugin and i have already filtered out that it is due to this problem. Thanks a lot!

PHP Code:
public OnPluginStart()
{
    
HookEvent("round_start"EventRoundStart);
}

public 
EventRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{

for(new 
1<= MaxClientsi++)
    {
        new 
String:name[MAX_NAME_LENGTH];        
        
PrintToChatAll("Name: %N"GetClientName(inamesizeof(name)));
        
PrintToChatAll("Index: %d"i);
    }

EmJay88 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-16-2020 , 08:00   Re: Problems with GetClientName
Reply With Quote #2

It's incorrect forum but here you go. I'm also new to sourcepawn.

Code:
    for(new i = 1, String:name[MAX_NAME_LENGTH]  ; i <= MaxClients; i++)     {               if(  GetClientName(i, name, sizeof(name)-1)  ) {               PrintToChatAll("ID #%i Name: %s", i, name);          }     }
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-16-2020 at 08:11.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-17-2020 , 05:43   Re: Problems with GetClientName
Reply With Quote #3

GetClientName return value is bool, 1 or 0
Code:
bool GetClientName(int client, char[] name, int maxlen)
https://sm.alliedmods.net/new-api/clients/GetClientName


Here is three example, works same way
PHP Code:
    char buffer[MAX_NAME_LENGTH]; // string where store text

    
GetClientName(clientbuffersizeof(buffer));
    
PrintToChatAll("Name - %s"buffer);

    
// https://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)#Format_Specifiers
    
Format(buffersizeof(buffer), "%N"client);
    
PrintToChatAll("Name - %s"buffer);

    
PrintToChatAll("Name - %N"client); 

And here if loop, you should check first, is client in game before continue code.
PHP Code:
    for(int client 1client <= MaxClientsclient++)
    {
        
// skip client indexes, which is not in-game
        
if(!IsClientInGame(client)) continue;
        
        
        
PrintToChatAll("Index %i - Name %N"clientclient);
    } 
__________________
Do not Private Message @me
Bacardi is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 11-17-2020 , 07:29   Re: Problems with GetClientName
Reply With Quote #4

You can just pass client index for %N:
Code:
for (int i = 1; i <= MaxClients; i++) {
	if ( IsClientConnected( i ) )
		PrintToChatAll( "Index: %i | Name: %N", i, i );
}
__________________
MAGNAT2645 is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 11-18-2020 , 02:12   Re: Problems with GetClientName
Reply With Quote #5

If you're going to use the format specifier %N, then you should give it a client index.
If you want to use GetClientName, then you should use the specifier %s.

Example:

PHP Code:
for(int i 1<= MaxClientsi++)
    if(
IsClientConnected(i))
    {
        
PrintToChatAll("Name: %N"i);
        
PrintToChatAll("Index: %d"i);
    } 
https://wiki.alliedmods.net/Format_C...eMod_Scripting)

Last edited by FAQU; 11-18-2020 at 02:13. Reason: Forgot to add a link.
FAQU 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 15:48.


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