#include <sourcemod>
#include <cstrike>
#include <sdktools>

new RespawnTime = 15;
new Float:Position[MAXPLAYERS+1][3];

public Plugin:myinfo = 
{
	name = "AutoRespawn",
	author = "rainyt",
	version = "1.0"
};

public OnPluginStart()	
{
	HookEvent("round_start", Start);
	HookEvent("player_death", Death);
	HookEvent("player_spawn", Spawn);
}

public Action:Start(Handle:event, const String:name[], bool:dB)
{
	RespawnTime = 15;
	CreateTimer(5.0, Timer_Start);
}

public Action:Timer_Start(Handle:timer)	CreateTimer(1.0, Timer_Message, _, TIMER_REPEAT);

public Action:Timer_Message(Handle:timer)
{
	if(RespawnTime > 0)
	{
		for(new i = 1; i <= MaxClients; i++)
		{
			if(IsClientInGame(i) && GetClientTeam(i) > 1)
			{
				PrintHintText(i, "Автовоскрешение доступно ещё <font color='#CD5D17'><b>%d</b></font> секунд", RespawnTime);
			}
		}
		RespawnTime--;
	}
	else return Plugin_Stop;
	
	return Plugin_Continue;
}

public Action:Spawn(Handle:event, const String:name[], bool:dB)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	GetClientAbsOrigin(client, Position[client]);
	Position[client][2] += 75;
}

public Action:Death(Handle:event, const String:name[], bool:dB)
{
	if(RespawnTime > 0)
	{
		new client = GetClientOfUserId(GetEventInt(event, "userid"));
		CreateTimer(0.1, Timer_Respawn, any:client)
	}
}

public Action:Timer_Respawn(Handle:timer, any:client)
{
	CS_RespawnPlayer(client);
	TeleportEntity(client, Position[client], NULL_VECTOR, NULL_VECTOR);
}



