HEX formatting
#1

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?
Reply
#2

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);
}
Reply
#3

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
Reply
#4

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}
Reply
#5

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)
Reply
#6

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);
}
Reply
#7

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
Reply
#8

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.
Reply
#9

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)