I've looked into teame06's ColorChat snippet and tried to modify it so the color is cvar controlled, not by case:
Code:
#include <amxmodx>
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 cvar_num;
new cvar_string;
new cvar_test;
new TeamName[][] =
{
"",
"TERRORIST",
"CT",
"SPECTATOR"
}
new bool:IsConnected[33];
public plugin_init()
{
register_plugin("Cs Color Chat Function Test", "1.2", "teame06");
register_clcmd("say /test", "cmd_test")
cvar_test = register_cvar("test_color", "red")
cvar_num = register_cvar("test_num", "3")
cvar_string = register_cvar("test_string", "hello")
TeamInfo = get_user_msgid("TeamInfo");
SayText = get_user_msgid("SayText");
MaxSlots = get_maxplayers();
}
public cmd_test(id)
{
print_color(id, "DEBUG")
new string[32];
get_pcvar_string(cvar_string, string, 31)
print_color(id, "%s %d", string, get_pcvar_num(cvar_num))
}
public client_putinserver(id)
IsConnected[id] = true;
public client_disconnect(id)
IsConnected[id] = false;
public print_color(id, const msg[], any:...)
{
static message[256];
new colortype[32];
get_pcvar_string(cvar_test, colortype, 31)
if(equal(colortype, "yellow"))
message[0] = 0x01;
else if(equal(colortype, "green"))
message[0] = 0x04;
else
message[0] = 0x03;
vformat(message[1], 251, msg, 2);
// 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, colortype);
ShowColorMessage(index, MSG_Type, message);
if(ColorChange)
Team_Info(index, MSG_Type, TeamName[team]);
}
ShowColorMessage(id, type, message[])
{
message_begin(type, SayText, _, id);
write_byte(id)
write_string(message);
message_end();
}
Team_Info(id, type, team[])
{
message_begin(type, TeamInfo, _, id);
write_byte(id);
write_string(team);
message_end();
return 1;
}
ColorSelection(index, type, const colortype[])
{
if(equal(colortype, "red"))
return Team_Info(index, type, TeamName[1]);
if(equal(colortype, "blue"))
return Team_Info(index, type, TeamName[2]);
if(equal(colortype, "grey"))
return Team_Info(index, type, TeamName[0]);
return 0;
}
FindPlayer()
{
new i = -1;
while(i <= MaxSlots)
{
if(IsConnected[++i])
{
return i;
}
}
return -1;
}
print_color(id, "Hello") is working fine.
But print_color(id, "Hello %d", get_pcvar_num(number)) gives me "Hello 'the number as it should be only - 1'"
And print_color(id, "%s Hello %d", string, get_pcvar_num(number)) gives me wrong number, no string and is all bizarre