bro
Пользователь
- Регистрация
- 10 Июн 2017
- Сообщения
- 35
- Симпатии
- 1
- Пол
- Мужской
Код:
#include <amxmodx>
#include <reapi>
#define wp_cfg "addons/amxmodx/configs/cws/warmup.cfg"
#define mtch_cfg "addons/amxmodx/configs/cws/match.cfg"
#define ovt_cfg "addons/amxmodx/configs/cws/overtime.cfg"
#define max_pl_in_team 5 // количество игроков в команде
#define max_rounds 30 // максимум раундов в матче
#define ovt_rounds 3 // количество раундов в овертайме
#define round_wins 16 // количество побед одной команды
//#define force_match // Функция форсирования матча
//#define map_list
// Список карт для игры. Победитель матча выбирает следующую карту.
// А-ля "Играем 3 карты чтобы выяснить кто ты на самом деле" :D
// НЕ РАБОТАЕТ!
#define alive_listen_dead_players
// По дефолту живые не слышах мертвых при sv_alltalk 0
// Данный макрос "фиксит" этот косяк
enum _:MatchStates
{
bool:warmup,
bool:match,
bool:overtime,
bool:selectteam,
bool:blockchange,
matchend
}
new g_iTeamCaptain[any:TeamName],
bool:g_bTeamReady[any:TeamName];
new g_iMatchState[MatchStates];
new g_iRoundNum;
new g_iTeamScore[any:TeamName],
g_iSaveScore[any:TeamName];
new HookChain:g_Hook_GiveDefaultItems,
HookChain:g_Hook_RoundEnd,
HookChain:g_Hook_RoundStart;
#if defined force_match
new g_iNotFullTeam;
#endif
#if defined map_list
new Array:g_aMapList;
#endif
#if defined alive_listen_dead_players
#include <fakemeta>
#endif
#define GetTeam(%0) get_member(%0, m_iTeam)
public plugin_init()
{
register_plugin("Auto ClanWar System", "1.1", "neygomon");
register_clcmd("jointeam", "clcmdJoinTeam");
register_clcmd("say /tt", "clcmdSelectTeamTt");
register_clcmd("say /ct", "clcmdSelectTeamCt");
register_clcmd("say /captain", "clcmdCaptain");
register_clcmd("say /ready", "clcmdReady");
#if defined force_match
register_clcmd("say /forcematch", "clcmdForceMatch");
#endif
DisableHookChain((g_Hook_RoundStart = RegisterHookChain(RG_CSGameRules_RestartRound, "fwdRoundStart", false)));
DisableHookChain((g_Hook_RoundEnd = RegisterHookChain(RG_RoundEnd, "fwdRoundEnd", true)));
DisableHookChain((g_Hook_GiveDefaultItems = RegisterHookChain(RG_CBasePlayer_GiveDefaultItems, "fwd_GiveDefaultItems_Pre", false)));
#if defined alive_listen_dead_players
register_forward(FM_Voice_SetClientListening, "FwdSetClientListening", false);
#endif
#if defined map_list
register_clcmd("say /map", "SelectMap");
g_aMapList = ArrayCreate(32);
new fp = fopen("addons/amxmodx/configs/cws/maps.ini", "rt");
if(fp)
{
new buffer[32];
while(!feof(fp))
{
fgets(fp, buffer, charsmax(buffer));
trim(buffer);
if(!buffer[0] || buffer[0] == ';')
continue;
else if(is_map_valid(buffer))
ArrayPushString(g_aMapList, buffer);
}
fclose(fp);
}
#endif
}
#if defined force_match
#if AMXX_VERSION_NUM < 183
#define client_disconnected client_disconnect
#endif
public client_disconnected(id)
{
if(!g_iMatchState[warmup] && !g_iMatchState[match] && !g_iMatchState[overtime])
return;
new TeamName:team = GetTeam(id);
if(team != TEAM_TERRORIST && team != TEAM_CT)
return;
g_iMatchState[match] = false;
g_iNotFullTeam = team;
client_print(0, print_chat, "* Игрок из команды %s покинул сервер", team == TEAM_TERRORIST ? "террористов" : "контр-террористов");
new players[32], pnum;
get_players(players, pnum, "e", team == TEAM_TERRORIST ? "TERRORIST" : "CT");
for(new i; i < pnum; i++)
{
client_print(0, print_chat, "* Если игрок не будет участвовать и нет замены, напишите /forcematch");
client_print(0, print_chat, "* Если в течение минуты игрок не зайдет на сервер или не будет команды /forcematch");
client_print(0, print_chat, "* Вам будет засчитано Тех Поражение 16:0");
}
set_task(60.0, "StopMatch", 1224);
}
#endif
#if defined alive_listen_dead_players
public FwdSetClientListening(iReciever, iSender)
{
if(iReciever == iSender)
return FMRES_IGNORED;
if(GetTeam(iReciever) != GetTeam(iSender))
return FMRES_IGNORED;
if(is_user_alive(iReciever) == is_user_alive(iReciever))
return FMRES_IGNORED;
engfunc(EngFunc_SetClientListening, iReciever, iSender, false);
forward_return(FMV_CELL, false);
return FMRES_SUPERCEDE;
}
#endif
public fwdRoundStart()
{
if(g_iMatchState[warmup])
{
BuyZone_ToogleSolid(SOLID_NOT);
EnableHookChain(g_Hook_RoundEnd);
EnableHookChain(g_Hook_GiveDefaultItems);
g_iMatchState[matchend] = 0; // lol. почему тут? :D
client_print(0, print_chat, "* Разминочный раунд на ножах!");
client_print(0, print_chat, "* Победитель выбирает команду!");
client_print(0, print_chat, "* Удачи! ;)");
}
else if(g_iMatchState[selectteam])
{
new TeamName:team = g_iTeamScore[TEAM_TERRORIST] ? TEAM_TERRORIST : TEAM_CT;
client_print(g_iTeamCaptain[team], print_chat, "* Выберите команду");
client_print(g_iTeamCaptain[team], print_chat, "* Для этого напишите в чат");
client_print(g_iTeamCaptain[team], print_chat, "* /tt или /ct");
}
else if(g_iMatchState[match])
{
if(g_iRoundNum++ == max_rounds / 2)
{
g_iTeamScore[TEAM_TERRORIST] = g_iSaveScore[TEAM_CT];
g_iTeamScore[TEAM_CT] = g_iSaveScore[TEAM_TERRORIST];
}
if(g_iTeamScore[TEAM_TERRORIST] != g_iTeamScore[TEAM_CT])
client_print(0, print_chat,
"* Лидирует команда %s. Счет [TT %d] | [CT %d]",
g_iTeamScore[TEAM_TERRORIST] > g_iTeamScore[TEAM_CT] ? "террористов" : "контр-террористов",
g_iTeamScore[TEAM_TERRORIST], g_iTeamScore[TEAM_CT]
);
}
else if(g_iMatchState[matchend] > 0)
{
client_print(0, print_chat, "* Победила команда %s", g_iMatchState[matchend] == 1 ? "террористов" : "контр-террористов");
client_print(0, print_chat, "* Co счетом %d | %d", g_iTeamScore[TEAM_TERRORIST],g_iTeamScore[TEAM_CT]);
client_print(0, print_chat, "* Поздравляем!");
ExecCfg("server.cfg");
ClearData();
}
}
public fwdRoundEnd(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
g_iTeamScore[TEAM_TERRORIST] = get_member_game(m_iNumTerroristWins) + g_iSaveScore[TEAM_CT];
g_iTeamScore[TEAM_CT] = get_member_game(m_iNumCTWins) + g_iSaveScore[TEAM_TERRORIST];
if(g_iMatchState[warmup])
{
DisableHookChain(g_Hook_GiveDefaultItems);
BuyZone_ToogleSolid(SOLID_TRIGGER);
g_iMatchState[warmup] = false;
g_iMatchState[selectteam] = true;
}
else if(g_iRoundNum == max_rounds / 2)
{
client_print(0, print_chat, "* Смена команд!");
g_iSaveScore[TEAM_TERRORIST] = g_iTeamScore[TEAM_TERRORIST];
g_iSaveScore[TEAM_CT] = g_iTeamScore[TEAM_CT];
g_iMatchState[blockchange] = true;
ChangeTeam();
SV_Restart();
}
else if(g_iMatchState[overtime])
{
if(g_iRoundNum == ovt_rounds)
{
if(g_iTeamScore[TEAM_TERRORIST] > g_iTeamScore[TEAM_CT])
g_iMatchState[matchend] = 1, g_iMatchState[match] = false;
else if(g_iTeamScore[TEAM_CT] > g_iTeamScore[TEAM_TERRORIST])
g_iMatchState[matchend] = 2, g_iMatchState[match] = false;
}
}
else
{
if(g_iTeamScore[TEAM_TERRORIST] == round_wins)
g_iMatchState[matchend] = 1, g_iMatchState[match] = false;
else if(g_iTeamScore[TEAM_CT] == round_wins)
g_iMatchState[matchend] = 2, g_iMatchState[match] = false;
else if(g_iRoundNum == max_rounds)
{
client_print(0, print_chat, "* Обе команды набрали равное количество побед!");
client_print(0, print_chat, "* OverTime...!");
g_iSaveScore[TEAM_TERRORIST] = g_iTeamScore[TEAM_TERRORIST];
g_iSaveScore[TEAM_CT] = g_iTeamScore[TEAM_CT];
g_iMatchState[overtime] = true;
g_iRoundNum = 0;
ExecCfg(ovt_cfg);
ChangeTeam();
SV_Restart();
}
}
}
public clcmdCaptain(id)
{
new TeamName:team = GetTeam(id);
if(team != TEAM_TERRORIST && team != TEAM_CT)
return PLUGIN_HANDLED;
else if(g_iTeamCaptain[team])
{
client_print(id, print_chat, "* Капитан этой команды уже назначен!");
return PLUGIN_HANDLED;
}
else g_iTeamCaptain[team] = id;
client_print(id, print_chat, "* Как только Ваша команда будет готова, напишите /ready");
return PLUGIN_HANDLED;
}
public clcmdReady(id)
{
if(g_iMatchState[warmup] || g_iMatchState[match] || g_iMatchState[overtime] || g_iMatchState[matchend] > 0)
{
client_print(id, print_chat, "* Матч уже идет!");
return PLUGIN_HANDLED;
}
new TeamName:team = GetTeam(id);
if(g_iTeamCaptain[team] != id)
{
client_print(id, print_chat, "* Вы не являетесь капитаном команды!");
return PLUGIN_HANDLED;
}
if(g_bTeamReady[team])
{
client_print(id, print_chat, "* Вы уже предоставили информацию о готовности команды!");
return PLUGIN_HANDLED;
}
new players[32], pnum;
get_players(players, pnum, "e", team == TEAM_TERRORIST ? "TERRORIST" : "CT");
if(pnum != max_pl_in_team)
{
client_print(id, print_chat, "* Состав команды не соответсвует регламенту! Необходимо %d игроков!", max_pl_in_team);
return PLUGIN_HANDLED;
}
g_bTeamReady[team] = true;
client_print(0, print_chat, "* Команда %s к матчу готова!", team == TEAM_TERRORIST ? "террористов" : "контр-террористов");
if(g_bTeamReady[team] && g_bTeamReady[team == TEAM_TERRORIST ? TEAM_CT : TEAM_TERRORIST])
{
g_iMatchState[warmup] = true;
g_iRoundNum = 0;
EnableHookChain(g_Hook_RoundStart);
ExecCfg(wp_cfg);
SV_Restart();
}
return PLUGIN_HANDLED;
}
#if defined force_match
public clcmdForceMatch(id)
{
if(!g_iNotFullTeam)
return PLUGIN_HANDLED;
if(GetTeam(id) != g_iNotFullTeam)
return PLUGIN_HANDLED;
client_print(0, print_chat, "* Команда %s решила играть не в полном составе", g_iNotFullTeam == 1 ? "террористов" : "контр-террористов");
remove_task(1224);
g_iNotFullTeam = 0;
g_iMatchState[match] = true;
return PLUGIN_HANDLED;
}
#endif
public clcmdJoinTeam(id)
{
if(g_iMatchState[blockchange] || g_iMatchState[selectteam])
return PLUGIN_HANDLED;
if(!g_iMatchState[warmup])
return PLUGIN_CONTINUE;
#if defined force_match
new TeamName:team[2]; read_argv(1, team, charsmax(team));
if(g_iNotFullTeam != str_to_num(team))
return PLUGIN_CONTINUE;
client_print(0, print_chat, "* Команды укомплектованы полностью");
remove_task(1224);
g_iMatchState[match] = true;
#endif
return PLUGIN_CONTINUE;
}
public clcmdSelectTeamTt(id)
{
if(g_iMatchState[selectteam])
SelectTeam(id, TEAM_TERRORIST);
return PLUGIN_HANDLED;
}
public clcmdSelectTeamCt(id)
{
if(g_iMatchState[selectteam])
SelectTeam(id, TEAM_CT);
return PLUGIN_HANDLED;
}
public fwd_GiveDefaultItems_Pre(const id)
{
rg_remove_all_items(id);
set_member(id, m_bHasPrimary, 0);
rg_give_item(id, "weapon_knife");
return HC_SUPERCEDE;
}
#if defined map_list
public SelectMap(id)
{
new TeamName:team = GetTeam(id);
if(id != g_iTeamCaptain[team])
client_print(id, print_chat, "* Вы не капитан команды!");
else if(!g_iMatchState[matchend])
client_print(id, print_chat, "* Матч еще не закончился!");
else if(team == g_iMatchState[matchend])
client_print(id, print_chat, "* Ваша команда проиграла! Вы не можете выбирать карту!");
else
{
// Надо короче придумать код)))
}
return PLUGIN_HANDLED;
}
#endif
public SV_Restart()
server_cmd("sv_restart 1");
#if defined force_match
public StopMatch()
{
if(!g_iNotFullTeam)
return;
client_print(0, print_chat, "* Команда %s проиграла", g_iNotFullTeam == 1 ? "террористов" : "контр-террористов");
client_print(0, print_chat, "* Техническое поражение!");
ClearData();
}
#endif
ExecCfg(const cfg[])
{
server_cmd("exec %s", cfg);
server_exec();
}
ClearData()
{
g_iRoundNum = 0;
#if defined force_match
g_iNotFullTeam = 0;
#endif
arrayset(g_iMatchState, 0, MatchStates);
arrayset(g_bTeamReady, false, sizeof g_bTeamReady);
arrayset(g_iTeamCaptain,0, sizeof g_iTeamCaptain);
arrayset(g_iTeamScore, 0, sizeof g_iTeamScore);
arrayset(g_iSaveScore, 0, sizeof g_iSaveScore);
DisableHookChain(g_Hook_RoundStart);
DisableHookChain(g_Hook_RoundEnd);
DisableHookChain(g_Hook_GiveDefaultItems);
}
SelectTeam(id, TeamName:selectedTeam)
{
new TeamName:team = GetTeam(id);
if(g_iTeamCaptain[team] != id)
{
client_print(id, print_chat, "* Вы не являетесь капитаном команды!");
return;
}
else if((g_iTeamScore[TEAM_TERRORIST] && team != TEAM_TERRORIST) || (g_iTeamScore[TEAM_CT] && team != TEAM_CT))
return;
else if(selectedTeam != team)
ChangeTeam();
g_iMatchState[match] = true;
g_iMatchState[selectteam] = false;
g_iRoundNum = 0;
ExecCfg(mtch_cfg);
SV_Restart();
set_task(1.2, "SV_Restart", .flags="a", .repeat=2);
}
ChangeTeam()
{
new players[32], pnum;
get_players(players, pnum);
for(new i; i < pnum; i++)
{
switch(TeamName:GetTeam(players[i]))
{
case TEAM_TERRORIST: rg_set_user_team(players[i], TEAM_CT);
case TEAM_CT: rg_set_user_team(players[i], TEAM_TERRORIST);
}
}
}
stock BuyZone_ToogleSolid(const solid)
{
new entityIndex = 0;
while ((entityIndex = rg_find_ent_by_class(entityIndex, "func_buyzone")))
set_entvar(entityIndex, var_solid, solid);
}
L 09/21/2017 - 22:17:31: [AMXX] Displaying debug trace (plugin "auto_cw_system.amxx", version "1.1")
L 09/21/2017 - 22:17:31: [AMXX] Run time error 10: native error (native "get_member")
L 09/21/2017 - 22:17:31: [AMXX] [0] auto_cw_system.sma::FwdSetClientListening (line 130)
L 09/21/2017 - 22:17:31: [AMXX] Run time error 10: native error (native "get_member")
L 09/21/2017 - 22:17:31: [AMXX] [0] auto_cw_system.sma::FwdSetClientListening (line 130)