new Array:MessageCMD, Array:MessageAuto;
new message_cmd_load, msg_cmd[msg_cmd_enum], message_auto_load;
new cur_auto_msg_id, cur_auto_msg[192];
new pcvar_auto_type, pcvar_auto_random;
register_plugin("AD Manager", "1.0", "Nesquik");
pcvar_auto_type = register_cvar("ad_manager_auto_type", "0"); // 0 - показывать всем, 1 - показывать только мертвым, 2 - показывать только живым
pcvar_auto_random = register_cvar("ad_manager_auto_random", "0"); // 0 - сообщения идут по порядку, 1 - сообщения выбираются случайным образом
get_configsdir(filename, charsmax(filename));
add(filename, charsmax(filename), "/ad_manager.ini");
if (!file_exists(filename)) set_fail_state("ad_manager file not found");
MessageCMD = ArrayCreate(msg_cmd_enum);
MessageAuto = ArrayCreate(192, 1);
new hostname[64], contact[64], maxplayers[32], mapname[32], server_ip[25];
new file = fopen(filename, "rt");
if (!file) set_fail_state("ad_manager open error!");
get_cvar_string("hostname", hostname, charsmax(hostname));
get_mapname(mapname, charsmax(mapname));
formatex(maxplayers, charsmax(maxplayers), "%d", get_maxplayers());
get_user_ip(0, server_ip, charsmax(server_ip));
if (cvar_exists("sv_contact")) get_cvar_string("sv_contact", contact, charsmax(contact));
fgets(file, text, charsmax(text));
if (text[0] == ';' || !text[0]) continue;
strtok(text[1], msg_cmd[cmd_com], charsmax(msg_cmd[cmd_com]), msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), ' ');
strtolower(msg_cmd[cmd_com]);
format(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "^1%s", msg_cmd[cmd_msg]);
while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "!g", "^4")){}
while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "!t", "^3")){}
while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "!n", "^1")){}
if (containi(msg_cmd[cmd_msg], "#hostname#") != -1) while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "#hostname#", hostname)){}
if (containi(msg_cmd[cmd_msg], "#maxplayers#") != -1) while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "#maxplayers#", maxplayers)){}
if (containi(msg_cmd[cmd_msg], "#server_ip#") != -1) while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "#server_ip#", server_ip)){}
if (containi(msg_cmd[cmd_msg], "#mapname#") != -1) while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "#mapname#", mapname)){}
if (containi(msg_cmd[cmd_msg], "#contact#") != -1) while(replace(msg_cmd[cmd_msg], charsmax(msg_cmd[cmd_msg]), "#contact#", contact)){}
ArrayPushArray(MessageCMD, msg_cmd);
format(text, charsmax(text), "^1%s", text);
while(replace(text, charsmax(text), "!g", "^4")){}
while(replace(text, charsmax(text), "!t", "^3")){}
while(replace(text, charsmax(text), "!n", "^1")){}
if (containi(text, "#hostname#") != -1) while(replace(text, charsmax(text), "#hostname#", hostname)){}
if (containi(text, "#maxplayers#") != -1) while(replace(text, charsmax(text), "#maxplayers#", maxplayers)){}
if (containi(text, "#server_ip#") != -1) while(replace(text, charsmax(text), "#server_ip#", server_ip)){}
if (containi(text, "#mapname#") != -1) while(replace(text, charsmax(text), "#mapname#", mapname)){}
if (containi(text, "#contact#") != -1) while(replace(text, charsmax(text), "#contact#", contact)){}
if (strlen(text) > 191) text[191] = '^0';
ArrayPushString(MessageAuto, text);
if ((message_cmd_load = ArraySize(MessageCMD)) > 0)
register_clcmd("say", "fwd_hook_say");
register_clcmd("say_team", "fwd_hook_say");
if ((message_auto_load = ArraySize(MessageAuto)) > 0)
set_task(random_float(25.0, 45.0), "ShowAutoAD", TASK_ID, .flags = "b");
switch(get_pcvar_num(pcvar_auto_type))
case 1: get_players(players, count, "bch");
case 2: get_players(players, count, "ach");
default: get_players(players, count, "ch");
if (get_pcvar_num(pcvar_auto_random)) cur_auto_msg_id = random_num(0, message_auto_load - 1);
if (cur_auto_msg_id >= message_auto_load || cur_auto_msg_id < 0) cur_auto_msg_id = 0;
ArrayGetString(MessageAuto, cur_auto_msg_id, cur_auto_msg, charsmax(cur_auto_msg));
for( i = 0; i < count; i++ )
case 1..8: set_task(0.1, "ShowAutoMSG", player);
case 9..16: set_task(0.2, "ShowAutoMSG", player);
case 17..24: set_task(0.3, "ShowAutoMSG", player);
case 25..32: set_task(0.4, "ShowAutoMSG", player);
public ShowAutoMSG(player) Print_Color_Msg(player, cur_auto_msg);
read_args(msg, charsmax(msg));
for( new i = 0; i < message_cmd_load; i++ )
ArrayGetArray(MessageCMD, i, msg_cmd);
if (equal(msg, msg_cmd[cmd_com])) Print_Color_Msg(id, msg_cmd[cmd_msg]);
public Print_Color_Msg(id, msg[])
format(cur_msg, charsmax(cur_msg), msg);
replace_all_tags(id, cur_msg);
message_begin(MSG_ONE_UNRELIABLE, 76, .player = id);
public replace_all_tags(id, msg[])
static len, time; len = strlen(msg);
if (containi(msg, "#name#") != -1)
get_user_name(id, string, charsmax(string));
while(replace(msg, len, "#name#", string)){}
if (containi(msg, "#numplayers#") != -1)
format(string, charsmax(string), "%d", get_playersnum());
while(replace(msg, len, "#numplayers#", string)){}
if (containi(msg, "#timeleft#") != -1)
format(string, charsmax(string), "%d:%02d", time / 60, time % 60);
while(replace(msg, len, "#timeleft#", string)){}