Loading playercolor for factions
#4

I'm going to assume you're using ZCMD, otherwise you can alter it as you see fit.

pawn Код:
CMD:factioncolor(playerid, params[]) //Called when a player types /factioncolor
{
    new hex[10]; //This variable will store whatever the player inputs
    if(sscanf(params, "s[10]", hex)) return SendClientMessage(playerid, -1, "USAGE: /factioncolor [RRGGBB]"); //If the player doesn't type a correct hex value.
    if(strlen(hex) != 6) return SendClientMessage(playerid, -1, "Incorrect HEX value! Hex must be in 'RRGGBB' format.");
    format(hex, sizeof(hex), "%sFF", hex);
    new output = HexToInt(hex); //Converts the string to an integer value
    if(output == 0) return SendClientMessage(playerid, -1, "Invalid HEX value! Characters must be between 0 and 9, or between A and F.");
    FactionInfo[FACTION_ID][FactionColor] = output;
    SendClientMessage(playerid, output, "This is the new color of your faction.");
    return 1;
}

stock HexToInt(string[])
{
    if(!string[0]) return 0;
    new cur = 1, res = 0;
    for(new i = strlen(string); i > 0; i--)
    {
        if(!('A' <= string[i - 1] <= 'F') && !('a' <= string[i - 1] <= 'f') && !('0' <= string[i - 1] <= '9')) return 0;
        res += cur * (string[i - 1] - ((string[i - 1] < 58) ? (48) : (55)));
        cur *= 16;
    }
    return res;
}
Includes ZCMD and SSCANF.
Obviously 'FACTION_ID' should be replaced by the player's faction, FactionColor is an integer, not a string.

EDIT:
Quote:
Originally Posted by Nero_3D
Your functions checks if there are small letters but you never convert them
Ah thanks Nero, didn't even overlook that. I got few more things to learn about stuff like 'color = color << 8 | 0xFF;' and 'result <<= 4;'.
Reply


Messages In This Thread
Loading playercolor for factions - by xAzKingx - 22.01.2015, 09:16
Re: Loading playercolor for factions - by Threshold - 22.01.2015, 10:34
Re: Loading playercolor for factions - by xAzKingx - 22.01.2015, 10:44
Re: Loading playercolor for factions - by Threshold - 22.01.2015, 11:25
AW: Loading playercolor for factions - by Nero_3D - 22.01.2015, 12:40
Re: Loading playercolor for factions - by xAzKingx - 22.01.2015, 13:14
Re: Loading playercolor for factions - by xAzKingx - 22.01.2015, 21:16
AW: Re: Loading playercolor for factions - by Nero_3D - 23.01.2015, 12:42
Re: AW: Re: Loading playercolor for factions - by xAzKingx - 23.01.2015, 15:34
AW: Loading playercolor for factions - by Nero_3D - 23.01.2015, 16:10

Forum Jump:


Users browsing this thread: 1 Guest(s)