AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cvar Strings (https://forums.alliedmods.net/showthread.php?t=96061)

shadow.hk 06-30-2009 09:47

Cvar Strings
 
Wondering why when I use a pcvar to set a name or 'tag' that it skips certain symbols?

Here's the portion of the code.

PHP Code:

public cmdTag(id)
{
    new 
szName[32];
    
get_user_name(id,szName,31);
    
    new 
szTagName[16];
    switch(
g_bAdmin[id])
    {
        case 
true:    get_pcvar_string(cvar_membertag,szTagName,15);
        case 
false:    get_pcvar_string(cvar_admintag,szTagName,15);
    }
    
    if(
contain(szName,szTagName) != -1)
    {
        
client_print(id,print_chat,"You're already tagged up.");
        return 
PLUGIN_HANDLED;
    }
    
    new 
bool:prename;
    if(
contain(szTagName,"!p"))
    {
        
prename true;
        
replace(szTagName,15,"!p","");
    }
    
    switch(
prename)
    {
        case 
true:    client_cmd(id,"name ^"%%s^"",szTagName,szName);
        case 
false:    client_cmd(id,"name ^"%%s^"",szName,szTagName);
    }
    
    
client_print(id,print_chat,"You are now tagged up.");
    
    return 
PLUGIN_HANDLED;


It gets the cvar string fine but when I set it to, say, "!pTag#", it skips the # symbol. Any ideas? :|

Bugsy 06-30-2009 09:55

Re: Cvar Strings
 
contain and containi return -1 on failure so you cannot do an if( contain() ) check. Also, this function can return 0 if the contain string is found at the beginning of the search-in string. You use it correctly the first time in the above code.

Use
PHP Code:

if( containszTagName "!p" ) != -

Also, you should not use a switch statement for checking bool values. A simple if-statement will suffice.

PHP Code:

if ( prename )
    
//true
else
    
//false 

PHP Code:

if ( g_bAdmin[id] )
    
//true
else
    
//false 


shadow.hk 06-30-2009 10:16

Re: Cvar Strings
 
So this should fix the problem with the # symbol not turning up for (!pTag#)?

By the way, thanks for the quick response, +karma

Bugsy 06-30-2009 10:18

Re: Cvar Strings
 
Quote:

Originally Posted by shadow.hk (Post 860774)
So this should fix the problem with the # symbol not turning up for (!pTag#)?

By the way, thanks for the quick response, +karma

Try it and see. If not, try to determine whether it is not being found at contain() or replace().


All times are GMT -4. The time now is 15:28.

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