AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Players chat colors problem (https://forums.alliedmods.net/showthread.php?t=222397)

medow 08-02-2013 07:03

Players chat colors problem
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define MAXSLOTS 32

enum Color
{
    
YELLOW 1// Yellow
    
GREEN// Green Color
    
TEAM_COLOR// Red, grey, blue
    
GREY// grey
    
RED// Red
    
BLUE// Blue
}

new 
TeamInfo;
new 
SayText;
new 
MaxSlots;

new 
bool:IsConnected[MAXSLOTS 1];

new 
TeamName[][] = 
{
    
"",
    
"TERRORIST",
    
"CT",
    
"SPECTATOR"
}

new 
ColorMode;

public 
plugin_init() {
    
register_plugin("Color Chat""1.03""MaTTe");
    
    
ColorMode register_cvar("colorchat_mode""2");
    
    
register_clcmd("say""hook_say",ADMIN_KICK);
    
register_clcmd("say_team""hook_team_say",ADMIN_KICK);
    
    
TeamInfo get_user_msgid("TeamInfo");
    
SayText get_user_msgid("SayText");
    
MaxSlots get_maxplayers();
}

public 
client_putinserver(player)
{
    
IsConnected[player] = true;
}

public 
client_disconnect(player)
{
    
IsConnected[player] = false;
}

public 
hook_say(id) {
    if(!
get_pcvar_num(ColorMode))
        return 
PLUGIN_CONTINUE;

    static 
text2[200];
    
read_args(text2199);
    
remove_quotes(text2);
    
trim(text2);
    
    new 
name[32];
    
get_user_name(idname31);
    
    if(
equal(text2""))
        return 
PLUGIN_HANDLED;
    switch(
get_pcvar_num(ColorMode)) {
        case 
1
        {
            if(
is_user_alive(id)) 
                
ColorChat(0RED"^x03%s : %s"nametext2);
            else
                
ColorChat(0RED"^x03*DEAD* %s : ^x03%s"nametext2);
        }
        case 
2
                        
        {
            if(
is_user_alive(id) & get_user_team(id) == 1)
                
ColorChat(0RED"%s : %s"nametext2);
                if(!
is_user_alive(id) && get_user_team(id) == 1)    
                
ColorChat(0RED"*DEAD* %s : %s"nametext2);
                        if(
is_user_alive(id) & get_user_team(id) == 2)
                                
ColorChat(0BLUE"%s : %s"nametext2);
                        if(!
is_user_alive(id) && get_user_team(id) == 1)
                                
ColorChat(0BLUE"*DEAD* %s : %s"nametext2);
                        if(
is_user_alive(id) & get_user_team(id) == 3)
                                
ColorChat(0GREY"%s : %s"nametext2);
                        if(!
is_user_alive(id) && get_user_team(id) == 3)
                                
ColorChat(0GREY"*DEAD* %s : %s"nametext2);
        }
        case 
3
        {
            if(
is_user_alive(id))
                
ColorChat(0BLUE"^x01%s : ^x03%s"nametext2);
            else
                
ColorChat(0BLUE"^x01*DEAD* %s : ^x03%s"nametext2);
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
hook_team_say(id) {
    if(!
get_pcvar_num(ColorMode))
        return 
PLUGIN_CONTINUE;
        
    static 
text2[200];
    
read_args(text2199);
    
remove_quotes(text2);
    
trim(text2);
    
    new 
name[32];
    
get_user_name(idname31);
    
    if(
equal(text2""))
        return 
PLUGIN_HANDLED;
    switch(
get_pcvar_num(ColorMode)) {
        case 
1
        {
            if((
is_user_alive(id) == 0))
                
ColorChat(0RED"^x03*DEAD* %s : %s"nametext2);
            else
                
ColorChat(0RED"^x03%s : %s"nametext2);
        }
        case 
2
        {
            
            if(
is_user_alive(id) & get_user_team(id) == 1)
                
ColorChat(0RED"%s : %s"nametext2);
                if(!
is_user_alive(id) && get_user_team(id) == 1)    
                
ColorChat(0RED"*DEAD* %s : %s"nametext2);
                        if(
is_user_alive(id) & get_user_team(id) == 2)
                                
ColorChat(0BLUE"%s : %s"nametext2);
                        if(!
is_user_alive(id) && get_user_team(id) == 1)
                                
ColorChat(0BLUE"*DEAD* %s : %s"nametext2);
                        if(
is_user_alive(id) & get_user_team(id) == 3)
                                
ColorChat(0GREY"%s : %s"nametext2);
                        if(!
is_user_alive(id) && get_user_team(id) == 3)
                                
ColorChat(0GREY"*DEAD* %s : %s"nametext2);
        }
        case 
3
        {
            if((
is_user_alive(id) == 0))
                
ColorChat(0BLUE"^x01*DEAD* %s : ^x03%s"nametext2);
            else
                
ColorChat(0BLUE"%s : %s"nametext2);
        }
    }
    
    return 
PLUGIN_HANDLED;
}            

public 
ColorChat(idColor:type, const msg[], {Float,Sql,Result,_}:...)
{
    static 
message[256];

    switch(
type)
    {
        case 
YELLOW// Yellow
        
{
            
message[0] = 0x01;
        }
        case 
GREEN// Green
        
{
            
message[0] = 0x04;
        }
        default: 
// White, Red, Blue
        
{
            
message[0] = 0x03;
        }
    }

    
vformat(message[1], 251msg4);

    
// Make sure message is not longer than 192 character. Will crash the server.
    
message[192] = '^0';

    new 
teamColorChangeindexMSG_Type;
    
    if(!
id)
    {
        
index FindPlayer();
        
MSG_Type MSG_ALL;
    
    } else {
        
MSG_Type MSG_ONE;
        
index id;
    }
    
    
team get_user_team(index);    
    
ColorChange ColorSelection(indexMSG_Typetype);

    
ShowColorMessage(indexMSG_Typemessage);
        
    if(
ColorChange)
    {
        
Team_Info(indexMSG_TypeTeamName[team]);
    }
}

ShowColorMessage(idtypemessage[])
{
    
emessage_begin(typeSayText_id);
    
ewrite_byte(id)        
    
ewrite_string(message);
    
emessage_end();    
}

Team_Info(idtypeteam[])
{
    
emessage_begin(typeTeamInfo_id);
    
ewrite_byte(id);
    
ewrite_string(team);
    
emessage_end();

    return 
1;
}

ColorSelection(indextypeColor:Type)
{
    switch(
Type)
    {
        case 
RED:
        {
            return 
Team_Info(indextypeTeamName[1]);
        }
        case 
BLUE:
        {
            return 
Team_Info(indextypeTeamName[2]);
        }
        case 
GREY:
        {
            return 
Team_Info(indextypeTeamName[0]);
        }
    }

    return 
0;
}

FindPlayer()
{
    new 
= -1;

    while(
<= MaxSlots)
    {
        if(
IsConnected[++i])
        {
            return 
i;
        }
    }

    return -
1;


The problem is that players can't write in chat.(The text doesn't appear - look just in case 2)

Black Rose 08-02-2013 12:13

Re: Players chat colors problem
 
You should really learn to debug if you want to create plugins.
Here's a small tutorial:

Code:
            server_print("Called case 2:1")             if(is_user_alive(id) & get_user_team(id) == 1)                 ColorChat(0, RED, "%s : %s", name, text2);             if(!is_user_alive(id) && get_user_team(id) == 1)                     ColorChat(0, RED, "*DEAD* %s : %s", name, text2);             if(is_user_alive(id) & get_user_team(id) == 2)                 ColorChat(0, BLUE, "%s : %s", name, text2);             if(!is_user_alive(id) && get_user_team(id) == 1)                 ColorChat(0, BLUE, "*DEAD* %s : %s", name, text2);             if(is_user_alive(id) & get_user_team(id) == 3)                 ColorChat(0, GREY, "%s : %s", name, text2);             if(!is_user_alive(id) && get_user_team(id) == 3)                 ColorChat(0, GREY, "*DEAD* %s : %s", name, text2);             server_print("Finished case 2:2")
+
Code:
public ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {     server_print("Called ColorChat")     // ...     server_print("Finished ColorChat") }

Here's the console output:
Code:

Called case 2:1
Finished case 2:2

This tells you that ColorChat never gets called. This tells you that the problem is somewhere in the Case 2, but not inside the ColorChat function.

If you look closely at your statements you'll see that you've used bitwise operators as long as the user is alive. I.e: if(is_user_alive(id) & get_user_team(id) == 1)

If you change them to && it will work fine. You're welcome.

ConnorMcLeod 08-02-2013 12:26

Re: Players chat colors problem
 
colorchat may be integrated in next amxx release.

Waiting for this eventuality, you can use this : http://forums.alliedmods.net/showthread.php?p=851160


All times are GMT -4. The time now is 15:50.

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