HEX formatting -
sim_sima - 19.12.2013
Just a fast question.
I am trying to make a function called "SendSystemMessage".
Here is what it looks like:
pawn Код:
stock SendSystemMessage(playerid, color, message[])
{
new string[170];
format(string,sizeof(string),"{FFFFFF}[{2B78FF}MSG{FFFFFF}] {%x}%s", color, message);
SendClientMessage(playerid, color, string);
}
My problem is the color implementing (the "{%x}").
The the color is used in the function, it will look something like this:
pawn Код:
SendSystemMessage(playerid, 0x009900FF, "Welcome back!");
But in order to use the color in the string formatting, it needs to look like this: "009900"
I have to remove the "0x" and the last 2 letters within the formatting. How do I do that?
Re: HEX formatting -
Konstantinos - 19.12.2013
pawn Код:
stock SendSystemMessage(playerid, color, message[])
{
new string[144];
format(string,sizeof(string),"[{2B78FF}MSG{FFFFFF}] {%06x}%s", color >>> 8, message);
SendClientMessage(playerid, -1, string);
}
Re: HEX formatting -
sim_sima - 19.12.2013
Quote:
Originally Posted by Konstantinos
pawn Код:
stock SendSystemMessage(playerid, color, message[]) { new string[144]; format(string,sizeof(string),"[{2B78FF}MSG{FFFFFF}] {%06x}%s", color >>> 8, message); SendClientMessage(playerid, -1, string); }
|
Doesn't work. I need to split the HEX color like this: 0x 009900 FF
so that it only uses the MIDDLE 6 characters of the HEX.
Removing the 0x and the FF like this: 009900
Thank you for trying though
Re: HEX formatting -
Konstantinos - 19.12.2013
It does work.
Run:
pawn Код:
#include <a_samp>
main()
{
new
string[9],
color = 0x009900FF;
format(string, sizeof(string), "{%06x}", color >>> 8);
print(string);
}
The output is: {009900}
Re: HEX formatting -
sim_sima - 19.12.2013
Quote:
Originally Posted by Konstantinos
It does work.
Run:
pawn Код:
#include <a_samp>
main() { new string[9], color = 0x009900FF; format(string, sizeof(string), "{%06x}", color >>> 8); print(string); }
The output is: {009900}
|
This is a function that I am making. It is supposed to be used like this:
pawn Код:
SendSystemMessage(playerid, 0x009900FF, "This is a message")
It will send a client message that looks like this: "[MSG] This is a message", where the "[]" are blue and the "MSG" is white, and the "This is a message" will be green (or whatever color you use in the function)
Re: HEX formatting -
Konstantinos - 19.12.2013
Quote:
Originally Posted by sim_sima
It will send a client message that looks like this: "[MSG] This is a message", where the "[]" are blue and the "MSG" is white, and the "This is a message" will be green (or whatever color you use in the function)
|
The code you posted in your first post does the opposite. It makes the brackets [] white and the MSG blue.
pawn Код:
stock SendSystemMessage(playerid, color, message[])
{
new string[144];
format(string, sizeof(string), "[{FFFFFF}MSG{2B78FF}] {%06x}%s", color >>> 8, message);
SendClientMessage(playerid, 0x2B78FFFF, string);
}
Re: HEX formatting -
sim_sima - 19.12.2013
Quote:
Originally Posted by Konstantinos
The code you posted in your first post does the opposite. It makes the brackets [] white and the MSG blue.
pawn Код:
stock SendSystemMessage(playerid, color, message[]) { new string[144]; format(string, sizeof(string), "[{FFFFFF}MSG{2B78FF}] {%06x}%s", color >>> 8, message); SendClientMessage(playerid, 0x2B78FFFF, string); }
|
Yes I know, but I changed that. The problem is the string message, not the "[MSG]" part
Re: HEX formatting -
Konstantinos - 19.12.2013
Well, the code works fine. I even tested it to show you how it looks like:
So the problem is that you're doing something wrong.
Re: HEX formatting -
sim_sima - 19.12.2013
Quote:
Originally Posted by Konstantinos
Well, the code works fine. I even tested it to show you how it looks like:
So the problem is that you're doing something wrong.
|
Yes it would be easy to make it if I only wanted to use the green color.
But I want to be able to use it dynamically with any color
EDIT: Oh nvm, I figured it out
Thank you!