enum fInfo { FactionTaken, FactionName[20], FactionLeader[MAX_PLAYER_NAME], Float:FactionSpawn[4], FactionColor[20] }; new FactionInfo[10][fInfo]; |
enum fInfo { FactionTaken, FactionName[20], FactionLeader[MAX_PLAYER_NAME], Float:FactionSpawn[4], Float:FactionColor }; new FactionInfo[10][fInfo]; |
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;
}
Originally Posted by Nero_3D
Your functions checks if there are small letters but you never convert them
|
CMD:factioncolor(playerid, params[]) {
new
color = HexToInt(params)
;
if(color == 0) {
return SendClientMessage(playerid, -1, "USAGE: /factioncolor [RRGGBB] (0-9, A-F, a-f)");
}
color = color << 8 | 0xFF;
FactionInfo[FACTION_ID][FactionColor] = color;
return SendClientMessage(playerid, color, "This is the new color of your faction.");;
}
stock HexToInt(string[]) {
new
i,
result,
tmp = string[0]
;
do {
result <<= 4;
if('0' <= tmp <= '9') {
result += tmp - '0';
continue;
}
if('A' <= tmp <= 'F') {
result += tmp - ('A' - 10);
continue;
}
if('a' <= tmp <= 'f') {
result += tmp - ('a' - 10);
continue;
}
return false;
} while((tmp = string[++i]));
return result;
}
C:\Users\Asad\Documents\Kingdom Roleplay\gamemodes\nwrp.pwn(26072) : error 021: symbol already defined: "HexToInt" Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 1 Error. |
format(coordsstring, sizeof(coordsstring), "%d|%s|%s|%s|%d|%f|%f|%f|%f|%s|%s|%s|%s|%s|%s|%d|% f|%d|%d\n", FamilyInfo[idx][FamilyTaken], FamilyInfo[idx][FamilyName], FamilyInfo[idx][FamilyMOTD], FamilyInfo[idx][FamilyLeader], FamilyInfo[idx][FamilyMembers], FamilyInfo[idx][FamilySpawn][0], FamilyInfo[idx][FamilySpawn][1], FamilyInfo[idx][FamilySpawn][2], FamilyInfo[idx][FamilySpawn][3], FamilyInfo[idx][FamilyRank1], FamilyInfo[idx][FamilyRank2], FamilyInfo[idx][FamilyRank3], FamilyInfo[idx][FamilyRank4], FamilyInfo[idx][FamilyRank5], FamilyInfo[idx][FamilyRank6], FamilyInfo[idx][FamilyInterior], FamilyInfo[idx][FamilyColor], FamilyInfo[idx][FamilyPoints], FamilyInfo[idx][FamilyLastDate]); |
Okey, Im having another issue saving it. Im trying to save it with %x and its giving out this
Rank 6|0|FFF000FF|0|0 Plus, Im still getting that error. I dont know why... I dont have double pasted or any thing described with that. Still getting that error. |
%x gives out the number in hex, nothing wrong, how do you want it ?
About the error, you must have the function twice, maybe it is already defined in an include The easieast would be to comment out that one in your script and check if it still works or you simply rename it to something else |
format(coordsstring, sizeof(coordsstring), "%d|%s|%s|%s|%d|%f|%f|%f|%f|%s|%s|%s|%s|%s|%s|%d|% x|%x|%d|%d\n", FamilyInfo[idx][FamilyTaken], FamilyInfo[idx][FamilyName], FamilyInfo[idx][FamilyMOTD], FamilyInfo[idx][FamilyLeader], FamilyInfo[idx][FamilyMembers], FamilyInfo[idx][FamilySpawn][0], FamilyInfo[idx][FamilySpawn][1], FamilyInfo[idx][FamilySpawn][2], FamilyInfo[idx][FamilySpawn][3], FamilyInfo[idx][FamilyRank1], FamilyInfo[idx][FamilyRank2], FamilyInfo[idx][FamilyRank3], FamilyInfo[idx][FamilyRank4], FamilyInfo[idx][FamilyRank5], FamilyInfo[idx][FamilyRank6], FamilyInfo[idx][FamilyInterior], FamilyInfo[idx][FamilyColor] FamilyInfo[idx][FamilyColor2], FamilyInfo[idx][FamilyPoints], FamilyInfo[idx][FamilyLastDate]); |
//
new
rgba = (color << 8) | 0xFF, // normal functions - 0xABCDEFFF
argb = color | (0xFF << 24) // for objects - 0xFFABCDEF
;
FactionInfo[FACTION_ID][FactionColor] = rgba;
FactionInfo[FACTION_ID][FactionColor2] = argb;
return SendClientMessage(playerid, rgba, "This is the new color of your faction.");
RGBAlpha(& color, rgba) {
if(rgba) { // rgba - argb
color = (color << 24) | (color >>> 8);
} else { // argb - rgba
color = (color >>> 24) | (color << 8);
}
}