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

[EDIT REQ] Block/Allow some characters on names


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Snake.
Senior Member
Join Date: Jul 2017
Old 02-10-2019 , 06:40   [EDIT REQ] Block/Allow some characters on names
Reply With Quote #1

It only allows A-Z and numbers on names but i want to allow $, &, %, /, (, ) etc... How can i do ?

PHP Code:
#include <amxmodx>

#define PLUGIN        "No-Spl Chars InName"
#define VERSION        "1.0"
#define AUTHOR        "Shooting King"


public plugin_init()
{
    
register_pluginPLUGINVERSIONAUTHOR );
}

public 
client_putinserver(idCheckName(idtrue);

public 
client_infochanged(idCheckName(idfalse);

public 
CheckNameidbool:bShowMsg )
{
    static 
ijszName[33], szNewName[33], len;
    
    
len 0;
    
szName[0] = '^0';
    
szNewName[0] = '^0';
    
    
get_user_info(id"name"szName33);
    
len strlen(szName);
    
// log_amx( "Checking.... %s[%d] ", szName, len );
    
    
for( 0leni++ )
    {
        if( (
szName[i] > 47 &&  szName[i] < 58) ||  // Numbers from 1, 2, ...., 0
            
(szName[i] > 64 &&  szName[i] < 91) ||    // Chars from A, B, C, ...., Z
            
(szName[i] > 96 &&  szName[i] < 123) || // Chars from a, b, c, ...., z
            
(szName[i] == ' ') )
        {
            
// log_amx( "a Valid Char.... %c[%d] ", szName[i], i );
            
szNewName[j] = szName[i];
            
j++;
        }
        else
        {
            
// log_amx( "Not a Valid Char.... %c[%d] ", szName[i], i );
            
continue;
        }
    }
    
    if( 
33 szNewName[j] = '^0';    
    
set_user_info(id,"name",szNewName); 
    
    if( 
bShowMsg )
    {
        
client_print0print_chat"Player with original nickname ^"%s^"[%s] joined the game."szNameszNewName );
    }

Snake. is offline
Send a message via Skype™ to Snake.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-10-2019 , 17:41   Re: [EDIT REQ] Block/Allow some characters on names
Reply With Quote #2

Here is the for loop optimized which makes it easier to add characters or the list of allowed characters:

PHP Code:
    for( 0leni++ )
    {
        switch( 
szName[i] )
        {
            case 
'0'..'9''A'..'Z''a'..'z'' '// Add characters to the list here.
            
{
                
// log_amx( "a Valid Char.... %c[%d] ", szName[i], i );
                
szNewName[j++] = szName[i];
            }
        }
    } 
Simply add the characters you want using single quotes around each one and separating them with commas in the case condition in the above code.
__________________

Last edited by fysiks; 02-10-2019 at 17:45.
fysiks 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 04:48.


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