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

How to solve this? (Curweapon)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 09-16-2011 , 22:19   How to solve this? (Curweapon)
Reply With Quote #1

I recently found this code:

PHP Code:
#include <amxmodx>

new g_curWpn[33][2];

public 
plugin_init() {
    
    
register_event("CurWeapon""Event_Cur_Weapon",  "b")
}

public 
Event_Cur_Weapon(id)
{
    new 
weapon read_data(2);
    new 
ammo read_data(3);
    
    if(
g_curWpn[id][0] != weapon)
    {
        
g_curWpn[id][0] = weapon;
        
g_curWpn[id][1] = ammo;
    }
    
    if(
g_curWpn[id][1] < ammo)
    {
        
g_curWpn[id][1] = ammo;
        
client_print(idprint_chat"Reloaded...."); //This.
    
}
    
    
g_curWpn[id][0] = weapon;
    
g_curWpn[id][1] = ammo;

It detects when you stop reloading a weapon and it works (kinda), because it only detects that event when you only use the weapon. I mean, if I have a deagle, shot some bullets and after the I change it for a TMP, when I use back the deagle and reload it wont detect it. But when I shoot only with the deagle it will detect the event.

Is there a way to solve that?

PD: I hope you could understand the explanation
AfteR. is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 09-17-2011 , 01:18   Re: How to solve this? (Curweapon)
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>

#define NO_RELOAD ((1 << 2) | (1 << CSW_KNIFE) | (1 << CSW_C4) | (1 << CSW_M3) | (1 << CSW_XM1014) | (1 << CSW_HEGRENADE) | (1 << CSW_FLASHBANG) | (1 << CSW_SMOKEGRENADE))

#define m_pPlayer 41
#define m_fInReload 54
#define m_iClip 51

public plugin_init()
{
    new 
szWeaponName[20];
    for(new 
CSW_P228<= CSW_P90i++) 
    {
        if(
NO_RELOAD & (<< i))
            continue;
        
        
get_weaponname(iszWeaponNamecharsmax(szWeaponName));
        
RegisterHam(Ham_Weapon_ReloadszWeaponName"fwdHamWeaponReload"1);
    }
    
RegisterHam(Ham_Weapon_Reload"weapon_m3""fwdHamWeaponSpecialReload"1);
    
RegisterHam(Ham_Weapon_Reload"weapon_xm1014""fwdHamWeaponSpecialReload"1);
}

public 
fwdHamWeaponReload(const iWeapon)
{
    new 
id get_pdata_cbase(iWeaponm_pPlayer4);
    
    if(!
is_user_connected(id))
        return 
HAM_IGNORED;
        
    if(
get_pdata_int(iWeaponm_fInReload4))
    {
        if(
pev(idpev_button) & IN_RELOAD)
        {
            
//In normal reloads
            //iClipAmmo = get_pdata_int(iWeapon, m_iClip, 4); //Gets clip ammo
            //set_pdata_int(iWeapon, m_iClip, 0, 4);//Sets clip ammo to 0
        
}
    }
    return 
HAM_IGNORED;
}

public 
fwdHamWeaponSpecialReload(const iWeapon)
{
    new 
id get_pdata_cbase(iWeaponm_pPlayer4);
    
    if(!
is_user_connected(id))
        return 
HAM_IGNORED;
        
    if(
get_pdata_int(iWeaponm_fInReload4))
    {
        if(
pev(idpev_button) & IN_RELOAD)
        {
            
//In special reload of shotguns
            //iClipAmmo = get_pdata_int(iWeapon, m_iClip, 4); //Gets clip ammo
            //set_pdata_int(iWeapon, m_iClip, 0, 4);//Sets clip ammo to 0
        
}
    }
    return 
HAM_IGNORED;

Catches the reload event of each weapon including the special weapons

I do not take credit for the above code i got it from Xpaw i believe.

To get which weapon is being reloaded use cs_get_weapon_id(iWeapon);
Doc-Holiday is offline
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 09-17-2011 , 12:56   Re: How to solve this? (Curweapon)
Reply With Quote #3

Quote:
Originally Posted by Doc-Holiday View Post
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>

#define NO_RELOAD ((1 << 2) | (1 << CSW_KNIFE) | (1 << CSW_C4) | (1 << CSW_M3) | (1 << CSW_XM1014) | (1 << CSW_HEGRENADE) | (1 << CSW_FLASHBANG) | (1 << CSW_SMOKEGRENADE))

#define m_pPlayer 41
#define m_fInReload 54
#define m_iClip 51

public plugin_init()
{
    new 
szWeaponName[20];
    for(new 
CSW_P228<= CSW_P90i++) 
    {
        if(
NO_RELOAD & (<< i))
            continue;
        
        
get_weaponname(iszWeaponNamecharsmax(szWeaponName));
        
RegisterHam(Ham_Weapon_ReloadszWeaponName"fwdHamWeaponReload"1);
    }
    
RegisterHam(Ham_Weapon_Reload"weapon_m3""fwdHamWeaponSpecialReload"1);
    
RegisterHam(Ham_Weapon_Reload"weapon_xm1014""fwdHamWeaponSpecialReload"1);
}

public 
fwdHamWeaponReload(const iWeapon)
{
    new 
id get_pdata_cbase(iWeaponm_pPlayer4);
    
    if(!
is_user_connected(id))
        return 
HAM_IGNORED;
        
    if(
get_pdata_int(iWeaponm_fInReload4))
    {
        if(
pev(idpev_button) & IN_RELOAD)
        {
            
//In normal reloads
            //iClipAmmo = get_pdata_int(iWeapon, m_iClip, 4); //Gets clip ammo
            //set_pdata_int(iWeapon, m_iClip, 0, 4);//Sets clip ammo to 0
        
}
    }
    return 
HAM_IGNORED;
}

public 
fwdHamWeaponSpecialReload(const iWeapon)
{
    new 
id get_pdata_cbase(iWeaponm_pPlayer4);
    
    if(!
is_user_connected(id))
        return 
HAM_IGNORED;
        
    if(
get_pdata_int(iWeaponm_fInReload4))
    {
        if(
pev(idpev_button) & IN_RELOAD)
        {
            
//In special reload of shotguns
            //iClipAmmo = get_pdata_int(iWeapon, m_iClip, 4); //Gets clip ammo
            //set_pdata_int(iWeapon, m_iClip, 0, 4);//Sets clip ammo to 0
        
}
    }
    return 
HAM_IGNORED;

Catches the reload event of each weapon including the special weapons

I do not take credit for the above code i got it from Xpaw i believe.

To get which weapon is being reloaded use cs_get_weapon_id(iWeapon);
Thank you, but what I need is to detect when it stops reloading. BTW, thanks for that code.
AfteR. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-17-2011 , 15:18   Re: How to solve this? (Curweapon)
Reply With Quote #4

Look at the SDK to figure it out, I don't have access or I would look for you.

I believe you can hook CurWeapon to fire when the HUD updates the ammo, you can use the above to hook reload start then curweapon for reload end. There may be a much easier way, its just an idea.
__________________

Last edited by Bugsy; 09-17-2011 at 15:28.
Bugsy is offline
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 09-18-2011 , 13:42   Re: How to solve this? (Curweapon)
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Look at the SDK to figure it out, I don't have access or I would look for you.

I believe you can hook CurWeapon to fire when the HUD updates the ammo, you can use the above to hook reload start then curweapon for reload end. There may be a much easier way, its just an idea.
Nevermind, I found this plugin:

http://forums.alliedmods.net/showthread.php?p=220167

Thank you, anyway!
AfteR. is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 09-18-2011 , 15:45   Re: How to solve this? (Curweapon)
Reply With Quote #6

How to hook reload event properly
__________________
xPaw is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 09-18-2011 , 17:34   Re: How to solve this? (Curweapon)
Reply With Quote #7

Quote:
Originally Posted by xPaw View Post

Thats where i got the code from swapped it around abit using a bit some cus its used else where also. but same code.
Doc-Holiday is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-19-2011 , 01:51   Re: How to solve this? (Curweapon)
Reply With Quote #8

Quote:
Originally Posted by AfteR. View Post
Nevermind, I found this plugin:

http://forums.alliedmods.net/showthread.php?p=220167

Thank you, anyway!
Plugin is not accurate, look at version i posted in last pages.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
AfteR.
Veteran Member
Join Date: Dec 2008
Location: λ
Old 09-19-2011 , 14:37   Re: How to solve this? (Curweapon)
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
Plugin is not accurate, look at version i posted in last pages.
Ok thanks for that!
AfteR. 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 02:50.


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