Customizing colors in SendClientMessage -
Elie1996 - 04.07.2016
I'd like to do something like this:
function(color1,color2)
{
SendClientMessage(playerid,COLOR_WHITE, "{color1} Hello {color2} World!");
return 1;
}
It seems far-fetched but is it somehow possible.
Thanks.
Re: Customizing colors in SendClientMessage -
DRIFT_HUNTER - 04.07.2016
#define color_black "{000000}"
SendClientMessage(playerid,COLOR_WHITE, "Hello "color_black" World!");
Re: Customizing colors in SendClientMessage -
Mencent - 04.07.2016
Hello!
You can realize that like this:
PHP код:
stock function1(color1[],color2[])
{
new string[144],s1[10],s2[10];
if(!strcmp(color1,"red",true))format(s1,sizeof(s1),"ef3f23");
if(!strcmp(color2,"green",true))format(s2,sizeof(s2),"476e15");
format(string,sizeof string,"{%s} Hello,{%s} this is a test message!",s1,s2);
SendClientMessageToAll(-1,string);
return 1;
}
So, you have the choice between red and green. Of yourse, you can insert more colours.
Re: Customizing colors in SendClientMessage -
Stinged - 04.07.2016
Quote:
Originally Posted by Mencent
Hello!
You can realize that like this:
PHP код:
stock function1(color1[],color2[])
{
new string[144],s1[10],s2[10];
if(!strcmp(color1,"red",true))format(s1,sizeof(s1),"ef3f23");
if(!strcmp(color2,"green",true))format(s2,sizeof(s2),"476e15");
format(string,sizeof string,"{%s} Hello,{%s} this is a test message!",s1,s2);
SendClientMessageToAll(-1,string);
return 1;
}
So, you have the choice between red and green. Of yourse, you can insert more colours.
|
That's just a waste of memory.
If you want to make a function like that, you just just use a macro.
Re: Customizing colors in SendClientMessage -
Elie1996 - 04.07.2016
Yeah I know those, But I wish to use the parameters color1 and color2. And not A macro definition... Isn't there a way?
Re: Customizing colors in SendClientMessage -
Stinged - 04.07.2016
Why do you reject using a macro? It does the job fine here.
Код:
#define function(%0,%1,%2) SendClientMessage(%0, COLOR_WHITE, "{"#%1"}Hello {"#%2"}World!")
// %0 = player
// %1 = color1 -- This format: RRGGBB
// %2 = color2 -- This format: RRGGBB
// Example:
function(playerid, 000000, 00FF00);
Would send this:
Hello World
Re: Customizing colors in SendClientMessage -
SickAttack - 04.07.2016
pawn Код:
// ** INCLUDES
#include <a_samp>
#include <sscanf>
#include <zcmd>
// ** MAIN
main()
{
print("Loaded \"color_hex_function.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** COMMANDS
CMD:color(playerid, params[])
{
Function(playerid, "0xFFF000FF", "0xFF0000FF");
return 1;
}
// ** FUNCTIONS
stock Function(playerid, color_1[], color_2[])
{
new string[144];
format(string, sizeof(string), "{%06x}Hello {%06x}World!", HexToInt(color_1) >>> 8, HexToInt(color_2) >>> 8);
SendClientMessage(playerid, -1, string);
return 1;
}
stock HexToInt(hex[])
{
new int;
sscanf(hex, "x", int);
return int;
}
Re: Customizing colors in SendClientMessage -
Elie1996 - 04.07.2016
Quote:
Originally Posted by SickAttack
pawn Код:
// ** INCLUDES
#include <a_samp> #include <sscanf> #include <zcmd>
// ** MAIN
main() { print("Loaded \"color_hex_function.amx\"."); }
// ** CALLBACKS
public OnGameModeInit() { return 1; }
public OnGameModeExit() { return 1; }
// ** COMMANDS
CMD:color(playerid, params[]) { Function(playerid, "0xFFF000FF", "0xFF0000FF"); return 1; }
// ** FUNCTIONS
stock Function(playerid, color_1[], color_2[]) { new string[144]; [COLOR="Red"] format(string, sizeof(string), "{%06x}Hello {%06x}World!", HexToInt(color_1) >>> 8, HexToInt(color_2) >>> 8);[/COLOR] SendClientMessage(playerid, -1, string); return 1; }
stock HexToInt(hex[]) { new int; sscanf(hex, "x", int); return int; }
|
Hey could you explain two the line of
format for me?
I don't understand what "
>>> 8" means, nor the
{%06x}
also, just to be sure, what do u assume you exactly have in array hex[]? Only the code of the colors correct?
Thanks for replying!
Re: Customizing colors in SendClientMessage -
Elie1996 - 04.07.2016
Quote:
Originally Posted by Stinged
Why do you reject using a macro? It does the job fine here.
Код:
#define function(%0,%1,%2) SendClientMessage(%0, COLOR_WHITE, "{"#%1"}Hello {"#%2"}World!")
// %0 = player
// %1 = color1 -- This format: RRGGBB
// %2 = color2 -- This format: RRGGBB
// Example:
function(playerid, 000000, 00FF00);
Would send this:
Hello World
|
I refuse to use MACROS because they won't work in my case.
I know how to use MACRO like this; but I need to write code that'll allow me to send different colors of my choice to make my code look cleaner.
Re: Customizing colors in SendClientMessage -
SickAttack - 05.07.2016
Quote:
Originally Posted by Elie1996
Hey could you explain two the line of format for me?
I don't understand what ">>> 8" means, nor the {%06x}
also, just to be sure, what do u assume you exactly have in array hex[]? Only the code of the colors correct?
Thanks for replying!
|
hex[] = variable passed to the function
{%06x} = placeholder for hexadecimal values, the 6 ensures that the output string will always be six characters long and the 0 will pad it with zeros if it's not
>>> 8 = logical right shift to remove the alpha value (transparent: two last characters)
https://sampwiki.blast.hk/wiki/Colors_List