#pragma semicolon 1
#include <cstrike>
#include <csgo_colors>
#include <sdktools_functions>
new Handle:Respawn_Timer,
Handle:RespawnTime,
bool:bAntiReconnect[MAXPLAYERS + 1];
public OnPluginStart()
{
RespawnTime = CreateConVar("minigame_time", "300", "Respawn time");
HookEvent("round_start", Round_Start, EventHookMode_PostNoCopy);
HookEvent("round_end", Round_End, EventHookMode_PostNoCopy);
HookEvent("player_death", Player_Death);
HookEventEx("player_spawn", Event_PlayerSpawn, EventHookMode_Pre);
}
public Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
if (Respawn_Timer != INVALID_HANDLE) KillTimer(Respawn_Timer);
Respawn_Timer = CreateTimer(float(GetConVarInt(RespawnTime)), StopTimer);
new Var_Sec = GetConVarInt(RespawnTime);
CGOPrintToChatAll("{RED}[MiniGame]: {GREEN}Если в умрёте в течении %i сек, вы будете возрождены!", Var_Sec);
}
public Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (Respawn_Timer != INVALID_HANDLE && !bAntiReconnect[client]) CreateTimer(1.0, TimerRespawn, client);
}
public Round_End(Handle:event, const String:name[], bool:dontBroadcast)
{
Reset_Variable();
if (Respawn_Timer != INVALID_HANDLE)
{
KillTimer(Respawn_Timer);
Respawn_Timer = INVALID_HANDLE;
}
}
public Action:StopTimer(Handle:timer)
{
Respawn_Timer = INVALID_HANDLE;
}
public Action:TimerRespawn(Handle:timer, any:client)
{
if (IsClientInGame(client) && !IsPlayerAlive(client) && GetClientTeam(client) > 1)
{
CS_RespawnPlayer(client);
CGOPrintToChat(client, "{RED}[MiniGame]: {GREEN}Вы были возрождены!");
}
}
public OnClientDisconnect(client) {
bAntiReconnect[client] = false;
}
stock Reset_Variable() {
for (new i = 1; i <= MaxClients; i++) bAntiReconnect[i] = false;
}
public OnMapEnd() {
Reset_Variable();
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (bAntiReconnect[client]) ForcePlayerSuicide(client);
}