AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   How to properly reset user speed ? (https://forums.alliedmods.net/showthread.php?t=136908)

Costin83 08-31-2010 11:25

How to properly reset user speed ?
 
I've just bumped into some old code that I had searched help for and since it was never finished I put a little time in it and came with a "beta version" that it's working well...

My problem is that I want to know if I did it right and if I can improve/strip the code or use less modules to achieve the same result. First problem I've bumped in it was that the player speed was not reset after using CS_SET_NO_ZOOM function on him... So I want to know if there is a better way to reset user speed to "unscoped" default weapon speed after using this func.

Code:

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

#define PLUGIN "UnZoom"
#define VERSION "0.1"
#define AUTHOR "Connor & 80T"

const m_pPlayer            = 41
const m_flNextPrimaryAttack    = 46
const m_flNextSecondaryAttack    = 47
const m_iClip            = 51
const m_iFOV            = 363

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    RegisterHam(Ham_Item_PostFrame, "weapon_scout", "Sniper_PostFrame")
    RegisterHam(Ham_Item_PostFrame, "weapon_awp", "Sniper_PostFrame")
}

public Sniper_PostFrame( iEnt )
{
    static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
    static iButton ; iButton = pev(id, pev_button)

    if(    (!(iButton & IN_ATTACK2) || get_pdata_float(iEnt, m_flNextSecondaryAttack, 4) > 0.0)
    &&    (iButton & IN_ATTACK)
    &&    get_pdata_int(iEnt, m_iClip, 4)
    &&    get_pdata_float(iEnt, m_flNextPrimaryAttack, 4) <= 0.0    )
    {
            if( get_pdata_int(id, m_iFOV, 5) < 90 )
        {
            cs_set_user_zoom( id , CS_SET_NO_ZOOM , 1 );

            new wclip, wammo
            switch(get_user_weapon(id,wclip,wammo))
            {
                case CSW_AWP:
                    set_user_maxspeed(id , 210.0);

                case CSW_SCOUT:
                    set_user_maxspeed(id , 260.0);
            }

        }
    }
}


Arkshine 08-31-2010 11:52

Re: How to properly reset user speed ?
 
The best way is that : http://forums.alliedmods.net/showpos...2&postcount=11 ( calling Ham_Player_ResetMaxSpeed )

Costin83 08-31-2010 12:56

Re: How to properly reset user speed ?
 
So...

PHP Code:

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

#define PLUGIN "UnZoom"
#define VERSION "0.1"
#define AUTHOR "Connor & 80T"

new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame
new boolreset

const m_pPlayer            41
const m_flNextPrimaryAttack    46
const m_flNextSecondaryAttack    47
const m_iClip            51
const m_iFOV            363

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Player_ResetMaxSpeed,"player","playerResetMaxSpeed",1)

    
RegisterHam(Ham_Item_PostFrame"weapon_scout""Sniper_PostFrame")
    
RegisterHam(Ham_Item_PostFrame"weapon_awp""Sniper_PostFrame")
}

public 
Sniper_PostFrameiEnt )
{
    static 
id id get_pdata_cbase(iEntm_pPlayer4)
    static 
iButton iButton pev(idpev_button)

    if(    (!(
iButton IN_ATTACK2) || get_pdata_float(iEntm_flNextSecondaryAttack4) > 0.0)
    &&    (
iButton IN_ATTACK)
    &&    
get_pdata_int(iEntm_iClip4)
    &&    
get_pdata_float(iEntm_flNextPrimaryAttack4) <= 0.0    )
    {
            if( 
get_pdata_int(idm_iFOV5) < 90 )
        {
            
cs_set_user_zoomid CS_SET_NO_ZOOM );

            
reset true
        
}
    }
}

public 
playerResetMaxSpeed(id)
{
    static 
Float:maxspeed
    pev
(id,pev_maxspeed,maxspeed)
    
    if(
reset)
    {
        
set_pev(id,pev_maxspeed,maxspeed)
    }
    
reset false




???
.... I can't really understand this... it isn't working... I'm such a noob lol...

Exolent[jNr] 08-31-2010 13:00

Re: How to properly reset user speed ?
 
He said call it, not hook it.

PHP Code:

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

#define PLUGIN "UnZoom"
#define VERSION "0.1"
#define AUTHOR "Connor & 80T"

new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame
new boolreset

const m_pPlayer            41
const m_flNextPrimaryAttack    46
const m_flNextSecondaryAttack    47
const m_iClip            51
const m_iFOV            363

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Item_PostFrame"weapon_scout""Sniper_PostFrame")
    
RegisterHam(Ham_Item_PostFrame"weapon_awp""Sniper_PostFrame")
}

public 
Sniper_PostFrameiEnt )
{
    static 
id id get_pdata_cbase(iEntm_pPlayer4)
    static 
iButton iButton pev(idpev_button)

    if(    (!(
iButton IN_ATTACK2) || get_pdata_float(iEntm_flNextSecondaryAttack4) > 0.0)
    &&    (
iButton IN_ATTACK)
    &&    
get_pdata_int(iEntm_iClip4)
    &&    
get_pdata_float(iEntm_flNextPrimaryAttack4) <= 0.0    )
    {
            if( 
get_pdata_int(idm_iFOV5) < 90 )
        {
            
cs_set_user_zoomid CS_SET_NO_ZOOM );

            
ExecuteHamBHam_Player_ResetMaxSpeedid );
        }
    }



Arkshine 08-31-2010 13:01

Re: How to properly reset user speed ?
 
ExecuteHamB( Ham_Player_ResetMaxSpeed, id );

Anyway, about your code, if you want to remove the zoom when you do +attack, just make a check in PrimaryAttack, why are you using PostFrame ?

Costin83 08-31-2010 13:08

Re: How to properly reset user speed ?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1287183)
He said call it, not hook it.

PHP Code:

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

#define PLUGIN "UnZoom"
#define VERSION "0.1"
#define AUTHOR "Connor & 80T"

new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame
// new bool: reset

const m_pPlayer            41
const m_flNextPrimaryAttack    46
const m_flNextSecondaryAttack    47
const m_iClip            51
const m_iFOV            363

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Item_PostFrame"weapon_scout""Sniper_PostFrame")
    
RegisterHam(Ham_Item_PostFrame"weapon_awp""Sniper_PostFrame")
}

public 
Sniper_PostFrameiEnt )
{
    static 
id id get_pdata_cbase(iEntm_pPlayer4)
    static 
iButton iButton pev(idpev_button)

    if(    (!(
iButton IN_ATTACK2) || get_pdata_float(iEntm_flNextSecondaryAttack4) > 0.0)
    &&    (
iButton IN_ATTACK)
    &&    
get_pdata_int(iEntm_iClip4)
    &&    
get_pdata_float(iEntm_flNextPrimaryAttack4) <= 0.0    )
    {
            if( 
get_pdata_int(idm_iFOV5) < 90 )
        {
            
cs_set_user_zoomid CS_SET_NO_ZOOM );

            
ExecuteHamBHam_Player_ResetMaxSpeedid );
        }
    }



Oups! Sorry.. my bad.

Also I don't need FUN module any more :mrgreen:
Thanx for help and fast replying.

It's working perfect now and I'm so happy with this code :mrgreen: :mrgreen: :mrgreen:

Edit:

One more question: Does Hamsandwich has a function that can replace "cs_set_user_zoom( id , CS_SET_NO_ZOOM , 1 );" from cstrike ?

Quote:

Originally Posted by Arkshine (Post 1287184)
ExecuteHamB( Ham_Player_ResetMaxSpeed, id );

Anyway, about your code, if you want to remove the zoom when you do +attack, just make a check in PrimaryAttack, why are you using PostFrame ?

Ask ConnorMcLeod, It's his code in most part... :|

This was the original thread: ClickMe

And this might be the answer to your question:

Quote:

Originally Posted by Hawk552 (Post 768034)
The biggest problem is that your method of detection is inaccurate. It checks whether they're olding down the attack button or not but doesn't detect if they actually shot. I think there's a hook in Ham Sandwich for the actual attack event which you can use, instead.

BTW: Can I post this in the New Plugin Submissions thread ?

Arkshine 08-31-2010 14:31

Re: How to properly reset user speed ?
 
Still it would be better to do the check in PrimaryAttack. I don't see the need to use a forward called all the time instead of a forward called only when you fire.

Costin83 08-31-2010 15:31

Re: How to properly reset user speed ?
 
Quote:

Originally Posted by Arkshine (Post 1287274)
Still it would be better to do the check in PrimaryAttack. I don't see the need to use a forward called all the time instead of a forward called only when you fire.

I don't have anything against it... but I can't say that I know how to do it... :|

Arkshine 08-31-2010 15:57

Re: How to properly reset user speed ?
 
Hooking Ham_Weapon_PrimaryAttack and keeping only the fov check. It would be even more appropriate to prefer the VEN's method hooking the shot event.

Costin83 08-31-2010 16:18

Re: How to properly reset user speed ?
 
Quote:

Originally Posted by Arkshine (Post 1287353)
Hooking Ham_Weapon_PrimaryAttack and keeping only the fov check. It would be even more appropriate to prefer the VEN's method hooking the shot event.

Like this ?

PHP Code:

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

#define PLUGIN "UnZoom"
#define VERSION "0.1"
#define AUTHOR "Connor/Arkshine/Exolent/80T"

new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame

const m_pPlayer            41
const m_iFOV            363

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_awp""Sniper_UnScope")
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_scout""Sniper_UnScope")
}

public 
Sniper_UnScopeiEnt )
{
    static 
id id get_pdata_cbase(iEntm_pPlayer4)

    if( 
get_pdata_int(idm_iFOV5) < 90 )
    {
        
cs_set_user_zoomid CS_SET_NO_ZOOM );
        
ExecuteHamBHam_Player_ResetMaxSpeedid );
    }


Still searching for VEN's version... can't find the dang search tut...


All times are GMT -4. The time now is 18:02.

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