Raised This Month: $32 Target: $400
 8% 

[TUT] CS Semirecoil


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-23-2009 , 10:24   [TUT] CS Semirecoil
Reply With Quote #1

This is a problem that has been discused for some time here on amxx.
How to make a gun have semirecoil.

How do we do this?
Well we need 2 modules:
FakeMeta and HamSandWich

First we need to learn how to catch a weapon fire in HamSandWich.
We register first the normal forward becouse we want to get the punchangle before the shot.
We register the next forward as post becouse that is the moment when we can manipulate the punchangle (the recoil)
PHP Code:
// In plugin_init()
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_deagle""fw_primary_attack")
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_deagle""fw_primary_attack_post",1
In order to do this efficently we need 2 defines:
PHP Code:
// We use this bitsum to avoid using weapons that don't have recoil. (of course a nade doesn't have :P)
#define NO_RECOIL_WEAPONS_BITSUM  ( 1 << CSW_KNIFE | 1 << CSW_HEGRENADE | 1 << CSW_FLASHBANG | 1 << CSW_SMOKEGRENADE | 1 << CSW_C4 )
#define MAX_PLAYERS 32
// Here we store the punch angle before shot
new Float:cl_pushangle[MAX_PLAYERS 1][3
If you want to catch all the weapons it is not hard.
PHP Code:
    new weapon_name[24]
    
    for ( new 
1<= 30i+ ) 
    { 
        if (!(
NO_RECOIL_WEAPONS_BITSUM << i) && get_weaponname(iweapon_name23))
        { 
            
RegisterHamHam_Weapon_PrimaryAttackweapon_name"fw_primary_attack" )
            
RegisterHamHam_Weapon_PrimaryAttackweapon_name"fw_primary_attack_post")
        } 
    } 
We must remember that the forward will be called on the entities! Not on the players! So in order to get the player we need to find the entity owner.

PHP Code:
// The alive check is already done and the entity is valid 
public fw_primary_attack(ent)
{
    new 
id pev(ent,pev_owner)
    
// Save the punchangle before shot
    
pev(id,pev_punchangle,cl_pushangle[id])
    
    return 
HAM_IGNORED
}

public 
fw_primary_attack_post(ent)
{
    
// get the owner of the entity (player)
    
new id pev(ent,pev_owner)

    
// Here we can get the recoil or punchangle of the weapon fire
    
new Float:punch[3]
    
pev(id,pev_punchangle,punch)
    
punch[0] -= cl_pushangle[id][0]
    
punch[1] -= cl_pushangle[id][1]
    
punch[2] -= cl_pushangle[id][2]

    
// We print it to see the values in this case but this is the best place
    // where we can manipulate it
    
client_print(id,print_chat,"%0.2f , %0.2f, %0.2f",punch[0],punch[1],punch[2])
    
    return 
HAM_IGNORED

If we put it all together then we will have this:
PHP Code:
#define NO_RECOIL_WEAPONS_BITSUM  ( 1 << CSW_KNIFE | 1 << CSW_HEGRENADE | 1 << CSW_FLASHBANG | 1 << CSW_SMOKEGRENADE | 1 << CSW_C4 )
#define MAX_PLAYERS 32
// Here we store the punch angle before shot
new Float:cl_pushangle[MAX_PLAYERS 1][3]

public 
plugin_init()
{
    new 
weapon_name[24]
    
// Register all the weapons that we need
    
for ( new 1<= 30i++ ) 
    { 
        if (!(
NO_RECOIL_WEAPONS_BITSUM << i) && get_weaponname(iweapon_name23))
        { 
            
RegisterHamHam_Weapon_PrimaryAttackweapon_name"fw_primary_attack" )
            
RegisterHamHam_Weapon_PrimaryAttackweapon_name"fw_primary_attack_post")
        } 
    }
}

// The alive check is already done and the entity is valid 
public fw_primary_attack(ent)
{
    new 
id pev(ent,pev_owner)
    
// Save the punchangle before shot
    
pev(id,pev_punchangle,cl_pushangle[id])
    
    return 
HAM_IGNORED
}

public 
fw_primary_attack_post(ent)
{
    
// get the owner of the entity (player)
    
new id pev(ent,pev_owner)

    
// Here we can get the recoil or punchangle of the weapon fire
    
new Float:punch[3]
    
pev(id,pev_punchangle,punch)
    
punch[0] -= cl_pushangle[id][0]
    
punch[1] -= cl_pushangle[id][1]
    
punch[2] -= cl_pushangle[id][2]

    
// We print it to see the values in this case but this is the best place
    // where we can manipulate it
    
client_print(id,print_chat,"%0.2f , %0.2f, %0.2f",punch[0],punch[1],punch[2])
    
    return 
HAM_IGNORED

My plugin based on this tutorial: Recoil Control

And that's all! Hope that you guys find it usefull!
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 10-12-2009 at 20:14. Reason: Updated!
ot_207 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-23-2009 , 11:06   Re: [TUT] CS Semirecoil
Reply With Quote #2

About the second code, you should avoid to create var into a loop, also you can directly check get_user_weaponame(), it will return the weapon name length and 0 if weapon not found. I should be :

Code:
    new weapon_name[24];         for (new i=1;i<=30;i++)     {         // We get the weapon_name in our string, using the id of the weapon which is i that is why it starts from 1 and goes till 30         // We check if we have a valid weapon         if ( get_weaponname(i, weapon_name, 23) )         {             // We register the weapon's primary attack             RegisterHam(Ham_Weapon_PrimaryAttack, weapon_name, "fw_primary_attack_post",1)         }     }

About the third code, I think that pev_valid is useless, and is_user_alive() too in such forward. Also, Instead ot checking weapon which don't have recoil each time, just don't register theses weapons in the second code. Something like if i'm right :

Code:
    #define NO_RECOIL_WEAPONS_BITSUM  ( 1 << CSW_KNIFE | 1 << CSW_HEGRENADE | 1 << CSW_FLASHBANG | 1 << CSW_SMOKEGRENADE | 1 << CSW_C4 )         new weapon_name[24];         for ( new i = 1; i <= 30; i+ )     {         if ( !( NO_RECOIL_WEAPONS_BITSUM & 1 << i ) && get_weaponname( i, weapon_name, 23 ) )         {             RegisterHam( Ham_Weapon_PrimaryAttack, weapon_name, "fw_primary_attack_post", 1 );         }     }

Something like that, should be enough :

Code:
public fw_primary_attack_post( ent ) {     new id = pev( ent, pev_owner );         new Float:punch[3];     pev( id, pev_punchangle, punch );         client_print(id,print_chat, "%0.2f , %0.2f, %0.2f", punch[0], punch[1], punch[2] ) }

Last edited by Arkshine; 03-23-2009 at 11:14.
Arkshine is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-23-2009 , 11:09   Re: [TUT] CS Semirecoil
Reply With Quote #3

Quote:
Originally Posted by arkshine View Post
About the second code, you should avoid to create var into a loop, also you can directly check get_user_weaponame(), it will return the weapon name length and 0 if weapon not found. I should be :

Code:
    new weapon_name[24];         for (new i=1;i<=30;i++)     {         // We get the weapon_name in our string, using the id of the weapon which is i that is why it starts from 1 and goes till 30         // We check if we have a valid weapon         if ( get_weaponname(i, weapon_name, 23) )         {             // We register the weapon's primary attack             RegisterHam(Ham_Weapon_PrimaryAttack, weapon_name, "fw_primary_attack_post",1)         }     }

About the third code, I think that pev_valid is useless, and is_user_alive() too in such forward. Also, Instead ot checking weapon which don't have recoil each time, just don't register theses weapons in the second code.
Ok will update these days. I will be a little bit busy.
And I will add another thing to the tutorial that will make get the true recoil of the weapon. This method can produse small false pozitives
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-25-2009 , 19:32   Re: [TUT] CS Semirecoil
Reply With Quote #4

Updated the tutorial hope that everything is better now.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 03-29-2009 , 13:45   Re: [TUT] CS Semirecoil
Reply With Quote #5

Nice, nice!
__________________

anakin_cstrike is offline
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 03-29-2009 , 13:52   Re: [TUT] CS Semirecoil
Reply With Quote #6

good tutorial
__________________
alan_el_more is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-31-2009 , 14:16   Re: [TUT] CS Semirecoil
Reply With Quote #7

Updated some parts of the tutorial. There were some errors ...
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 04-01-2009 , 11:13   Re: [TUT] CS Semirecoil
Reply With Quote #8

Great, now we can go pwn noobs with da TMP!

On a side-note: it seems that, except for shotguns and deagle's, there is no client-side prediction of weapon's recoil (unlike CSS). This means if you have a ping greater than 0, you'll be seeing a delayed/incorrect recoil pattern when you shoot! And that explains the incredible amount of BS you get when spraying around...
__________________
MeRcyLeZZ is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 04-01-2009 , 12:23   Re: [TUT] CS Semirecoil
Reply With Quote #9

Quote:
Originally Posted by MeRcyLeZZ View Post
Great, now we can go pwn noobs with da TMP!


Quote:
Originally Posted by MeRcyLeZZ View Post
On a side-note: it seems that, except for shotguns and deagle's, there is no client-side prediction of weapon's recoil (unlike CSS). This means if you have a ping greater than 0, you'll be seeing a delayed/incorrect recoil pattern when you shoot! And that explains the incredible amount of BS you get when spraying around...
Unfortunately that is the only problem...
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Old 04-01-2009, 17:28
MeRcyLeZZ
This message has been deleted by MeRcyLeZZ. Reason: useless
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 09-26-2009 , 10:07   Re: [TUT] CS Semirecoil
Reply With Quote #10

PHP Code:
for(new 1<= 30i+) 


PHP Code:
for(new 1<= 30i++) 
__________________
alan_el_more 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 08:49.


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