Raised This Month: $ Target: $400
 0% 

Cvar Strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 06-30-2009 , 09:47   Cvar Strings
Reply With Quote #1

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?
shadow.hk is offline
Send a message via MSN to shadow.hk
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-30-2009 , 09:55   Re: Cvar Strings
Reply With Quote #2

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 
__________________

Last edited by Bugsy; 06-30-2009 at 10:08.
Bugsy is offline
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 06-30-2009 , 10:16   Re: Cvar Strings
Reply With Quote #3

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

By the way, thanks for the quick response, +karma
shadow.hk is offline
Send a message via MSN to shadow.hk
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-30-2009 , 10:18   Re: Cvar Strings
Reply With Quote #4

Quote:
Originally Posted by shadow.hk View Post
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().
__________________
Bugsy 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 15:28.


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