AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to replace color in chat? (https://forums.alliedmods.net/showthread.php?t=299097)

gameplayonline 07-02-2017 23:58

How to replace color in chat?
 
Im trying to find tutorial how to replace color of messages what player say but i cant find it have somebody?

gameplayonline 07-03-2017 01:39

Re: How to replace color in chat?
 
I have it if it will help somebody:
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <cstrike>

#define PLUGIN "Prefix"
#define VERSION "1.0"
#define AUTHOR "gameplayonline"

new  prefix[][] =
{
        "^1(^3Unassigned^1) [^4Affliate VIP^1]",                        //0
        "^1(^3Spectator^1) [^4Affliate VIP^1]",                                //1
        "^1*DEAD* (^3Counter-Terrorist^1) [^4Affliate VIP^1]",        //2
        "^1*DEAD* (^3Terrorist^1) [^4Affliate VIP^1]",                //3
        "^1[^4Affliate VIP^1]",                                                //4
        "^1*DEAD* [^4Affliate VIP^1]"                                //5
}


public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_clcmd("say", "VIP_Prefix")
        register_clcmd("say_team", "VIP_Prefix_Team") 
}

public VIP_Prefix(id)
{
        new Message[192]
        new Name[33]
        get_user_name(id, Name, charsmax(Name))
       
        read_args(Message, charsmax(Message))
        remove_quotes(Message)
       
        if(is_user_alive(id))
        {
                if(get_user_team(id) == 0)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message)
                }
                else if(get_user_team(id) == 1)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
                }
                else if(get_user_team(id) == 2)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
                }
                else if(get_user_team(id) == 3)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message)
                }
                else
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
                }
        }
        else
        {
                if(get_user_team(id) == 0)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message)
                }
                else if(get_user_team(id) == 1)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[3], Name, Message)
                }
                else if(get_user_team(id) == 2)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[2], Name, Message)
                }
                else if(get_user_team(id) == 3)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message)
                }
                else
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
                }
               
        }
        return PLUGIN_HANDLED
}

public VIP_Prefix_Team(id)
{
        new Message[192]
        new Name[33]
        get_user_name(id, Name, charsmax(Name))
       
        read_args(Message, charsmax(Message))
        remove_quotes(Message)
       
        if(is_user_alive(id))
        {
                if(get_user_team(id) == 0)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message)
                }
                else if(get_user_team(id) == 1)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
                }
                else if(get_user_team(id) == 2)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
                }
                else if(get_user_team(id) == 3)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message)
                }
                else
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
                }
        }
        else 
        {
                if(get_user_team(id) == 0)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message)
                }
                else if(get_user_team(id) == 1)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[3], Name, Message)
                }
                else if(get_user_team(id) == 2)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[2], Name, Message)
                }
                else if(get_user_team(id) == 3)
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message)
                }
                else
                {
                        ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
                }
               
        }
        return PLUGIN_HANDLED
}


fysiks 07-03-2017 03:28

Re: How to replace color in chat?
 
You should use a switch instead of an if else if structure for the user's team. Calling get_user_team() that many times is inefficient.

gameplayonline 07-04-2017 04:26

Re: How to replace color in chat?
 
i read somewhere function if is faster than switch and when i use switch it doesnt show messages what i type when i change team and it kill myself with if is it working normal. Is it true?
I dont know how to do else in switch

wickedd 07-04-2017 05:07

Re: How to replace color in chat?
 
PHP Code:

new CsTeams:teamteam cs_get_user_teamid 
    
switch( 
team )
{
    case 
CS_TEAM_T:
    {                    
        
//your code
    
}
    case 
CS_TEAM_CT:
    {
        
//your code
    
}




fysiks 07-04-2017 13:09

Re: How to replace color in chat?
 
https://wiki.alliedmods.net/Optimizi..._Optimizations

gameplayonline 07-08-2017 18:40

Re: How to replace color in chat?
 
after testing when i do
Code:

ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
Only myself see sented message when i try
Code:

ColorChat(0, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
everyone see it but with color of his own team. Chat with prefix Dead too see all players how can i fix it please?

gameplayonline 07-08-2017 19:34

Re: How to replace color in chat?
 
In API
Code:

client_print_color

Syntax

native client_print_color(index, sender, const message[], any:...);
Usage

index       
Client index, use 0 to display to all clients
sender       
Client index used as the message sender
fmt       
Formatting rules
...       
Variable number of formatting parameters

IS client index usable like Team? I think 0 is all 1 is terrorist 2 is CT 3 is spectator or no?

fysiks 07-09-2017 00:33

Re: How to replace color in chat?
 
You can't choose red or blue, only team color. I know that there exists a function that tricks the game into thinking you are on the other team to force a color but I don't know if it actually works or is reliable.

index is the specific player which is often called "id" in most plugins/functions and is the player's entity index.

gameplayonline 07-09-2017 11:19

Re: How to replace color in chat?
 
And is any other way how to do colored chat with prefixes where Terrorist will see name of Counter-Terrorist in blue color?


All times are GMT -4. The time now is 23:10.

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