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

How to properly reset user speed ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Costin83
Senior Member
Join Date: Jul 2008
Location: Romania
Old 08-31-2010 , 11:25   How to properly reset user speed ?
Reply With Quote #1

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);
            }
        }
    }
}
__________________
Originally Posted by Hawk552
Actually, if your style pisses me off enough, I'll generally go through your code and find some reason to unapprove it or at least hold it back.

Last edited by Costin83; 08-31-2010 at 11:28.
Costin83 is offline
Send a message via Yahoo to Costin83
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-31-2010 , 11:52   Re: How to properly reset user speed ?
Reply With Quote #2

The best way is that : http://forums.alliedmods.net/showpos...2&postcount=11 ( calling Ham_Player_ResetMaxSpeed )
__________________

Last edited by Arkshine; 08-31-2010 at 11:55.
Arkshine is offline
Costin83
Senior Member
Join Date: Jul 2008
Location: Romania
Old 08-31-2010 , 12:56   Re: How to properly reset user speed ?
Reply With Quote #3

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...
__________________
Originally Posted by Hawk552
Actually, if your style pisses me off enough, I'll generally go through your code and find some reason to unapprove it or at least hold it back.
Costin83 is offline
Send a message via Yahoo to Costin83
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-31-2010 , 13:00   Re: How to properly reset user speed ?
Reply With Quote #4

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 );
        }
    }

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-31-2010 , 13:01   Re: How to properly reset user speed ?
Reply With Quote #5

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 ?
__________________
Arkshine is offline
Costin83
Senior Member
Join Date: Jul 2008
Location: Romania
Old 08-31-2010 , 13:08   Re: How to properly reset user speed ?
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
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
Thanx for help and fast replying.

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

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 View Post
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 View Post
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 ?
__________________
Originally Posted by Hawk552
Actually, if your style pisses me off enough, I'll generally go through your code and find some reason to unapprove it or at least hold it back.

Last edited by Costin83; 08-31-2010 at 13:41.
Costin83 is offline
Send a message via Yahoo to Costin83
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-31-2010 , 14:31   Re: How to properly reset user speed ?
Reply With Quote #7

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.
__________________
Arkshine is offline
Costin83
Senior Member
Join Date: Jul 2008
Location: Romania
Old 08-31-2010 , 15:31   Re: How to properly reset user speed ?
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
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...
__________________
Originally Posted by Hawk552
Actually, if your style pisses me off enough, I'll generally go through your code and find some reason to unapprove it or at least hold it back.
Costin83 is offline
Send a message via Yahoo to Costin83
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-31-2010 , 15:57   Re: How to properly reset user speed ?
Reply With Quote #9

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.
__________________
Arkshine is offline
Costin83
Senior Member
Join Date: Jul 2008
Location: Romania
Old 08-31-2010 , 16:18   Re: How to properly reset user speed ?
Reply With Quote #10

Quote:
Originally Posted by Arkshine View Post
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...
__________________
Originally Posted by Hawk552
Actually, if your style pisses me off enough, I'll generally go through your code and find some reason to unapprove it or at least hold it back.

Last edited by Costin83; 08-31-2010 at 16:32.
Costin83 is offline
Send a message via Yahoo to Costin83
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 09:49.


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