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

[TUT] How to hook reload event properly


Post New Thread Reply   
 
Thread Tools Display Modes
Immortal_BLG
Member
Join Date: Feb 2010
Location: RUSSIA
Old 04-10-2010 , 20:54   Re: How to hook reload event properly
Reply With Quote #11

Sorry I was wrong....
Immortal_BLG is offline
Foghrye4
Junior Member
Join Date: Dec 2010
Old 12-11-2010 , 15:38   Re: How to hook reload event properly
Reply With Quote #12

xPaw
I have a question. A memory offset for m_fReloadTimefor get_pdata_float() is?
__________________
|卍|///A山E己ロME・ロ丁AK凵///|卍|
Foghrye4 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-11-2010 , 15:57   Re: How to hook reload event properly
Reply With Quote #13

It doesn't exist. It's hardcoded in each weapon file, passed into DefaultReload() and into this function set in m_flNextAttack. (player, 83)
__________________
Arkshine is offline
Foghrye4
Junior Member
Join Date: Dec 2010
Old 12-12-2010 , 06:15   Re: How to hook reload event properly
Reply With Quote #14

Arkshine
So, if i want to change reload time i must check "if weapon reloading" state using m_fInReload with memory offset 54 and then simple change m_flNextAttack with memory offset 83?
Does it work fine?

UPD(15:46)___________________________________ _____________
Okey, i try it and it's work, thanx to Arkshine. I try it in "RPGx 2.0" plugin by Roflmao, by modification "Speed Shot+".
Here is code:
Code:
#pragma semicolon 1

#include <amxmodx>
#include <engine>
#include <fakemeta_util>
#include <rpgx>

new upgrade_id, level, weaponid, ent, str[16], Float:reload_delay, weapon[32], bool:is_reloading;

public plugin_init(){
    register_plugin("Reload Speed+ RPGx Upgrade", "1.0", "roflmao456+Foghrye4");
}
    
public RPGx_OnPluginReady()
    upgrade_id = RPGx_MakeUpgrade("Reload+", 5, 15, 20);

public client_PreThink(id){
    level = RPGx_GetUpgradeLevel(id, upgrade_id);
    if(level){
        weaponid = get_user_weapon(id);
        if(weaponid){
            get_weaponname(weaponid, weapon, 31);
            ent = fm_find_ent_by_owner(-1, weapon, id);
            if(ent){
            reload_delay = get_pdata_float(id, 83, 4);
        is_reloading = (reload_delay > 0.0) &&  (get_pdata_int(ent, 54, 4) > 0);
                if(is_reloading){
        set_pdata_float(id, 83, reload_delay - (reload_delay * (level * 0.05)), 4);
             }
        }
        }
 }
/* For debug only */
format(str, 15, "Accuracy %f", reload_delay);
client_print(id, print_chat, "%L", id, str);
}
But now i have one more problem. How i can change animation speed for reloading process?
Because it looks too unrealistic in high levels to shoot just after clip is empty with no clip reloading.
__________________
|卍|///A山E己ロME・ロ丁AK凵///|卍|

Last edited by Foghrye4; 12-12-2010 at 08:00. Reason: Updated
Foghrye4 is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-07-2011 , 07:39   Re: How to hook reload event properly
Reply With Quote #15

How do I get weapon owner id when the weapon is being reloaded?

Edit: Well sorry for being too lazy, I browser wiki and found out this works:
new id = pev( iWeapon, pev_owner )
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 08-07-2011 at 07:43.
Backstabnoob is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 08-09-2011 , 07:33   Re: How to hook reload event properly
Reply With Quote #16

Quote:
Originally Posted by Backstabnoob View Post
How do I get weapon owner id when the weapon is being reloaded?

Edit: Well sorry for being too lazy, I browser wiki and found out this works:
new id = pev( iWeapon, pev_owner )
You can also use m_pPlayer offset.
PHP Code:
#define m_pPlayer 41

new id get_pdata_cbaseiWeaponm_pPlayer); 
__________________
xPaw is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 08-21-2011 , 09:04   Re: How to hook reload event properly
Reply With Quote #17

Euhm,
those settings are for Windows?

If yes,
Can U give me the Linux settings / Link me?
__________________
Retired.
Xalus is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-21-2011 , 09:33   Re: How to hook reload event properly
Reply With Quote #18

It will work for linux too.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-21-2011 , 11:57   Re: How to hook reload event properly
Reply With Quote #19

Reload end : (seems to be reliable after only few tests) :
Can be altered with register_message instead of register_event.

SHOTGUNS are not covered because of their special reload system.

PHP Code:
#define NADES_BITSUM    (1 << CSW_HEGRENADE) |  (1 << CSW_FLASHBANG) | (1 << CSW_SMOKEGRENADE)
#define NORELOAD_BITSUM NADES_BITSUM | (1 << CSW_KNIFE) | (1 << CSW_C4) | (1 << CSW_M3) | (1 << CSW_XM1014) 

const XO_WEAPON 4
const m_pPlayer 41
const m_iId 43
const m_iClip 51
const m_iClientClip 52
const m_fInReload  54

const XO_PLAYER 5
const m_pActiveItem 373 
PHP Code:
register_event("CurWeapon""Event_CurWeapon""be""1=1""3>0"
PHP Code:
public Event_CurWeaponid )
{
    new 
iId read_data(2)
    if( ~
NORELOAD_BITSUM 1<<iId )
    {
        new 
iWeapon get_pdata_cbase(idm_pActiveItemXO_PLAYER)
        new 
iClientClip get_pdata_int(iWeaponm_iClientClipXO_WEAPON)
        new 
iClip read_data(3)
        if( 
iClip iClientClip )
        {
            
// Player <id> has reloaded weapon <m_pActiveItem>, weapontype iId
        
}
    }


Note : If this is reliable, it uses less cpu than hooking Item_PreFrame


Other way :
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define NADES_BITSUM    (1 << CSW_HEGRENADE) |  (1 << CSW_FLASHBANG) | (1 << CSW_SMOKEGRENADE)
#define NORELOAD_BITSUM NADES_BITSUM | (1 << CSW_KNIFE) | (1 << CSW_C4) | (1 << CSW_M3) | (1 << CSW_XM1014) 

const XO_WEAPON 4
const m_pPlayer 41
const m_iId 43
const m_iClip 51
const m_iClientClip 52
const m_fInReload  54

const XO_PLAYER 5
const m_pActiveItem 373

const MAX_PLAYERS 32
new g_iPlayerWeaponReloading[MAX_PLAYERS+1]

public 
plugin_init() 
{
    
register_plugin("Reload""0.0.1""ConnorMcLeod")

    new 
szWeapon[32]
    for(new 
iId CSW_P228iId <= CSW_P90iId++) 
    {
        if( ~
NORELOAD_BITSUM & (<< iId) && get_weaponnameiIdszWeaponcharsmax(szWeapon)) )
        {
            
RegisterHamHam_Weapon_ReloadszWeapon"Weapon_Reload_Post"true)
            
RegisterHam(Ham_Item_HolsterszWeapon"Item_Holster")
        }
    }
    
register_event("CurWeapon""Event_CurWeapon""be""1=1""3>0")
}

public 
Weapon_Reload_PostiWeapon 
{
    if( 
get_pdata_int(iWeaponm_fInReloadXO_WEAPON) )
    {
        
// starts reloading
        
new id get_pdata_cbase(iWeaponm_pPlayerXO_WEAPON)
        new 
iId get_pdata_int(iWeaponm_iIdXO_WEAPON)
        
g_iPlayerWeaponReloadingid ] = iId
        
new szWeapon[32]
        
get_weaponname(iIdszWeaponcharsmax(szWeapon))
        
client_print(idprint_chat"START RELOAD %s"szWeapon)
    }
}

public 
Item_HolsteriWeapon )
{
    if( 
get_pdata_int(iWeaponm_fInReloadXO_WEAPON) )
    {
        new 
id get_pdata_cbase(iWeaponm_pPlayerXO_WEAPON)
        new 
iId g_iPlayerWeaponReloadingid ]
        if( 
iId )
        {
            new 
szWeapon[32]
            
get_weaponname(iIdszWeaponcharsmax(szWeapon))
            
client_print(idprint_chat"STOP RELOAD %s"szWeapon)
        }
        
g_iPlayerWeaponReloadingid ] = 0
    
}
}

public 
Event_CurWeaponid )
{
    new 
iId read_data(2)

    new 
iPlayerWeaponReloading g_iPlayerWeaponReloadingid ]
    if( 
iPlayerWeaponReloading && iPlayerWeaponReloading == iId )
    {
        
// player has finished to reload
        
new szWeapon[32]
        
get_weaponname(iIdszWeaponcharsmax(szWeapon))
        
client_print(idprint_chat"Finished Reload %s"szWeapon)
        
g_iPlayerWeaponReloadingid ] = 0
    
}


You can find the exact way it should be hooked in this plugin, but as i said, Item_Preframe uses more cpu.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 09-21-2011 at 12:08.
ConnorMcLeod is offline
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 04:19.


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