Help with OnPlayerText
#1

Hello guys, I'm having a little problem in OnPlayerText.. The thing is, that when a player types something in the chat, his name should be in Team color. Like for example if he's in USA team, he's nick color must be blue and only the nickname, not also the rest of the text what he types..

Here's the pic how it looks at the moment: http://i.imgur.com/ozF7NlN.png


And the code:

Код:
new
        hours, 
        minutes, 
        seconds,
        str[128], 
        name[MAX_PLAYER_NAME]; 

        GetPlayerName(playerid,name,sizeof(name)); 
        gettime(hours, minutes, seconds); 
        format(str,sizeof(str),"[%02d:%02d:%02d] %s [%d]: %s",hours,minutes,seconds,PlayerName(playerid),playerid,text); 
        SendClientMessageToAll( -1, str); // 
        return 0; // Returning 0
Please give me a hint what do I have to change or add. I know it's very simple, but I always forget something..

Thanks!
Reply
#2

Use SetPlayerColor:
https://sampwiki.blast.hk/wiki/SetPlayerColor
Reply
#3

As you can see here, the -1 is color white.
pawn Код:
format(str,sizeof(str),"[%02d:%02d:%02d] %s [%d]: %s",hours,minutes,seconds,PlayerName(playerid),playerid,text);
        SendClientMessageToAll( -1, str); //
Therefore it will send the message in white, use GetPlayerColor, and put it instead of -1.
You can always show the rest of the message in white if you want it by putting {FFFFFF} in the string format, whereever you want it to be white.

So replace the above with this.
pawn Код:
format(str,sizeof(str),"[%02d:%02d:%02d] %s [%d]: {FFFFFF}%s",hours,minutes,seconds,PlayerName(playerid),playerid,text);
        SendClientMessageToAll(GetPlayerColor, str);
Or ofcourse remove the {FFFFFF} if you do not want white color after the name. This works with other colors too, as long as you put them inside such boxes: { }
Reply
#4

This is from my script:
PHP код:
        new playername[128], message[128];
        
GetPlayerName(playeridplayernamesizeof(playername));
        
format(messagesizeof(message), "{%06x}%s[%d]:{FFFFFF} %s"GetPlayerColor(playerid) >>> 8playernameplayeridtext);
        
SendClientMessageToAll(COLOR_WHITEmessage); 
You can edit it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)