#include <sourcemod>
#include <sdktools>
#include <cstrike>
new Handle:hTimer[MAXPLAYERS+1] = INVALID_HANDLE,
Handle:g_hTime = INVALID_HANDLE,
Handle:hTime = INVALID_HANDLE;
new bool:g_hRespawnPlayer;
new g_hSec;
public OnPluginStart()
{
g_hTime = CreateConVar("sm_warmup_time", "25", "Укажите время разминки");
HookEvent("round_start", Event_OnRoundStart);
HookEvent("player_spawn", Event_OnPlayerSpawn);
HookEvent("flashbang_detonate", Event_OnFlashBangDetonate);
HookEvent("player_death", Event_OnPlayerDeath);
HookEvent("round_end", Event_OnRoundEnd);
}
public OnMapStart()
{
FunctionKillTimer();
g_hRespawnPlayer = false;
}
public OnClientDisconnect(client)
{
if (hTimer[client] != INVALID_HANDLE)
{
KillTimer(hTimer[client]);
hTimer[client] = INVALID_HANDLE;
}
}
public Event_OnRoundStart(Handle:timer, const String:name[], bool:silent)
{
FunctionKillTimer();
if (!g_hRespawnPlayer)
{
g_hSec = GetConVarInt(g_hTime) + 1;
ServerCommand("mp_ignore_round_win_conditions 1;sv_ignoregrenaderadio 1");
hTime = CreateTimer(1.0, Time, _, TIMER_REPEAT);
}
}
public Event_OnPlayerSpawn(Handle:event, const String:name[], bool:silent)
{
if (!g_hRespawnPlayer)
{
// Удаление оружия взято с https://forums.alliedmods.net/showthread.php?p=1681812
new client = GetClientOfUserId(GetEventInt(event, "userid")),
weapon;
for (new i = 0; i <= 5; i++)
{
if ((weapon = GetPlayerWeaponSlot(client, i)) != -1)
{
RemovePlayerItem(client, weapon);
}
}
SetEntityHealth(client, 1);
GivePlayerItem(client, "weapon_flashbang");
}
}
public Event_OnFlashBangDetonate(Handle:event, const String:name[], bool:silent)
{
if (!g_hRespawnPlayer)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"))
if (client > 0 && IsPlayerAlive(client))
{
GivePlayerItem(client, "weapon_flashbang");
}
}
}
public Event_OnPlayerDeath(Handle:event, const String:name[], bool:silent)
{
if (!g_hRespawnPlayer)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
hTimer[client] = CreateTimer(1.0, Timer, client, TIMER_FLAG_NO_MAPCHANGE);
}
}
public Event_OnRoundEnd(Handle:timer, const String:name[], bool:silent)
{
FunctionKillTimer();
}
public Action:Timer(Handle:timer, any:client)
{
if (!g_hRespawnPlayer)
{
if (GetClientTeam(client) > 1 && !IsPlayerAlive(client))
{
CS_RespawnPlayer(client);
}
}
hTimer[client] = INVALID_HANDLE;
}
public Action:Time(Handle:timer)
{
if (!g_hRespawnPlayer)
{
if (g_hSec > 0)
{
PrintCenterTextAll("Разминка закончится через: %d", --g_hSec);
}
else
{
FunctionKillTimer()
g_hRespawnPlayer = true;
ServerCommand("mp_ignore_round_win_conditions 0;sv_ignoregrenaderadio 0");
CS_TerminateRound(5.0, CSRoundEndReason:9);
PrintCenterTextAll("Разминка завершена!");
}
}
hTime = INVALID_HANDLE;
}
stock FunctionKillTimer()
{
if (hTime != INVALID_HANDLE)
{
KillTimer(hTime);
hTime = INVALID_HANDLE;
}
}