/*================================================================================

	-----------------------------------
	-*- [ZP] Respawn Command -*-
	-----------------------------------

	Say /respawn to respawn as a human when dead or spectating.
	Configurable cooldown.

================================================================================*/

#include <amxmodx>
#include <cstrike>
#include <zombie_plague_special>

#define PLUGIN_NAME		"[ZP] Respawn Command"
#define PLUGIN_VERSION	"1.0"
#define PLUGIN_AUTHOR	"Kimi Code"

new Float:g_last_respawn[33];
new cvar_cooldown;

public plugin_init() {
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
	register_clcmd("say /respawn", "cmd_respawn");
	register_clcmd("say_team /respawn", "cmd_respawn");

	cvar_cooldown = register_cvar("respawn_cooldown", "5.0");
}

public cmd_respawn(id) {
	if (!is_user_connected(id))
		return PLUGIN_CONTINUE;

	if (is_user_alive(id)) {
		client_print(id, print_chat, "[ZP] You can only respawn when dead.");
		return PLUGIN_HANDLED;
	}

	new Float:now = get_gametime();
	new Float:delay = get_pcvar_float(cvar_cooldown);
	if (now - g_last_respawn[id] < delay) {
		client_print(id, print_chat, "[ZP] Respawn cooldown: %.1f seconds remaining.", delay - (now - g_last_respawn[id]));
		return PLUGIN_HANDLED;
	}

	g_last_respawn[id] = now;

	// Make sure the player is on a team (spectators/joiners get CT/human)
	if (cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED)
		cs_set_user_team(id, CS_TEAM_CT);

	zp_respawn_user(id, ZP_TEAM_HUMAN);
	client_print(id, print_chat, "[ZP] You have been respawned.");

	return PLUGIN_HANDLED;
}
