#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "Ricochet Spectate"
#define VERSION "1.1"
new isSpectating[33]
new hEyes[33]
new Float:Origin[3], Float:vAngle[3], Float:Angles[3]
new hid
public plugin_init()
{
register_plugin(PLUGIN,VERSION,"Tony Angione")
register_clcmd("spec","spec_player",0,"[authid, nev vagy #jatekosid]")
register_forward(FM_PlayerPostThink, "PostThink")
register_forward(FM_AddToFullPack,"AddToFullPack")
}
public client_connect(id)
{
isSpectating[id] = 0
}
public client_disconnect(id)
{
if (isSpectating[id])
{
stop_spectating(id)
}
}
public plugin_precache()
{
precache_model("models/rpgrocket.mdl")
}
public spec_player(id,level,cid)
{
if (!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
new numbargs = read_argc()
if (numbargs == 1 && isSpectating[id])
{
stop_spectating(id)
}
else if (numbargs == 2)
{
if (isSpectating[id])
{
stop_spectating(id)
}
new arg[32]
read_argv(1,arg,31)
hid = cmd_target(id,arg,0)
if (!hid)
return PLUGIN_HANDLED
console_print(id, "[RS] A nezobol kiallashoz ird be ujra a parancsot, paramterek nelkul.")
start_spectating(id, hid)
}
else
{
console_print(id, "[RS] Hasznalat: spec [authid, nev vagy #jatekosid]")
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public start_spectating(id, hid)
{
hEyes[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
set_pev(hEyes[id],pev_classname,"spec_eyes")
engfunc(EngFunc_SetModel,hEyes[id],"models/rpgrocket.mdl")
set_pev(hEyes[id],pev_movetype,MOVETYPE_NOCLIP)
engfunc(EngFunc_SetSize,hEyes[id],Float:{0.0, 0.0, 0.0}, Float:{0.0, 0.0, 0.0})
set_pev(hEyes[id],pev_solid,SOLID_NOT)
set_pev(hEyes[id], pev_takedamage, 0.0)
set_pev(hEyes[id], pev_gravity, 0.0)
set_pev(hEyes[id],pev_owner,id)
set_pev(hEyes[id], pev_rendermode, kRenderTransColor)
set_pev(hEyes[id], pev_renderamt, 0.0)
set_pev(hEyes[id], pev_renderfx, kRenderFxNone)
dllfunc(DLLFunc_Think, hEyes[id])
engfunc(EngFunc_SetView, id, hEyes[id])
isSpectating[id] = hid
}
public stop_spectating(id)
{
engfunc(EngFunc_SetView, id, id)
engfunc(EngFunc_RemoveEntity, hEyes[id])
isSpectating[id] = 0
hEyes[id] = 0
}
public PostThink(id)
{
if (isSpectating[id])
{
pev(hid, pev_origin, Origin)
pev(hid, pev_v_angle, vAngle)
pev(hid, pev_angles, Angles)
Origin[2] += 28.0
vAngle[0] = (vAngle[0] * (0-1)) * 2
Angles[0] = (Angles[0] * (0-1)) * 2
set_pev(hEyes[id], pev_origin, Origin)
set_pev(hEyes[id], pev_v_angle, vAngle)
set_pev(hEyes[id], pev_angles, Angles)
return FMRES_HANDLED
}
return FMRES_IGNORED
}
public AddToFullPack(ent_state,e,edict_t_ent,host,hostflags,player,pSet)
{
if (is_user_connected(e) && is_user_connected(host))
{
if(is_user_alive(host) && isSpectating[host])
{
console_print(host, "[RS] Ujra eledrel, a nezesnek vege.")
stop_spectating(host)
}
else if (isSpectating[host] == e)
{
set_pev(e, pev_rendermode, 1)
return FMRES_HANDLED
}
else
{
set_pev(e, pev_rendermode, 0)
return FMRES_HANDLED
}
}
return FMRES_IGNORED
}