Customizing colors in SendClientMessage
#1

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

#define color_black "{000000}"

SendClientMessage(playerid,COLOR_WHITE, "Hello "color_black" World!");
Reply
#3

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

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

Yeah I know those, But I wish to use the parameters color1 and color2. And not A macro definition... Isn't there a way?
Reply
#6

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

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)