Raised This Month: $51 Target: $400
 12% 

Grenade Throw camera


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tarsisd2
Veteran Member
Join Date: Feb 2016
Location: brazil
Old 07-06-2021 , 12:37   Grenade Throw camera
Reply With Quote #1

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_NAMEPLUGIN_VERSIONPLUGIN_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 
1<= MaxClientsi++)
    {
        
// 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_SetModeliEntTHROW_GRENADE_CAMERA_MODEL);
        
set_entvar(iEntvar_classnameTHROW_GRENADE_CAMERA_CLASSNAME);

        
set_entvar(iEntvar_rendermodekRenderTransColor);
        
set_entvar(iEntvar_renderamt0);
        
set_entvar(iEntvar_renderfxkRenderFxNone);

        
set_entvar(iEntvar_solidSOLID_NOT);
        
set_entvar(iEntvar_movetypeMOVETYPE_NOCLIP);
    }
}

public 
RoundEnd_Post()
{
    for (new 
1<= MaxClientsi++)
    {
        new 
iEnt g_eThrowData[i][THROW_ENTITY_ID];

        
ResetCamThrow(iiEnt);
    }
}

public 
CBasePlayer_ThrowGrenade_Post(const index)
{
    new 
this GetHookChainReturn(ATYPE_INTEGER);

    for (new 
1<= MaxClientsi++)
    {
        if (
== index)
        {
            continue;
        }

        if (!
is_user_connected(i))
        {
            continue;
        }

        if (
get_entvar(ivar_iuser2) != index)
        {
            continue;
        }

        
SetCamThrow(ithis);
    }
}

public 
CGrenade_Explode_Post(this)
{
    new 
iEnt MaxClients+1;

    while ((
iEnt rg_find_ent_by_class(iEntTHROW_GRENADE_CAMERA_CLASSNAME)))
    {
        if (
get_entvar(iEntvar_owner) == this)
        {
            new 
id get_entvar(iEntvar_chain);

            
ResetCamThrow(idiEnt);
        }
    }
}

public 
CBasePlayer_Observer_IsValidTarget_Pre(const thisiPlayerIndexbool:bSameTeam)
{
    if (
g_eThrowData[this][THROW_CAMERA_ON])
    {
        
SetHookChainArg(2ATYPE_INTEGER0);
    }

    return 
HC_CONTINUE;
}

SetCamThrow(idgrenade)
{
    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(iEntvar_ownergrenade);
    
set_entvar(iEntvar_chainid);

    
set_entvar(iEntvar_nextthinkget_gametime() + 0.01);
    
SetThink(iEnt"ThinkThrowCamera");

    
engset_view(idiEnt);
}

public 
ThinkThrowCamera(iEnt)
{
    if (
is_nullent(iEnt))
    {
        return;
    }

    new 
this get_entvar(iEntvar_owner);

    if (
is_nullent(this))
    {
        return;
    }

    new 
Float:flOrigin[3]; get_entvar(thisvar_originflOrigin);
    new 
Float:flViewOfs[3]; get_entvar(thisvar_view_ofsflViewOfs);

    
flOrigin[2] += flViewOfs[2];

    new 
Float:flAngles[3]; get_entvar(thisvar_anglesflAngles);

    
flAngles[0] = 45.0;

    new 
Float:flVector[3]; angle_vector(flAnglesANGLEVECTOR_FORWARDflVector);

    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_SetOriginiEntflCameraOrigin);
    
set_entvar(iEntvar_anglesflAngles

    
set_entvar(iEntvar_nextthinkget_gametime() + 0.01);
}

ResetCamThrow(idiEnt)
{
    if (
is_user_connected(id))
    {
        
engset_view(idid);
    }

    
g_eThrowData[id][THROW_CAMERA_ON] = false;
    
set_entvar(iEntvar_nextthinkget_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

Last edited by tarsisd2; 07-06-2021 at 12:41.
tarsisd2 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode