Код:
#define HL_MAX_TEAMS 10
stock static teams[HL_MAX_TEAMS][16]
/* Returns team id. When length is greater then 0 then a name of team is set.
*/
stock hl_get_user_team(client, team[] = "", len = 0)
{
if(hl_get_user_spectator(client))
return 0
static Float: tdm; global_get(glb_teamplay, tdm)
if(tdm < 1.0) return 0
if(!len) len = 16
get_user_info(client, "model", team, len)
return __get_team_index(team)
}
/* Set player team by teamname.
*/
stock hl_set_user_team(client, const team[])
{
static Float: tdm; global_get(glb_teamplay, tdm)
if(tdm < 1.0) return 0
static teamid; teamid = __get_team_index(team)
if(teamid == -1) return 0
hl_set_user_spectator(client, false)
engfunc(EngFunc_SetClientKeyValue, client, engfunc(EngFunc_GetInfoKeyBuffer, client), "model", team)
engfunc(EngFunc_SetClientKeyValue, client, engfunc(EngFunc_GetInfoKeyBuffer, client), "team", team)
static TeamInfo
if(TeamInfo || (TeamInfo = get_user_msgid("TeamInfo")))
{
message_begin(MSG_ALL, TeamInfo)
write_byte(client)
write_string(team)
message_end()
}
static ScoreInfo
if(ScoreInfo || (ScoreInfo = get_user_msgid("ScoreInfo")))
{
message_begin(MSG_ALL, ScoreInfo)
write_byte(client)
write_short(get_user_frags(client))
write_short(hl_get_user_deaths(client))
write_short(0)
write_short(teamid)
message_end()
}
return 1
}
stock __get_team_index(const team[])
{
static teamid; teamid = 0
static valid; valid = 0
static i; i = 0
__count_teams()
for(i = 0 ; i < sizeof teams; i++)
{
teamid++
if(equali(teams[i][0], team))
{
valid = 1
break
}
}
if(valid)
return teamid
return 0
}
stock __count_teams()
{
if(!teams[0][0])
{
new teamlist[50]
get_pcvar_string(get_cvar_pointer("mp_teamlist"), teamlist, charsmax(teamlist)); trim(teamlist)
__explode_teamlist(teams, charsmax(teams[]), teamlist, ';')
}
static teamcount
if(!teamcount)
{
for(new i = 0; i < sizeof teams; i++)
{
if(teams[i][0])
teamcount++
}
}
return teamcount
}
stock __explode_teamlist(output[][], size, input[], delimiter)
{
new nIdx = 0, l = strlen(input)
new nLen = (1 + copyc(output[nIdx], size, input, delimiter ))
while( (nLen < l) && (++nIdx < HL_MAX_TEAMS) )
nLen += (1 + copyc(output[nIdx], size, input[nLen], delimiter ))
}
Код:
#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", "1");
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) {
if(!get_pcvar_num(ColorMode))
return PLUGIN_CONTINUE;
static text2[200];
read_args(text2, 199);
remove_quotes(text2);
trim(text2);
new name[32];
get_user_name(id, name, 31);
if(equal(text2, ""))
return PLUGIN_HANDLED;
switch(get_pcvar_num(ColorMode)) {
case 1:
{
if(is_user_alive(id))
ColorChat(0, RED, "^x01%s : ^x03%s", name, text2);
else
ColorChat(0, RED, "^x01*DEAD* %s : ^x03%s", name, text2);
}
case 2:
{
if(is_user_alive(id))
ColorChat(0, GREEN, "^x01%s : ^x04%s", name, text2);
else
ColorChat(0, GREEN, "^x01*DEAD* %s : ^x04%s", name, text2);
}
case 3:
{
if(is_user_alive(id))
ColorChat(0, BLUE, "^x01%s : ^x03%s", name, text2);
else
ColorChat(0, BLUE, "^x01*DEAD* %s : ^x03%s", name, text2);
}
}
return PLUGIN_HANDLED;
}
public ColorChat(id, Color: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], 251, msg, 4);
// Make sure message is not longer than 192 character. Will crash the server.
message[192] = '^0';
new team, ColorChange, index, MSG_Type;
if(!id)
{
index = FindPlayer();
MSG_Type = MSG_ALL;
} else {
MSG_Type = MSG_ONE;
index = id;
}
team = get_user_team(index);
ColorChange = ColorSelection(index, MSG_Type, type);
ShowColorMessage(index, MSG_Type, message);
if(ColorChange)
{
Team_Info(index, MSG_Type, TeamName[team]);
}
}
ShowColorMessage(id, type, message[])
{
emessage_begin(type, SayText, _, id);
ewrite_byte(id)
ewrite_string(message);
emessage_end();
}
Team_Info(id, type, team[])
{
emessage_begin(type, TeamInfo, _, id);
ewrite_byte(id);
ewrite_string(team);
emessage_end();
return 1;
}
ColorSelection(index, type, Color:Type)
{
switch(Type)
{
case RED:
{
return Team_Info(index, type, TeamName[1]);
}
case BLUE:
{
return Team_Info(index, type, TeamName[2]);
}
case GREY:
{
return Team_Info(index, type, TeamName[0]);
}
}
return 0;
}
FindPlayer()
{
new i = -1;
while(i <= MaxSlots)
{
if(IsConnected[++i])
{
return i;
}
}
return -1;
}