Raised This Month: $12 Target: $400
 3% 

Convert string to char (color)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
client21
Senior Member
Join Date: Apr 2013
Old 02-11-2017 , 18:00   Convert string to char (color)
Reply With Quote #1

PHP Code:
// ok, good
new GetColorChar("{green}"); 
PrintToChatAll(" zzz %c Test 1"x);

// how?
GetColorChar("#FFFFFF");
PrintToChatAll(" zzz %c Test 2"x);

stock GetColorChar(const String:sColor[])
{
    if (!
strcmp(sKey"{green}"false))
        return 
'\x04';

    if (
sColor[0] == '#')
    {
        
decl String:info[50];
        
FormatEx(info50"\x07%s"sColor[1]);
        
retrun .... ??? (StringToChar not existStringToInt not work)
    }

    return 
'\x01';

I know, i can save color in string like this
PrintToChatAll(" zzz \x07%s Test 2", "FFFFFF");
But i want char (int). How?

Last edited by client21; 02-11-2017 at 18:05.
client21 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-11-2017 , 18:37   Re: Convert string to char (color)
Reply With Quote #2

"\x07FFFFFF" is a 64 bit large string, you're not going to be able to put that into a 8 bit large char

you can do something like this:

PHP Code:
stock String:GetColorChar(const String:sColor[])
{
    
decl String:ret[50];
    
    if (!
strcmp(sColor"{green}"false))
    {
        
strcopy(retsizeof(ret), "\x04");
    }
    else if (
sColor[0] == '#')
    {
        
FormatEx(retsizeof(ret), "\x07%s"sColor[1]);
    }
    else
    {
        
strcopy(retsizeof(ret), "\x01");
    }
    
    return 
ret;
}  

public 
void OnPluginStart()
{
    new 
String:x[50];
    
GetColorChar("{green}"); 
    
PrintToChatAll(" zzz %s Test 1"x);
    
    
GetColorChar("#FFFFFF");
    
PrintToChatAll(" zzz %s Test 2"x);

but that still isn't a char
Miu 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 03:57.


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