Is a Color a string or variable - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is a Color a string or variable (
/showthread.php?tid=432089)
how do you save a hex in dini -
horsemeat - 21.04.2013
hello I Have a question about this color
is it a string or is it a variable if it is nether the tell what it is
I would like to make a command like this
pawn Код:
CMD:changecolor(playerid, params[])
{
new color;
if(sscanf(params,"i",color))
{
return SendClientMessage(playerid, RED, "SYNTAX /changecolor [color]");
}
SendClientMessage(playerid,color,"I like the color you picked");
return 1;
}
SOLVED
is a hex
Next question
how do you save a hex dini
SOLVED
dini_Intset works just fine
Re: Is a Color a string or variable -
FalconX - 21.04.2013
I believe it can be either used as integer or hex, doesn't matter.
You may use
h,
x or
i itself as a specifier in sscanf; for more information you may check the following link:
https://sampforum.blast.hk/showthread.php?tid=120356
Regards FalconX
Re: Is a Color a string or variable -
Pottus - 21.04.2013
A hex is just a number so you would use sscanf(params,"h",color) if your syntax is 0xFFFFFFFF it's a good to make sure the
STRING being supplied is a valid hex I did just that a few weeks ago try this stock function.
pawn Код:
// Is string a hexvalue
stock IsHexValue(const hstring[])
{
printf("%i",strlen(hstring));
if(strlen(hstring) < 10) return 0;
if(hstring[0] == 48 && hstring[1] == 120)
{
for(new i = 2; i < 10; i++)
{
if(hstring[i] == 48 || hstring[i] == 49 || hstring[i] == 50 || hstring[i] == 51 || hstring[i] == 52 ||
hstring[i] == 53 || hstring[i] == 54 || hstring[i] == 55 || hstring[i] == 56 || hstring[i] == 57 ||
hstring[i] == 65 || hstring[i] == 66 || hstring[i] == 67 || hstring[i] == 68 || hstring[i] == 69 ||
hstring[i] == 70) continue;
else return 0;
}
}
else return 0;
return 1;
}
You can also make it accept integer value inputs as well by checking if your color string in the command text is number with this stock.
pawn Код:
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Re: Is a Color a string or variable -
horsemeat - 21.04.2013
how would you use
pawn Код:
stock IsHexValue(const hstring[])
{
printf("%i",strlen(hstring));
if(strlen(hstring) < 10) return 0;
if(hstring[0] == 48 && hstring[1] == 120)
{
for(new i = 2; i < 10; i++)
{
if(hstring[i] == 48 || hstring[i] == 49 || hstring[i] == 50 || hstring[i] == 51 || hstring[i] == 52 ||
hstring[i] == 53 || hstring[i] == 54 || hstring[i] == 55 || hstring[i] == 56 || hstring[i] == 57 ||
hstring[i] == 65 || hstring[i] == 66 || hstring[i] == 67 || hstring[i] == 68 || hstring[i] == 69 ||
hstring[i] == 70) continue;
else return 0;
}
}
else return 0;
return 1;
}
I tryed an if statment but it did not seem to work I not so good at these stock functions