Raised This Month: $ Target: $400
 0% 

[HOWTO] Colored Player Names


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 15:12.


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