Raised This Month: $ Target: $400
 0% 

[HELP] Problem with Putting Recoil on Glock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 07-03-2017 , 23:25   [HELP] Problem with Putting Recoil on Glock
Reply With Quote #1

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

__________________
hellmonja is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-04-2017 , 00:17   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #2

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.
__________________









Last edited by CrazY.; 07-04-2017 at 00:18.
CrazY. is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 07-04-2017 , 06:20   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #3

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?....
__________________
hellmonja is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-04-2017 , 06:30   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #4

If entity really exists...
__________________

Last edited by HamletEagle; 07-04-2017 at 06:31.
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-04-2017 , 13:27   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #5

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).
__________________









Last edited by CrazY.; 07-04-2017 at 13:29.
CrazY. is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 07-04-2017 , 22:49   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #6

Okay, I'll try. But I'm not familiar with XS. I'll have to read up on it first. Thanks again!...
__________________
hellmonja is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-04-2017 , 22:59   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #7

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
__________________








CrazY. is offline
SpannerSpammer
Member
Join Date: Mar 2006
Old 07-04-2017 , 23:54   Re: [HELP] Problem with Putting Recoil on Glock
Reply With Quote #8

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

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.
__________________
[NeoTF|DEV]SpannerSpammer-[AoE]-
NeoTF Development Team.
http://steamcommunity.com/groups/neotf
SpannerSpammer is offline
Reply


Thread Tools
Display Modes

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 23:09.


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