PDA

View Full Version : Loading Color?


xAzKingx
24/01/2015, 04:46 PM
How do you load this color from saved files?


I have 0xFFFFF000 and 0xFFF000FF saved in KingdomColor and KingdomFlagColor.


They are not loading. This is my loading thing.

public LoadFamilys()
{
new arrCoords[3][64];
new strFromFile2[256];
new File: file = fopen("LARP/Familys.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(FamilyInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
FamilyInfo[idx][FamilyTaken] = strval(arrCoords[0]);
FamilyInfo[idx][FamilyColor] = strval(arrCoords[1]);
FamilyInfo[idx][FamilyFlagColor] = strval(arrCoords[2]);
idx++;
}
fclose(file);
}
return 1;
}

Dignity
24/01/2015, 04:50 PM
A hex value isn't a string, so you don't need to use strval.

xAzKingx
24/01/2015, 04:56 PM
A hex value isn't a string, so you don't need to use strval.


I dont know what should i use instead lol never worked with colors.

Dignity
24/01/2015, 04:59 PM
Nothing, inserting them as an integer should work.

xAzKingx
24/01/2015, 05:06 PM
Nothing, inserting them as an integer should work.

Im loading the color from a file, Aight? Unless it wont load. This FamilyInfo[id][FamilyColor] Would be 0 or 000000


So can you please show me how its done lol

Dignity
24/01/2015, 05:08 PM
:picard:

I'm retarded, please excuse my shit posting.

Write
24/01/2015, 05:11 PM
You must save the color as an integer and load it as an integer and don't use the "x" parameter it's broken atm.

TakeiT
24/01/2015, 05:12 PM
Not made by me, but I used something like this for a SetObjectMaterialText script I made about a year ago.


HexToInt(string[]){
if (string[0]==0) return 0;
new i;
new cur=1;
new res=0;
for (i=strlen(string);i>0;i--) {
if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
cur=cur*16;
}
return res;
}

Write
24/01/2015, 06:06 PM
Not made by me, but I used something like this for a SetObjectMaterialText script I made about a year ago.


HexToInt(string[]){
if (string[0]==0) return 0;
new i;
new cur=1;
new res=0;
for (i=strlen(string);i>0;i--) {
if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
cur=cur*16;
}
return res;
}
If he's loading it as an integer why would he want to convert the hex to the integer again?

xAzKingx
24/01/2015, 06:51 PM
like i have been saying, Color system is pain in ass lol

i tried this, but this aint working either


Edit: I tried this too

public LoadFamilys()
{
new rgba[4], argb[4], color[4];
new arrCoords[4][64];
new strFromFile2[256];
new File: file = fopen("LARP/Familys.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(FamilyInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
FamilyInfo[idx][FamilyTaken] = strval(arrCoords[0]);
color[idx] = HexToInt(arrCoords[1]);
rgba[idx] = (color[idx] << 8) | 0xFF,
argb[idx] = color[idx] | (0xFF << 24);
FamilyInfo[idx][FamilyColor] = rgba[idx];
FamilyInfo[idx][FamilyFlagColor] = argb[idx];
//printf("Family:%d Taken: %d Name:%s MOTD:%s Leader:%s Members:%d SpawnX:%f SpawnY:%f SpawnZ:%f Int:%d",
//idx,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][FamilyInterior]);
idx++;
}
fclose(file);
}
return 1;
}

doesnt work either, Shows some random color.

xAzKingx
24/01/2015, 09:57 PM
waiting a reply =/

xAzKingx
25/01/2015, 08:03 AM
Im trying to get 0xFFABCDEF and 0xABCDEFFF from a file. Its not working at all. Please help me. No one have a solution.


enum fInfo
{
FamilyTaken,
Color[20],
FamilyColor,
FamilyFlagColor
};
new FamilyInfo[9][fInfo];


Command:
if(strcmp(cmd, "/setcolor", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_GREY, " You havent logged in yet !");
return 1;
}
if(PlayerInfo[playerid][pLeader] == 0 && PlayerInfo[playerid][pFMember] == 255 || PlayerInfo[playerid][pFMember] != 255 && PlayerInfo[playerid][pRank] < 6)
{
SendClientMessage(playerid, COLOR_GREY, " You are not allowed to use this command!");
return 1;
}
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx+= 1;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx+= 1;
}
result[idx - offset] = EOS;
new color = HexToInt(cmdtext);
//color = color << 8 | 0xFF;
new
rgba = (color << 8) | 0xFF, // normal functions - 0xABCDEFFF
argb = color | (0xFF << 24); // for objects - 0xFFABCDEF
else if(PlayerInfo[playerid][pLeader] >= 1)
{
new id = PlayerInfo[playerid][pLeader];
strmid(FamilyInfo[id][Color], result, 0, strlen(result), 255);
FamilyInfo[id][FamilyColor] = rgba;
FamilyInfo[id][FamilyFlagColor] = argb;
SaveFamilys();
SendClientMessage(playerid, rgba, "[Family]: This is the new color of your Family.");
SendClientMessage(playerid, COLOR_WHITE, "For more colors, Visit: www.colorpicker.com");
}
else
{
SendClientMessage(playerid, COLOR_GREY, "[!]: Either your bugged or this system is bugged, Report it to AzKing.");
}
}
return 1;
}

Loading The color
public LoadFamilys()
{
new rgba[9], argb[9], color[9];
new arrCoords[4][64];
new strFromFile2[256];
new File: file = fopen("LARP/Familys.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(FamilyInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
FamilyInfo[idx][FamilyTaken] = strval(arrCoords[0]);
color[idx] = HexToInt(arrCoords[1]);
rgba[idx] = (color[idx] << 8) | 0xFF,
argb[idx] = color[idx] | (0xFF << 24);
FamilyInfo[idx][FamilyColor] = rgba[idx];
FamilyInfo[idx][FamilyFlagColor] = argb[idx];
idx++;
}
fclose(file);
}
return 1;
}

Saving color
public SaveFamilys()
{
new idx;
new File: file2;
while (idx < sizeof(FamilyInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d|%s\n",
FamilyInfo[idx][FamilyTaken],
FamilyInfo[idx][Color]);
if(idx == 0)
{
file2 = fopen("LARP/Familys.cfg", io_write);
}
else
{
file2 = fopen("LARP/Familys.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}

What am i doing wrong here. Why isnt it working. Stupid colors lol