hi, i have a request if you mighty guys can help me out, i have this plugin that when a grenade is thrown the spectator can see where the grenade is going as if it had a camera following, like csgo go, so i want to change it so i can use it to practice grenades throws on the maps
i want it that when i throw the grenade i see the grenade camera view, not just the spectator, it would be cool if i could toggle this option on and off, like grenadeon, grenadeoff on say, is this too hard to modify?
heres the code:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#define PLUGIN_NAME "Throw grenade camera"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "Denzer"
new const THROW_GRENADE_CAMERA_MODEL[] = "models/rpgrocket.mdl";
new const THROW_GRENADE_CAMERA_CLASSNAME[] = "throw_grenade_camera";
enum _:ThrowData_s
{
THROW_ENTITY_ID,
bool:THROW_CAMERA_ON
};
new g_eThrowData[MAX_PLAYERS + 1][ThrowData_s];
public plugin_precache()
{
precache_model(THROW_GRENADE_CAMERA_MODEL);
}
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
RegisterHookChain(RG_RoundEnd, "RoundEnd_Post", true);
RegisterHookChain(RG_CBasePlayer_ThrowGrenade, "CBasePlayer_ThrowGrenade_Post", true);
RegisterHookChain(RG_CGrenade_ExplodeHeGrenade, "CGrenade_Explode_Post", true);
RegisterHookChain(RG_CGrenade_ExplodeFlashbang, "CGrenade_Explode_Post", true);
RegisterHookChain(RG_CGrenade_ExplodeSmokeGrenade, "CGrenade_Explode_Post", true);
RegisterHookChain(RG_CBasePlayer_Observer_IsValidTarget, "CBasePlayer_Observer_IsValidTarget_Pre", false);
CreateCams();
}
public client_putinserver(id)
{
g_eThrowData[id][THROW_CAMERA_ON] = false;
}
CreateCams()
{
for (new i = 1; i <= MaxClients; i++)
{
// https://github.com/alliedmodders/amxmodx/blob/9bcabfeb1f774439475313c30fb3fe256870268f/modules/engine/engine.cpp#L495-L515
new iEnt = g_eThrowData[i][THROW_ENTITY_ID] = rg_create_entity("info_target");
if (is_nullent(iEnt))
{
continue;
}
engfunc(EngFunc_SetModel, iEnt, THROW_GRENADE_CAMERA_MODEL);
set_entvar(iEnt, var_classname, THROW_GRENADE_CAMERA_CLASSNAME);
set_entvar(iEnt, var_rendermode, kRenderTransColor);
set_entvar(iEnt, var_renderamt, 0);
set_entvar(iEnt, var_renderfx, kRenderFxNone);
set_entvar(iEnt, var_solid, SOLID_NOT);
set_entvar(iEnt, var_movetype, MOVETYPE_NOCLIP);
}
}
public RoundEnd_Post()
{
for (new i = 1; i <= MaxClients; i++)
{
new iEnt = g_eThrowData[i][THROW_ENTITY_ID];
ResetCamThrow(i, iEnt);
}
}
public CBasePlayer_ThrowGrenade_Post(const index)
{
new this = GetHookChainReturn(ATYPE_INTEGER);
for (new i = 1; i <= MaxClients; i++)
{
if (i == index)
{
continue;
}
if (!is_user_connected(i))
{
continue;
}
if (get_entvar(i, var_iuser2) != index)
{
continue;
}
SetCamThrow(i, this);
}
}
public CGrenade_Explode_Post(this)
{
new iEnt = MaxClients+1;
while ((iEnt = rg_find_ent_by_class(iEnt, THROW_GRENADE_CAMERA_CLASSNAME)))
{
if (get_entvar(iEnt, var_owner) == this)
{
new id = get_entvar(iEnt, var_chain);
ResetCamThrow(id, iEnt);
}
}
}
public CBasePlayer_Observer_IsValidTarget_Pre(const this, iPlayerIndex, bool:bSameTeam)
{
if (g_eThrowData[this][THROW_CAMERA_ON])
{
SetHookChainArg(2, ATYPE_INTEGER, 0);
}
return HC_CONTINUE;
}
SetCamThrow(id, grenade)
{
if (g_eThrowData[id][THROW_CAMERA_ON])
{
return;
}
new iEnt = g_eThrowData[id][THROW_ENTITY_ID];
g_eThrowData[id][THROW_CAMERA_ON] = true;
set_entvar(iEnt, var_owner, grenade);
set_entvar(iEnt, var_chain, id);
set_entvar(iEnt, var_nextthink, get_gametime() + 0.01);
SetThink(iEnt, "ThinkThrowCamera");
engset_view(id, iEnt);
}
public ThinkThrowCamera(iEnt)
{
if (is_nullent(iEnt))
{
return;
}
new this = get_entvar(iEnt, var_owner);
if (is_nullent(this))
{
return;
}
new Float:flOrigin[3]; get_entvar(this, var_origin, flOrigin);
new Float:flViewOfs[3]; get_entvar(this, var_view_ofs, flViewOfs);
flOrigin[2] += flViewOfs[2];
new Float:flAngles[3]; get_entvar(this, var_angles, flAngles);
flAngles[0] = 45.0;
new Float:flVector[3]; angle_vector(flAngles, ANGLEVECTOR_FORWARD, flVector);
new Float:flCameraOrigin[3];
flCameraOrigin[0] = flOrigin[0] + (-flVector[0] * 100.0);
flCameraOrigin[1] = flOrigin[1] + (-flVector[1] * 100.0);
flCameraOrigin[2] = flOrigin[2] + (-flVector[2] * 100.0);
engfunc(EngFunc_SetOrigin, iEnt, flCameraOrigin);
set_entvar(iEnt, var_angles, flAngles)
set_entvar(iEnt, var_nextthink, get_gametime() + 0.01);
}
ResetCamThrow(id, iEnt)
{
if (is_user_connected(id))
{
engset_view(id, id);
}
g_eThrowData[id][THROW_CAMERA_ON] = false;
set_entvar(iEnt, var_nextthink, get_gametime());
SetThink(iEnt, "");
}
edit: it would be great if the grenade camera started as off on default, since it would be used only for practice
thanks very much