#pragma semicolon 1
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <reapi>
new const CORPSE_CLASSNAME[] = "ent_corpse";
new const Float:CORPSE_MINS[3] = { -24.0, -24.0, 0.0 };
new const Float:CORPSE_MAXS[3] = { 24.0, 24.0, 24.0 };
new g_iCorpse[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin("Revive Player", "1.0.0", "fl0wer");
register_message(get_user_msgid("ClCorpse"), "@MSG_ClCorpse");
RegisterHam(Ham_ObjectCaps, "info_target", "@CInfoTarget_ObjectCaps_Pre", false);
RegisterHookChain(RG_CBasePlayer_Spawn, "@CBasePlayer_Spawn_Post", true);
}
public client_disconnected(id)
{
Corpse_Remove(id);
}
@CBasePlayer_Spawn_Post(id)
{
Corpse_Remove(id);
}
@MSG_ClCorpse(id, dest, player)
{
new model[PLATFORM_MAX_PATH];
new Float:vecOrigin[3];
new Float:vecAngles[3];
get_msg_arg_string(1, model, charsmax(model));
format(model, charsmax(model), "models/player/%s/%s.mdl", model, model);
for (new i = 0; i < 3; i++)
{
vecOrigin[i] = float(get_msg_arg_int(2 + i)) / 128.0;
vecAngles[i] = get_msg_arg_float(5 + i);
}
new sequence = get_msg_arg_int(9);
new team = get_msg_arg_int(11);
new playerId = get_msg_arg_int(12);
Corpse_Create(model, vecOrigin, vecAngles, sequence, team, playerId);
return PLUGIN_HANDLED;
}
@CInfoTarget_ObjectCaps_Pre(id)
{
if (!FClassnameIs(id, CORPSE_CLASSNAME))
return HAM_IGNORED;
SetHamReturnInteger(FCAP_ONOFF_USE);
return HAM_OVERRIDE;
}
Corpse_Create(model[], Float:vecOrigin[3], Float:vecAngles[3], sequence, team, owner)
{
new id = rg_create_entity("info_target");
if (is_nullent(id))
return;
g_iCorpse[owner] = id;
engfunc(EngFunc_SetModel, id, model);
engfunc(EngFunc_SetSize, id, CORPSE_MINS, CORPSE_MAXS);
engfunc(EngFunc_SetOrigin, id, vecOrigin);
set_entvar(id, var_classname, CORPSE_CLASSNAME);
set_entvar(id, var_angles, vecAngles);
set_entvar(id, var_team, team);
set_entvar(id, var_owner, owner);
set_entvar(id, var_sequence, sequence);
set_entvar(id, var_framerate, 1.0);
set_entvar(id, var_animtime, 0.0);
SetUse(id, "@Corpse_Use");
}
Corpse_Remove(id)
{
new corpse = g_iCorpse[id];
g_iCorpse[id] = 0;
if (is_nullent(corpse))
return;
set_entvar(corpse, var_flags, FL_KILLME);
}
@Corpse_Use(id, activator, caller, USE_TYPE:useType, Float:value)
{
if (activator != caller)
return;
if (!ExecuteHam(Ham_IsPlayer, activator))
return;
if (get_member(activator, m_iTeam) != get_entvar(id, var_team))
return;
new owner = get_entvar(id, var_owner);
Corpse_Remove(owner);
rg_round_respawn(owner);
}