AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [HOWTO] Colored Player Names (https://forums.alliedmods.net/showthread.php?t=54978)

Tobi17 05-09-2007 18:40

[HOWTO] Colored Player Names
 
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

Olly 05-09-2007 19:21

Re: [HOWTO] Colored Player Names
 
nice work :D

sslice 05-09-2007 19:24

Re: [HOWTO] Colored Player Names
 
Might be worth noting that it is CS:S specific.

Fredd 08-27-2007 18:14

Re: [HOWTO] Colored Player Names
 
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.


All times are GMT -4. The time now is 01:19.

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