PDA

View Full Version : Loading playercolor for factions


xAzKingx
22/01/2015, 09:16 AM
Greeting all,


Thanks for reading this thread. I have a really bad confusion with color system. Im willing to make a color system for factions. But i cant get them to work. I tried EVERYTHING. Only problem i get into is this

player type in /factioncolor FFFFFF. It goes all the way here. Where it saves.
strmid(FactionInfo[id][FactionColor], string, 0, strlen(string), 255);


Now. how do i attach 0x with FactionInfo[id][FactionColor] and then attach FF in the end.

same thing with this too

0xFF with FactionInfo[id][FactionColor].

I tried everything. I searched all the threads. None of them helped so far.

IF NOT,

Please tell me how can a playersave the faction color with this /teamcolor 000000 and it turns out into 0x000000FF

another thing, Which one is the correct form if im going to save whole color on the command.


THIS?
enum fInfo
{
FactionTaken,
FactionName[20],
FactionLeader[MAX_PLAYER_NAME],
Float:FactionSpawn[4],
FactionColor[20]
};
new FactionInfo[10][fInfo];

or This?

enum fInfo
{
FactionTaken,
FactionName[20],
FactionLeader[MAX_PLAYER_NAME],
Float:FactionSpawn[4],
Float:FactionColor
};
new FactionInfo[10][fInfo];


Its been a huge pain for me, I cant just get it working lol. Please help. Either im full of stress and cant get the small thing working or It cant be done literally what im trying to do.

Note: I dont want to save playercolor from getplayercolor.

Threshold
22/01/2015, 10:34 AM
Show your command for /factioncolor or /teamcolor.

xAzKingx
22/01/2015, 10:44 AM
I removed it already. It wasnt working so i removed like week ago. lol


It was just a normal command which does like /factioncolor FFFFFF and your FFFFFF get saved.

Couldnt use them in setplayercolor. was giving me errors and showing this kinda colors IG FFF0FFFF. I was freaked out.

Threshold
22/01/2015, 11:25 AM
I'm going to assume you're using ZCMD, otherwise you can alter it as you see fit.

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:
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;'.

Nero_3D
22/01/2015, 12:40 PM
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;
}

xAzKingx
22/01/2015, 01:14 PM
Thanks guys for reading and putting in time here, Really helped me and my community. +Rep for both of you :)


Why is this error popping out?

C:\Users\Asad\Documents\Kingdom Roleplay\gamemodes\nwrp.pwn(26072) : error 021: symbol already defined: "HexToInt"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

xAzKingx
22/01/2015, 09:16 PM
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



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]);

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.

Nero_3D
23/01/2015, 12:42 PM
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

xAzKingx
23/01/2015, 03:34 PM
%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

Ye, I dont have multiple function but i think theres something with it, i dont know. I cant even get it working that way.

I want it to give out as 0xABCDEFFF and 0xFFABCDEF both and it should be able to save in this file. When player types /factioncolor FFFFFF. I should be able to save one on FamilyColor and other one on FamilyColor2

in this.
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]);

So i can use this 0xABCDEFFF < in setplayercolor and this 0xFFABCDEF in object like Flag color. Shield color etc etc etc.

Command you guys made me. Didnt work. It keeps giving me same reply IG. "/factioncolor [FFDDSS]" even tho im typing in /factioncolor 000FFF. Doesnt work. I did come modification in it and got it working. Only problem im facing right now is THAT saving issue. Its not saving correctly so i can use it after restart....

Help me out yall. This is hard as hell. Literally pain in my ass lol and %x for saving doesnt work. It gives out FFF000FF something like that without any "0x". I tried it with yellow. Object was showing PINK. Thats a bad sign.

Nero_3D
23/01/2015, 04:10 PM
I would only save the main color (0xABCDEF) and ignore the alpha part if it is always FF (personal opinion can be ignored)

In the command the end should look now like that

//
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.");

You could also use a function to convert them (if needed)

RGBAlpha(& color, rgba) {
if(rgba) { // rgba - argb
color = (color << 24) | (color >>> 8);
} else { // argb - rgba
color = (color >>> 24) | (color << 8);
}
}

xAzKingx
23/01/2015, 04:39 PM
What about this issue?

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]);

I cant get it saved with that %x. It doesnt give out 0xcolorFF or 0xFFColor

Nero_3D
23/01/2015, 05:33 PM
Did you try that code in your command? to get it saved correctly

//
new
id = PlayerInfo[playerid][pFMember],
rgba = (color << 8) | 0xFF, // normal functions - 0xABCDEFFF
argb = color | (0xFF << 24) // for objects - 0xFFABCDEF
;
FactionInfo[id][FamilyColor] = rgba;
FactionInfo[id][FamilyColor2] = argb;


If you want the 0x in front you need to add it into the format
format(string, sizeof string, "0x%x", color);

xAzKingx
23/01/2015, 08:12 PM
We did it man lol, It finally worked. Finally! Yeah! That sweet taste of victory.

http://i62.tinypic.com/5u2wl0.png

only thing is not working is this

if(color == 0) {
return SendClientMessage(playerid, -1, "USAGE: /factioncolor [RRGGBB] (0-9, A-F, a-f)");
}

can you make it with cmdtext? im using /factionlist command, Not dcmd_ or cmd: