AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help me please with chat plugin (https://forums.alliedmods.net/showthread.php?t=204588)

alonelive 01-01-2013 07:28

Help me please with chat plugin
 
1 Attachment(s)
PHP Code:

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

#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"
}


public 
plugin_init() {
    
register_plugin("Color Chat""1.03""MaTTe");
    
    
register_clcmd("say""hook_say");
    
register_clcmd("say_team""hook_team_say");
    
    
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) {


    static 
text2[200];
    
read_args(text2199);
    
remove_quotes(text2);
    
trim(text2);
    
    new 
name[32];
    
get_user_name(idname31);
    
    if(
equal(text2""))
        return 
PLUGIN_HANDLED;
        
    if(
cs_get_user_team(id) == CS_TEAM_T) {
    
        if(
is_user_alive(id)) {        
        
ColorChat(0RED"^x01[^x03 TR ^x01] ^x03%s^x01: %s"nametext2)
        }
        
        else if((
is_user_alive(id) == 0)) {
        
ColorChat(0RED"^x01[^x03 TR ^x01] [^x03 DEAD ^x01] ^x03%s^x01: %s"nametext2)
        }
    }

    
    if(
cs_get_user_team(id) == CS_TEAM_CT) {
    
        if(
is_user_alive(id)) {        
        
ColorChat(0BLUE"^x01[^x03 CT ^x01] ^x03%s^x01: %s"nametext2)
        }
        
        else if((
is_user_alive(id) == 0)) {
        
ColorChat(0BLUE"^x01[^x03 CT ^x01] [^x03 DEAD ^x01] ^x03%s^x01: %s"nametext2)
        }
    }
    
        
    if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR || CS_TEAM_UNASSIGNED) {
        
ColorChat(0GREY"^x01[^x03 SP ^x01] ^x03%s^x01: %s"nametext2);
    }
  
    return 
PLUGIN_HANDLED;
}

public 
hook_team_say(id) {
        
    static 
text2[200];
    
read_args(text2199);
    
remove_quotes(text2);
    
trim(text2);
    
    new 
name[32];
    
get_user_name(idname31);
        
    new 
players[32], inum
    get_players
(playersinum)
    
    for (new 
0inum; ++i) {
        
    if(
equal(text2""))
        return 
PLUGIN_HANDLED;
        
    if(
cs_get_user_team(id) == CS_TEAM_T) {
    
        if(
is_user_alive(id) && players[i] != id) {        
        
ColorChat(idRED"^x01[^x03 TERRRORIST ^x01] ^x03%s^x01: %s"nametext2)
        }
        
        else if(
is_user_alive(id) == && players[i] != id) {
        
ColorChat(idRED"^x01[^x03 TERRRORIST ^x01] [^x03 DEAD ^x01] ^x03%s^x01: %s"nametext2)
        }
    }

    
    if(
cs_get_user_team(id) == CS_TEAM_CT) {
    
        if(
is_user_alive(id) && players[i] != id) {        
        
ColorChat(idBLUE"^x01[^x03 COUNTER-TERRRORIST ^x01] ^x03%s^x01: %s"nametext2)
        }
        
        else if(
is_user_alive(id) == && players[i] != id) {
        
ColorChat(idBLUE"^x01[^x03 COUNTER-TERRRORIST ^x01] [^x03 DEAD ^x01] ^x03%s^x01: %s"nametext2)
        }
    }

        
    if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR || CS_TEAM_UNASSIGNED) {
        if(
players[i] != id) {
        
ColorChat(idGREY"^x01[^x03 SPECTATOR ^x01] ^x03%s^x01: %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;


When i use team chat (key "U"), the message duplicated several times..
In future i want also add a logging functions for chat.

Team chat for CT and T does not work. I tried some ways to solve this function, but.. Not works CORRECTLY :(

ConnorMcLeod 01-01-2013 08:15

Re: Help me please with chat plugin
 
Because lot of times you put id instead of players[i].
Also, in normal say, you send chat to all players, but only alive players should receive chat from an alive player, and same for dead status.

What don't you use iChat plugin from Apple Kid ?

alonelive 01-01-2013 08:19

Re: Help me please with chat plugin
 
what i need:

say chat (from all T, CS, SPEC (dead or alive) to all)
say_team chat (only from dead/alive CT to dead/alive CT, from dead/alive T to dead/alive T and from SPEC to SPEC

iChat is too big construction. I need something simple. I shoult put id instead players[i] in ColorChat(...) ?

kNowo 01-01-2013 08:37

Re: Help me please with chat plugin
 
http://forums.alliedmods.net/showthread.php?p=571811

alonelive 01-01-2013 08:59

Re: Help me please with chat plugin
 
This is no way for this plugin, imho..

ConnorMcLeod 01-01-2013 09:00

Re: Help me please with chat plugin
 
Quote:

Originally Posted by kNowo (Post 1864724)

That one is not optimized at all, but can be used though.
I think iChat is better.

But you can try to fix your code, may be you prefer to understand and fix your mistakes and use your own code.

So for say your code is ok.
For say_team you have to send to players[i] and not to id (actually you still have to send once to id to sender knows he has sent something).

alonelive 01-01-2013 10:13

Re: Help me please with chat plugin
 
PHP Code:

public hook_team_say(id) {
        
    static 
text2[200];
    
read_args(text2199);
    
remove_quotes(text2);
    
trim(text2);
    
    new 
name[32];
    
get_user_name(idname31);
        
    if(
equal(text2""))
        return 
PLUGIN_HANDLED;
        
    if(
cs_get_user_team(id) == CS_TEAM_T) {
        
            new 
players[32], inum
            get_players
(playersinum)
    
            for (new 
0inum; ++i) {
                if(
cs_get_user_team(players[i]) == CS_TEAM_T) {        
                    
ColorChat(players[i], RED"^x01[^x03 TERRRORIST ^x01] ^x03%s^x01: %s"nametext2)
                }
            }
        
    }

    
    if(
cs_get_user_team(id) == CS_TEAM_CT) {
        
            new 
players[32], inum
            get_players
(playersinum)
    
            for (new 
0inum; ++i) {
                if(
cs_get_user_team(players[i]) == CS_TEAM_CT) {        
                    
ColorChat(players[i], BLUE"^x01[^x03 CT ^x01] ^x03%s^x01: %s"nametext2)
                }
            }
        
    }

        
    if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR || CS_TEAM_UNASSIGNED) {
        
            new 
players[32], inum
            get_players
(playersinum)
    
            for (new 
0inum; ++i) {
                if(
cs_get_user_team(players[i]) == CS_TEAM_CT || CS_TEAM_UNASSIGNED) {        
                    
ColorChat(players[i], GREY"^x01[^x03 CT ^x01] ^x03%s^x01: %s"nametext2)
                }
            }
        }
    return 
PLUGIN_HANDLED;


Is that true ?


All times are GMT -4. The time now is 13:27.

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