Raised This Month: $32 Target: $400
 8% 

[HOWTO] Colored Player Names


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tobi17
Senior Member
Join Date: May 2005
Old 05-09-2007 , 18:40   [HOWTO] Colored Player Names
Reply With Quote #1

Hello,

I made some functions to color all player names within a private message. The client name will be display in team colors while all other players will be displayed green.

Code:
stock color_player(owner_index, player_index, String: client_message[192]) 
{
	decl String:client_name[192];
	GetClientName(player_index, client_name, 192);

	new find_pos = StrContains(client_message, client_name, true);
	new String:temp_message[192];
	if (find_pos > -1) {
		new name_length = strlen(client_name);
		new message_length = strlen(client_message);
		new offset = 0;
		for(new i = 0; i < message_length; i++) {
			new edit_pos = i + offset;
			if (i == find_pos) {
				if (owner_index == player_index) {
					temp_message[edit_pos]   = 3;
				} else {
					temp_message[edit_pos]   = 4;
				}
				offset++
		  	} else if (i == (find_pos + name_length)) {
				temp_message[edit_pos]   = 1;
				offset++;
			}
			new pos = i + offset;
			temp_message[pos] = client_message[i];
		}
		strcopy(client_message, 192, temp_message);
	}
	
}

stock color_all_players(owner_index, String: message[192]) 
{
	new max_clients = GetMaxClients();
	for(new i = 1; i <= max_clients; i++) {
		new client = i;
		if (IsClientConnected(client)) {
			color_player(owner_index, client, message);
		}
	}
}
To color the playernames you would call the function with:
Code:
 color_all_players(client, message);
Remember not(!) to execute this function on every client message to display! We have made a very good trade-off to display this function only if the client player name is affected:
Code:
decl String:client_name[192];
GetClientName(player_index, client_name, 192);
if (StrContains(client_message, client_name, true) >= 0) {
	color_all_players(player_index, client_message);
}
Bye
Tobi

Last edited by Tobi17; 05-09-2007 at 18:44.
Tobi17 is offline
Olly
Senior Member
Join Date: Mar 2007
Location: UK
Old 05-09-2007 , 19:21   Re: [HOWTO] Colored Player Names
Reply With Quote #2

nice work
Olly is offline
Send a message via MSN to Olly
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 05-09-2007 , 19:24   Re: [HOWTO] Colored Player Names
Reply With Quote #3

Might be worth noting that it is CS:S specific.
__________________
sslice is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 08-27-2007 , 18:14   Re: [HOWTO] Colored Player Names
Reply With Quote #4

This doesn't work because, color_all_players has only 2 parms and since you check if the message contains the name, there is no away someone could add the name to color_all_players unless if you think everyone is going to use a format message or add a parm to your function other than that good tut.
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode