Raised This Month: $32 Target: $400
 8% 

Solved L4D1 How to get weapon's BACKUP ammo?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 12-08-2020 , 23:16   L4D1 How to get weapon's BACKUP ammo?
Reply With Quote #1

Hi people, I'm having problems getting current reserve (backup) ammo of a weapon dropped on the ground (or carried by a player).

I tried this:
PHP Code:
int reserveAmmo GetEntProp(clientProp_Send"m_iAmmo"); 
But it return always 1.

And obviously it wont work on weapons dropped on the groud, because "client" is present.

I also tried:
PHP Code:
int reserveAmmo GetEntProp(iWeaponProp_Send"m_iExtraPrimaryAmmo"); 
But it always return 0.

I found somewhere SMLIB has a function for this but the host is no longer online. The link is broken.
Does anybody have any idea please?


PD: I need weapon's BACKUP ammo. I am not talking about current magazine ammo
I know about
PHP Code:
GetEntProp(weaponProp_Send"m_iClip1"1); 
<--this is not what I am looking for.
Thanks ^^

Last edited by axelnieves2012; 12-09-2020 at 02:19.
axelnieves2012 is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-09-2020 , 00:52   Re: L4D1 How to get weapon's BACKUP ammo?
Reply With Quote #2

m_iExtraPrimaryAmmo is always 0 while clients hold the weapon, it is instead stored in m_iAmmo at offset indexes.
As soon as a client drops a weapon, it then transfers the m_iAmmo value at the offset and sets the property m_iExtraPrimaryAmmo on the newly dropped weapon.
Same with when a client picks up a weapon, it takes the m_iExtraPrimaryAmmo and applies to the m_iAmmo offset of the m_iPrimaryAmmoType and sets the m_iExtraPrimaryAmmo to 0.
PHP Code:
//Get reserve ammo of current weapon held by client:
int iWeapon GetEntPropEnt(clientProp_Data"m_hActiveWeapon");
if (
IsValidEntity(iWeapon))
{
    
int iOffsetValidate GetEntProp(iWeaponProp_Data"m_iPrimaryAmmoType");
    if (
iOffsetValidate != -1)
    {
        
int iReserveAmmo GetEntProp(clientProp_Send"m_iAmmo"_iOffsetValidate);
    }
}

//Get reserve ammo of weapon on ground:
int iWeapon //method of detection
if (IsValidEntity(iWeapon))
{
    
int iReserveAmmo GetEntProp(iWeaponProp_Data"m_iExtraPrimaryAmmo");

It could also be an issue of Prop_Send vs Prop_Data for some of these detections, but this method has worked in a test I just ran.

Last edited by Balimbanana; 12-09-2020 at 01:54. Reason: Validation in offset for PrimaryAmmoType
Balimbanana is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-09-2020 , 01:30   Re: L4D1 How to get weapon's BACKUP ammo?
Reply With Quote #3

This is what I use to get player's current reserve ammo:
PHP Code:
int iAmmo = -1iWeapon GetPlayerWeaponSlot(survivor0);
if (
iWeapon MaxClients)
{
    
char sWeapon[32];
    
GetEntityClassname(iWeaponsWeaponsizeof(sWeapon));
    
iAmmo GetEntProp(survivorProp_Send"m_iAmmo"_iGetWeaponOffset(sWeapon));
}

stock int iGetWeaponOffset(const char[] weapon)
{
    if (
StrEqual(weapon"weapon_rifle") || StrEqual(weapon"weapon_rifle_ak47") || StrEqual(weapon"weapon_rifle_desert") || StrEqual(weapon"weapon_rifle_sg552"))
    {
        return 
3;
    }
    else if (
StrEqual(weapon"weapon_smg") || StrEqual(weapon"weapon_smg_silenced") || StrEqual(weapon"weapon_smg_mp5"))
    {
        return 
5;
    }
    else if (
StrEqual(weapon"weapon_shotgun_chrome"))
    {
        return 
7;
    }
    else if (
StrEqual(weapon"weapon_pumpshotgun"))
    {
        return 
g_bLeft4Dead2 6;
    }
    else if (
StrEqual(weapon"weapon_shotgun_spas"))
    {
        return 
8;
    }
    else if (
StrEqual(weapon"weapon_autoshotgun"))
    {
        return 
g_bLeft4Dead2 6;
    }
    else if (
StrEqual(weapon"weapon_hunting_rifle"))
    {
        return 
g_bLeft4Dead2 2;
    }
    else if (
StrEqual(weapon"weapon_sniper_military") || StrEqual(weapon"weapon_sniper_scout") || StrEqual(weapon"weapon_sniper_awp"))
    {
        return 
10;
    }
    else if (
StrEqual(weapon"weapon_grenade_launcher"))
    {
        return 
17;
    }

    return 
0;

Hope this helps.
__________________
Psyk0tik is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 12-09-2020 , 02:17   Re: L4D1 How to get weapon's BACKUP ammo?
Reply With Quote #4

Quote:
Originally Posted by Balimbanana View Post
m_iExtraPrimaryAmmo is always 0 while clients hold the weapon, it is instead stored in m_iAmmo at offset indexes.
As soon as a client drops a weapon, it then transfers the m_iAmmo value at the offset and sets the property m_iExtraPrimaryAmmo on the newly dropped weapon.
Same with when a client picks up a weapon, it takes the m_iExtraPrimaryAmmo and applies to the m_iAmmo offset of the m_iPrimaryAmmoType and sets the m_iExtraPrimaryAmmo to 0.
PHP Code:
//Get reserve ammo of current weapon held by client:
int iWeapon GetEntPropEnt(clientProp_Data"m_hActiveWeapon");
if (
IsValidEntity(iWeapon))
{
    
int iOffsetValidate GetEntProp(iWeaponProp_Data"m_iPrimaryAmmoType");
    if (
iOffsetValidate != -1)
    {
        
int iReserveAmmo GetEntProp(clientProp_Send"m_iAmmo"_iOffsetValidate);
    }
}

//Get reserve ammo of weapon on ground:
int iWeapon //method of detection
if (IsValidEntity(iWeapon))
{
    
int iReserveAmmo GetEntProp(iWeaponProp_Data"m_iExtraPrimaryAmmo");

It could also be an issue of Prop_Send vs Prop_Data for some of these detections, but this method has worked in a test I just ran.
Thank you. I have completed my plugin now ^^
that was exactly what i needed
axelnieves2012 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 12-09-2020 , 02:19   Re: L4D1 How to get weapon's BACKUP ammo?
Reply With Quote #5

Quote:
Originally Posted by Crasher_3637 View Post
This is what I use to get player's current reserve ammo:
PHP Code:
int iAmmo = -1iWeapon GetPlayerWeaponSlot(survivor0);
if (
iWeapon MaxClients)
{
    
char sWeapon[32];
    
GetEntityClassname(iWeaponsWeaponsizeof(sWeapon));
    
iAmmo GetEntProp(survivorProp_Send"m_iAmmo"_iGetWeaponOffset(sWeapon));
}

stock int iGetWeaponOffset(const char[] weapon)
{
    if (
StrEqual(weapon"weapon_rifle") || StrEqual(weapon"weapon_rifle_ak47") || StrEqual(weapon"weapon_rifle_desert") || StrEqual(weapon"weapon_rifle_sg552"))
    {
        return 
3;
    }
    else if (
StrEqual(weapon"weapon_smg") || StrEqual(weapon"weapon_smg_silenced") || StrEqual(weapon"weapon_smg_mp5"))
    {
        return 
5;
    }
    else if (
StrEqual(weapon"weapon_shotgun_chrome"))
    {
        return 
7;
    }
    else if (
StrEqual(weapon"weapon_pumpshotgun"))
    {
        return 
g_bLeft4Dead2 6;
    }
    else if (
StrEqual(weapon"weapon_shotgun_spas"))
    {
        return 
8;
    }
    else if (
StrEqual(weapon"weapon_autoshotgun"))
    {
        return 
g_bLeft4Dead2 6;
    }
    else if (
StrEqual(weapon"weapon_hunting_rifle"))
    {
        return 
g_bLeft4Dead2 2;
    }
    else if (
StrEqual(weapon"weapon_sniper_military") || StrEqual(weapon"weapon_sniper_scout") || StrEqual(weapon"weapon_sniper_awp"))
    {
        return 
10;
    }
    else if (
StrEqual(weapon"weapon_grenade_launcher"))
    {
        return 
17;
    }

    return 
0;

Hope this helps.
Thank you too, it is useful
axelnieves2012 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 22:32.


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