AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [CS] Forward to detect whenever BP Ammo changes? (https://forums.alliedmods.net/showthread.php?t=88335)

MeRcyLeZZ 03-23-2009 11:18

[CS] Forward to detect whenever BP Ammo changes?
 
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,

Bugsy 03-23-2009 11:35

Re: [CS] Forward to detect whenever BP Ammo changes?
 
Quote:

Originally Posted by MeRcyLeZZ (Post 787236)
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;



ConnorMcLeod 03-23-2009 12:15

Re: [CS] Forward to detect whenever BP Ammo changes?
 
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.


All times are GMT -4. The time now is 08:53.

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