AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Problem with Putting Recoil on Glock (https://forums.alliedmods.net/showthread.php?t=299126)

hellmonja 07-03-2017 23:25

[HELP] Problem with Putting Recoil on Glock
 
I thought putting some recoil (camera shake) on the Glock was simple enough. And it actually works. But when I switch to burst mode I get bullet holes directly above me. Not sure why it's doing that. =/

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

new cvar_glock_recoil;
new const 
glock_model[]  = "models/v_glock18.mdl";

public 
plugin_init()
{
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_glock18""Fw_Weapon_PrimaryAttack_Post"1);
    
cvar_glock_recoil register_cvar("glock_recoil""1.1");
}

public 
Fw_Weapon_PrimaryAttack_Post(weapon)
{
    static 
idmodel[32];
    
id pev(weaponpev_owner);
    
pev(idpev_viewmodel2model31);
    
    if(!
equali(modelglock_model))
        return 
HAM_IGNORED
    
    
if(!cs_get_weapon_ammo(weapon))
        return 
HAM_IGNORED
    
    set_pev
(idpev_punchangleget_pcvar_float(cvar_glock_recoil));
    
    return 
HAM_IGNORED



CrazY. 07-04-2017 00:17

Re: [HELP] Problem with Putting Recoil on Glock
 
I've never witnessed Ham_PrimaryAttack written in this way...

Use this.
Code:
public fw_PrimaryAttack_Post(entity) {     if (!pev_valid(entity))        return;     new id = get_pdata_cbase(entity, 41, 4)     if (!is_user_alive(id))       return;        set_pev(id, pev_punchangle, get_pcvar_float(cvar_glock_recoil)); }

Returning values in a forward-type post will not result in anything, so I guess you don't need it.

Another observation, if you want to block the attack if the weapon does not have ammunition, you must register ham attack again but pre (0), run the Ammo check and return HAM_SUPERCEDE if the value is less than 1.

hellmonja 07-04-2017 06:20

Re: [HELP] Problem with Putting Recoil on Glock
 
Hey Crazy.! Thanks for the reply. I did what you said but now some of the bullet holes are scattered behind me. I must've made a mistake but I can't find it. Here's what I did:
PHP Code:

#define m_pPlayer 41
...
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_glock18""Fw_PrimaryAttack_Pre");
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_glock18""Fw_PrimaryAttack_Post"1);
...
public 
Fw_PrimaryAttack_Pre(weapon_ent)
{
    if(!
cs_get_weapon_ammo(weapon_ent))
        return 
HAM_SUPERCEDE
    
    
return HAM_IGNORED
}

public 
Fw_PrimaryAttack_Post(weapon_ent)
{
    if (!
pev_valid(weapon_ent))
        return;
    
    new 
id get_pdata_cbase(weapon_entm_pPlayer4)
    
    if (!
is_user_alive(id))
        return;
    
    
set_pev(idpev_punchangleget_pcvar_float(cvar_glock_recoil));


Also, I see this code all the time:
PHP Code:

pev_valid 

But never knew what it is for. The API says it Checks the validity of an entity. But validity for what?....

HamletEagle 07-04-2017 06:30

Re: [HELP] Problem with Putting Recoil on Glock
 
If entity really exists...

CrazY. 07-04-2017 13:27

Re: [HELP] Problem with Putting Recoil on Glock
 
It's the same of is_valid_ent of engine. As an Hamlet said, he check if this entity exists.

About the problem with bullet, I think you can try do this with xs (include).

hellmonja 07-04-2017 22:49

Re: [HELP] Problem with Putting Recoil on Glock
 
Okay, I'll try. But I'm not familiar with XS. I'll have to read up on it first. Thanks again!...

CrazY. 07-04-2017 22:59

Re: [HELP] Problem with Putting Recoil on Glock
 
I've seen many weapons using XS, maybe it's can help you, try to pick up some parts of the code.

https://forums.alliedmods.net/showthread.php?t=155583

SpannerSpammer 07-04-2017 23:54

Re: [HELP] Problem with Putting Recoil on Glock
 
Code:

set_pev(id, pev_punchangle, get_pcvar_float(cvar_glock_recoil));
:arrow:
Code:

new Float:vAngle[3];
vAngle[0] = get_pcvar_float(cvar_glock_recoil); // punch up/down (pitch)
vAngle[1] = 0.0; // punch left/right (yaw)
vAngle[2] = 0.0; // punch clockwise/anticlockwise (roll)
set_pev( id, pev_punchangle, vAngle );

Try putting some debug code in your functions to see exactly what is being executed.


All times are GMT -4. The time now is 23:09.

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