Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
new g_respawnCount = -1
new g_respawnIndex[5]
public plugin_init(){
register_plugin("AMX Respawn", "1.1", "whitemike")
register_clcmd("amx_respawn", "startRespawn", ADMIN_KICK, " <authid, nick, or #userid> - Respawn a player")
}
public startRespawn(id) {
if(!access(id, ADMIN_KICK)) {
console_print(id, "[AMXX] You have no access to this command")
return PLUGIN_HANDLED
}
new plrId[33]
read_argv(1, plrId, 32)
new plrIndex = cmd_target(id, plrId, 0)
if(!plrIndex) {
console_print(id, "[AMXX] Cannot find the specified player, try again")
return PLUGIN_HANDLED
}
else if(is_user_alive(plrIndex)) {
console_print(id, "[AMXX] That player is already alive, wait until they die")
return PLUGIN_HANDLED
}
for(new i=0; i<5; i++) {
if(g_respawnIndex[i] == plrIndex) {
console_print(id, "[AMXX] This player is already in queue for respawn")
return PLUGIN_HANDLED
}
}
if(g_respawnCount == 4) {
console_print(id, "[AMXX] There is too many players in the queue (5 max)")
return PLUGIN_HANDLED
}
g_respawnCount++
g_respawnIndex[g_respawnCount] = plrIndex
spawn(plrIndex)
set_task(0.5, "finishRespawn")
if(plrIndex != id) {
new adminName[33]
get_user_name(id, adminName, 32)
new clientName[33]
get_user_name(plrIndex, clientName, 32)
client_print(plrIndex, print_chat, "[AMXX] %s has granted you an extra life!", adminName)
console_print(id, "[AMXX] %s has been respawned successfully", clientName)
}
else {
client_print(id, print_chat, "[AMXX] You have been respawned.")
console_print(id, "[AMXX] You have been respawned.")
}
return PLUGIN_HANDLED
}
public finishRespawn() {
spawn(g_respawnIndex[g_respawnCount])
g_respawnIndex[g_respawnCount] = false
g_respawnCount--
return PLUGIN_HANDLED
}