#include <amxmodx>
#include <fakemeta>
#include <reapi>
#include <rog>
#include <xs>
enum {
CVARS_FOR_PREPARE = 0,
CVARS_FOR_BATTLE,
};
new Array:g_aBombs;
new g_iBombSpawnPlace;
new Float:g_vecBombPlace[3];
public plugin_init()
{
register_plugin("RETAKE", "0.1", "@emmajule");
g_aBombs = ArrayCreate(1, 0);
collectEntites("info_bomb_target");
collectEntites("func_bomb_target");
if (ArraySize(g_aBombs) <= 0) {
server_print("[RETAKE] Map without bombplaces. Plugin paused!");
ArrayDestroy(g_aBombs);
pause("ad");
return;
}
RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound", false);
RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "CSGameRules_OnRoundFreezeEnd", true);
RegisterHookChain(RG_CSGameRules_GetPlayerSpawnSpot, "CSGameRules_GetPlayerSpawnSpot", false);
ROGInitialize(256.0);
}
public plugin_cfg()
{
set_cvar_float("mp_forcechasecam", 2.0);
set_cvar_float("mp_c4timer", 40.0);
set_cvar_float("mp_freezetime", 11.0);
set_cvar_float("mp_roundtime", 0.67);
set_cvar_num("mp_give_player_c4", 0);
set_cvar_num("mp_plant_c4_anywhere", 0);
set_cvar_float("mp_roundrespawn_time", -1.0);
}
public CSGameRules_RestartRound()
{
setCvars(CVARS_FOR_PREPARE);
new roundTerroristsWon;
if (roundTerroristsWon == -1 || get_member_game(m_bCompleteReset)) {
roundTerroristsWon = 0;
}
new WinStatus:status = get_member_game(m_iRoundWinStatus);
if (status == WINSTATUS_TERRORISTS)
{
if (++roundTerroristsWon >= 3) {
rg_swap_all_players();
roundTerroristsWon = 0;
}
}
else
{
roundTerroristsWon = 0;
if (status == WINSTATUS_CTS)
{
rg_swap_all_players();
}
}
new pistolRound = !random_num(0, 3);
for (new i = MaxClients; i > 0; --i)
{
if (!is_user_connected(i)) {
continue;
}
set_member(i, m_flDisplayHistory, get_member(i, m_flDisplayHistory) & ~CS_HINT_ROUND_STARTED);
set_member(i, m_bReceivesNoMoneyNextRound, true);
set_member(i, m_bNotKilled, false);
rg_add_account(i, pistolRound ? 800 : 10000, AS_SET, false);
}
RetriveChoosenBombplace(g_vecBombPlace);
ROGShuffleOrigins();
}
public CSGameRules_OnRoundFreezeEnd()
{
setCvars(CVARS_FOR_BATTLE);
rg_plant_bomb(0, g_vecBombPlace);
rg_send_audio(0, "%!MRAD_BOMBPL");
client_printex(0, print_center, "#Bomb_Planted");
return 0;
}
public CSGameRules_GetPlayerSpawnSpot(const id)
{
new Float:Origin[3], Float:fDist;
new TeamName:myTeam = get_member(id, m_iTeam);
new spawnSpots = ROGGetOriginsNum();
for (new i; i < spawnSpots; i++)
{
ROGGetOrigin(Origin);
fDist = xs_vec_distance_2d(Origin, g_vecBombPlace);
switch (myTeam)
{
case TEAM_TERRORIST:
{
if (fDist > 700) {
continue;
}
if (floatabs(Origin[2] - g_vecBombPlace[2]) > 400) {
continue;
}
}
case TEAM_CT:
{
if (!(2000 < fDist < 2600)) {
continue;
}
}
}
if (IsHullVacant(Origin, HULL_HUMAN) && !IsWrongPlace(Origin, id))
{
break;
}
}
set_entvar(id, var_origin, Origin);
set_entvar(id, var_angles, NULL_VECTOR);
set_entvar(id, var_velocity, NULL_VECTOR);
set_entvar(id, var_punchangle, NULL_VECTOR);
SetHookChainReturn(ATYPE_INTEGER, 0);
return HC_SUPERCEDE;
}
setCvars(const period)
{
switch (period)
{
case CVARS_FOR_PREPARE:
{
set_cvar_float("mp_buytime", -1.0);
set_cvar_num("mp_buy_anywhere", 1);
}
case CVARS_FOR_BATTLE:
{
set_cvar_float("mp_buytime", 0.0);
set_cvar_num("mp_buy_anywhere", 0);
}
}
}
collectEntites(const classname[])
{
new id = rg_find_ent_by_class(-1, classname, true);
while (id > 0)
{
ArrayPushCell(g_aBombs, id);
id = rg_find_ent_by_class(id, classname, true);
}
}
RetriveChoosenBombplace(Float:origin[3])
{
new size = ArraySize(g_aBombs);
if (++g_iBombSpawnPlace < size) {}
else {
g_iBombSpawnPlace = 0;
}
new bombplace = ArrayGetCell(g_aBombs, g_iBombSpawnPlace);
new Float:mins[3], Float:maxs[3];
get_entvar(bombplace, var_origin, origin);
get_entvar(bombplace, var_mins, mins);
get_entvar(bombplace, var_maxs, maxs);
for (new i; i < 3; i++) {
origin[i] += (mins[i] + maxs[i]) * 0.5;
}
}
bool:IsWrongPlace(Float:origin[3], const id)
{
origin[2] += 16.0;
for (new i = MaxClients; i > 0; --i)
{
if (i == id) {
continue;
}
if (!is_user_alive(i)) {
continue;
}
if (get_member(i, m_iTeam) == get_member(id, m_iTeam)) {
continue;
}
if (fm_is_visible(i, origin)) {
return true;
}
}
return false;
}
bool:IsHullVacant(Float:origin[3], hull)
{
new tracehandle;
engfunc(EngFunc_TraceHull, origin, origin, DONT_IGNORE_MONSTERS, hull, 0, tracehandle);
return get_tr2(tracehandle, TR_InOpen) && !(get_tr2(tracehandle, TR_StartSolid) || get_tr2(tracehandle, TR_AllSolid));
}