Trying to make admin messages a different color
#1

Hey, I've made a little snippet of code to change my server's admin's public chat color, but everytime I try to use it, I get 2 messages sent, and they aren't even setting the color, and yes, I have return 0; at the end, did I mess something up in my code?

Код:
	if(PlayerInfo[playerid][pAdmin] > 1)
	{
	    new output[128];
	    new pcol = GetPlayerColor(playerid);
	    SetPlayerColor(playerid, pcol);
     	    format(output, sizeof(output), "%s(%i):{00FF00} %s", playerid, text);
     	    SendPlayerMessageToAll(playerid, output);
     	    session[messages] = session[messages] + 1;
	    return 0;
	}
Or should I try it like it says in the Wiki? https://sampwiki.blast.hk/wiki/OnPlayerText
Reply
#2

Код:
new output[128], name[MAX_PLAYER_NAME];
	    new pcol = GetPlayerColor(playerid);
	    SetPlayerColor(playerid, pcol);
	    GetPlayerName(playerid, name, sizeof(name));
	    format(output, sizeof(output), "%s(%d):{00FF00} %s", name, playerid, text);
	    SendPlayerMessageToAll(playerid, output);
	    session[messages] = session[messages] + 1;
Reply
#3

Quote:
Originally Posted by Shetch
Посмотреть сообщение
Код:
new output[128], name[MAX_PLAYER_NAME];
	    new pcol = GetPlayerColor(playerid);
	    SetPlayerColor(playerid, pcol);
	    GetPlayerName(playerid, name, sizeof(name));
	    format(output, sizeof(output), "%s(%d):{00FF00} %s", name, playerid, text);
	    SendPlayerMessageToAll(playerid, output);
	    session[messages] = session[messages] + 1;
Still doesn't work, and it sends two messages into the chat, and it does something weird with the second message though, it adds my name twice, one in black, and one in white,**Thats caused becuase GetPlayerColor isn't working, for some odd reason**
Picture
Reply
#4

SendPlayerMessage already incorporates the player's name, so you don't need to fetch it again. Also GetPlayerColor doesn't work if SetPlayerColor hasn't been used before. It says that on the wiki page.
Reply
#5

I'm not sure what sends them twice, but GetPlayerColor returns 0 if SetPlayerColor hasn't been used.

EDIT: I'm late^
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
SendPlayerMessage already incorporates the player's name, so you don't need to fetch it again. Also GetPlayerColor doesn't work if SetPlayerColor hasn't been used before. It says that on the wiki page.
Oh Okay, That makes sense, Guess I'll have to make a player color save feature, and when he joins, it will set the saved color, and I found out something else, I had to edit something else in the script, because it was conflicting with the code above

Problem Solved, Thanks for your help guys. + Rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)