#pragma compress 1
#pragma semicolon 1
#include <amxmodx>
#include <amxmisc>
stock const PLUGIN_NAME[] = "Demorecord";
stock const PLUGIN_VERSION[] = "1.0";
stock const PLUGIN_AUTHOR[] = "BiZaJe";
#define TASK_ID 6291
enum _:Cvar_List{
TEXT_CHAT,
Float:WAIT_START_DEMO,
MAX_DEMO,
DEMO_NAME[64]
};
new g_Cvar_List[Cvar_List], iDemo[MAX_PLAYERS + 1], szDemoName[64];
public plugin_init(){
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary("demorecord.txt");
bind_pcvar_num(
create_cvar("demo_text_chat", "1", FCVAR_NONE, "Выводить оповещение в чат о начале записи демо"),
g_Cvar_List[TEXT_CHAT]
);
bind_pcvar_float(
create_cvar("demo_start_time", "5.0", FCVAR_NONE, "Через сколько секунд начать запись демо после захода в игру"),
g_Cvar_List[WAIT_START_DEMO]
);
bind_pcvar_num(
create_cvar("demo_max", "3", FCVAR_NONE, "Максимальное количество записываемых демо игроку"),
g_Cvar_List[MAX_DEMO]
);
bind_pcvar_string(
create_cvar("demo_name", "%hostname%", FCVAR_NONE, "Название демо^n\
Так же можно использовать значения:^n\
%hostname% - Название сервера^n\
%ip% - Адрес сервера^n\
%port% - Порт сервера^n\
%mapname% - Название карты^n\
%num_demo% - Номер демо, принимает значения от 1-го до demo_max"),
g_Cvar_List[DEMO_NAME], charsmax(g_Cvar_List[DEMO_NAME])
);
}
public plugin_cfg(){
new cfgDir[32];
get_configsdir(cfgDir, charsmax(cfgDir));
server_cmd("exec %s/demorecord/demorecord.cfg", cfgDir);
}
public client_putinserver(iPlayer){
if(is_user_bot(iPlayer) || is_user_hltv(iPlayer)){
return;
}
if(g_Cvar_List[WAIT_START_DEMO] < 1.0){
set_task(1.0, "start_demo", iPlayer + TASK_ID);
return;
}
set_task(g_Cvar_List[WAIT_START_DEMO], "start_demo", iPlayer + TASK_ID);
}
public client_disconnected(iPlayer){
if(task_exists(iPlayer + TASK_ID)){
remove_task(iPlayer + TASK_ID);
}
}
public start_demo(TaskID){
TaskID -= TASK_ID;
replace_demo_name(TaskID);
client_cmd(TaskID, "stop; record ^"%s^"", szDemoName);
new szTime[16], szDate[16];
get_time("%H:%M:%S", szTime, charsmax(szTime));
get_time("%d.%m.%Y", szDate, charsmax(szDate));
if(g_Cvar_List[TEXT_CHAT] > 0){
client_print_color(TaskID, print_team_default, "%L %L", TaskID, "CHAT_DEMO_PREFIX", TaskID, "START_DEMO", TaskID);
client_print_color(TaskID, print_team_default, "%L %L", TaskID, "CHAT_DEMO_PREFIX", TaskID, "START_DEMO2", szDemoName, szTime, szDate);
}
}
replace_demo_name(iPlayer){
copy(szDemoName, charsmax(szDemoName), g_Cvar_List[DEMO_NAME]);
replace_all(szDemoName, charsmax(szDemoName), " ", "_");
if(containi(szDemoName, "%hostname%") != -1){
new hostname[33];
get_user_name(0, hostname, charsmax(hostname));
replace(szDemoName, charsmax(szDemoName), "%hostname%", hostname);
}
if(containi(szDemoName, "%ip%") != -1){
new ip[MAX_IP_LENGTH];
get_user_ip(0, ip, charsmax(ip), 1);
replace(szDemoName, charsmax(szDemoName), "%ip%", ip);
}
if(containi(szDemoName, "%port%") != -1){
new port[MAX_IP_WITH_PORT_LENGTH], szIP[MAX_IP_LENGTH], szPORT[6];
get_user_ip(0, port, charsmax(port));
strtok(port, szIP, charsmax(szIP), szPORT, charsmax(szPORT), ':');
replace(szDemoName, charsmax(szDemoName), "%port%", szPORT);
}
if(containi(szDemoName, "%mapname%") != -1){
new mapname[33];
get_mapname(mapname, charsmax(mapname));
replace(szDemoName, charsmax(szDemoName), "%mapname%", mapname);
}
new szBuff[3];
get_user_info(iPlayer, "_demorecord", szBuff, charsmax(szBuff));
iDemo[iPlayer] = str_to_num(szBuff);
if(iDemo[iPlayer] >= g_Cvar_List[MAX_DEMO]){
iDemo[iPlayer] = 0;
}
iDemo[iPlayer]++;
client_cmd(iPlayer, "setinfo _demorecord %d", iDemo[iPlayer]);
if(containi(szDemoName, "%num_demo%") != -1){
replace(szDemoName, charsmax(szDemoName), "%num_demo%", szBuff);
}
}