[Tutorial] Random colors on OnPlayerText (CHAT)
#1

Random Chat Colors

Hi there. Since 0.3c, you can now format the text with different "colors", instead just one, such as:
pawn Код:
SendClientMessage(playerid, 0xFFFFFFFF, "message"); // White = 0xFFFFFFFF
And, in this tutorial, I'm gonna tell you how to do "random colors" on the PlayerText. Not really useful, but funny though :P.

Firstly, we need to define the colors we gonna use. Put it on your script top:
PS: You can add more colors. Site for get these colors: Click here
pawn Код:
#define red "{FF002B}"
#define pink "{FF00D9}"
#define purple "{DFA7F2}"
#define blue "{A1C2FF}"
#define green "{3DE3B1}"
#define yellow "{FAF623}"
#define black "{69670C}"
#define orange "{F2C80C}"
#define ice "{03F2FF}"
#define lime "{00FF40}"
Also we need the arrays, since the color is randomly chosen, it will be chosen from the color array. So, put that after the color define, I told above.
PS: I used 3 arrays instead 1 because I'd get same colors with just one. Also, by other way with 1 array, would bug. Test yourself if you do not believe
pawn Код:
// Remember that 10 is the amount of colors that is on the array. You need to change according you add new colors!
static title[][10] =
{
""#red"",
""#pink"",
""#purple"",
""#blue"",
""#green"",
""#yellow"",
""#black"",
""#orange"",
""#ice"",
""#lime""
};
static message[][10] =
{
""#red"",
""#pink"",
""#purple"",
""#blue"",
""#green"",
""#yellow"",
""#black"",
""#orange"",
""#ice"",
""#lime""
};
static id[][10] =
{
""#red"",
""#pink"",
""#purple"",
""#blue"",
""#green"",
""#yellow"",
""#black"",
""#orange"",
""#ice"",
""#lime""
};
Now, we gotta go for the OnPlayerText callback:
pawn Код:
public OnPlayerText(playerid, text[])
{
    // Make the changes according you like. I did this on my script as I like
    new rand = random(sizeof(title)); // Random from array 'title'
    new rand2 = random(sizeof(id)); // Random from array 'id'
    new rand3 = random(sizeof(message)); // Random from array 'message'
    static name[MAX_PLAYER_NAME],string[128]; // Defining the 'string' and the 'name'
    GetPlayerName(playerid,name,sizeof(name)); // Here, we get the player name
    format(string,sizeof(string),"%s%s %s(%d): %s%s",title[rand][0],name,id[rand2][0],playerid,message[rand3][0],text); // formating the string which will be sent
    SendClientMessageToAll(color, string); // Here we send the string for all :P
        return 0; // Dont forget that
}
Explainment:
Код:
title[rand][0] = Gets a random color from the array 'title'
name = Player name, gotten from the array 'name'
id[rand2][0] = Gets a random color from the array 'id'
playerid = the player ID (Number in this case)
message[rand3][0] = Gets a random color from the array 'message'
text = The text which the player has typed
RESULT:


CREDITS: Blackwave

PASTEBIN: Click here
Reply
#2

Desperdiзando Vбriaveis.
Reply
#3

Good.
Reply
#4

Awesome, thanks for the TuT
Reply
#5

Nice tut brother
Reply
#6

Very usefull, thanks.
Reply
#7

Код:
SendClientMessageToAll(color, string);
you didn't define "color"? is it supposed to be defined anyways?
Reply
#8

Awesome!
Thanks Bro
Reply
#9

Nice and it is very usefull
Reply
#10

Rainbow in my eyes )) Nice idea =)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)