22.01.2015, 11:25
(
Последний раз редактировалось Threshold; 23.01.2015 в 01:56.
)
I'm going to assume you're using ZCMD, otherwise you can alter it as you see fit.
Includes ZCMD and SSCANF.
Obviously 'FACTION_ID' should be replaced by the player's faction, FactionColor is an integer, not a string.
EDIT:
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;'.
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;
}
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
|