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

[CS] Forward to detect whenever BP Ammo changes?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 03-23-2009 , 11:18   [CS] Forward to detect whenever BP Ammo changes?
Reply With Quote #1

Hi all,

I'm looking for a forward that could be used to efficiently detect whenever a player's backpack ammo amount changes.

I want to avoid using register_event/message for the "AmmoX" message, because an engine-generated message has to be sent during such forward's execution (doing that can currently crash the server or result in some awful recursion bugs). I know I can always get around those by using a 0.1 sec task, but I'm looking for a more "clean" and efficient method...

Thanks in advance,
__________________

Last edited by MeRcyLeZZ; 03-23-2009 at 11:31.
MeRcyLeZZ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2009 , 11:35   Re: [CS] Forward to detect whenever BP Ammo changes?
Reply With Quote #2

Quote:
Originally Posted by MeRcyLeZZ View Post
Hi all,

I'm looking for a forward that could be used to efficiently detect whenever a player's backpack ammo amount changes.

I want to avoid using register_event/message for the "AmmoX" message, because an engine-generated message has to be sent during such forward's execution (doing that can currently crash the server or result in some awful recursion bugs). I know I can always get around those by using a 0.1 sec task, but I'm looking for a more "clean" and efficient method...

Thanks in advance,
I found this somewhere and I use it to detect regular weapon reload. You can probably modify it to check change in bpammo on the passed weapon.

PHP Code:
new g_CurWeapon[33][2];
register_event("CurWeapon""fwEvCurWeapon",  "b");

public 
fwEvCurWeapon(id)
{
    new 
iWeapon read_data(2);
    new 
iAmmo read_data(3);
    
    if ( 
g_CurWeapon[id][0] != iWeapon )
    {
        
g_CurWeapon[id][0] = iWeapon;
        
g_CurWeapon[id][1] = iAmmo;
    }
    
    if ( 
g_CurWeapon[id][1] < iAmmo )
    {
        
g_CurWeapon[id][1] = iAmmo;
        
//Reloaded
    
}
    
    
g_CurWeapon[id][0] = iWeapon;
    
g_CurWeapon[id][1] = iAmmo;
    
    return 
PLUGIN_CONTINUE;

__________________
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-23-2009 , 12:15   Re: [CS] Forward to detect whenever BP Ammo changes?
Reply With Quote #3

UpdateClientData (pre hooked) and check for each bpammo slot if m_rgAmmo[SLOT] != m_rgAmmoLast[SLOT]

376 -> 407 - m_rgAmmo[MAX_AMMO_SLOTS]
408 -> 439 - m_rgAmmoLast[MAX_AMMO_SLOTS]

PHP Code:
// Called from UpdateClientData
// makes sure the client has all the necessary ammo info,  if values have changed
void CBasePlayer::SendAmmoUpdate(void)
{
    for (
int i=0MAX_AMMO_SLOTS;i++)
    {
        if (
m_rgAmmo[i] != m_rgAmmoLast[i])
        {
            
m_rgAmmoLast[i] = m_rgAmmo[i];

            
ASSERTm_rgAmmo[i] >= );
            
ASSERTm_rgAmmo[i] < 255 );

            
// send "Ammo" update message
            
MESSAGE_BEGINMSG_ONEgmsgAmmoXNULLpev );
                
WRITE_BYTE);
                
WRITE_BYTEmaxminm_rgAmmo[i], 254 ), ) );  // clamp the value to one byte
            
MESSAGE_END();
        }
    }


You could filter with active item to be more efficient.


You can still use the registered event instead of message AmmoX that will no crash and be less consuming ;), this way you won't be able to block the actual message from being sent but that better than a 0.1 task IMO.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-23-2009 at 12:18.
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 00:49.


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