AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   L4D2, How to Get Reserve Ammo Without m_hOwnerEntity? (https://forums.alliedmods.net/showthread.php?t=301594)

NgBUCKWANGS 09-28-2017 05:51

L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Hello,

I have a gripe with how I'm getting reserve ammo to any primary weapon. I currently have

PHP Code:

int _GetReserve(int ent) {

    static 
clienttype;
    
client GetEntPropEnt(entProp_Send"m_hOwnerEntity");

    if (
IsClientValid(client2)) {
        
type GetEntProp(entProp_Send"m_iPrimaryAmmoType");
        return 
GetEntProp(clientProp_Send"m_iAmmo"4type);
    }

    return -
1;


This works perfectly if the weapon is being held by a player. If the weapon is on the ground, it's f*****. I was
equipping the weapon onto a player just to get the reserve and then removing it but it feels hackish and if I remember correctly the player could potentially end up with 2 weapons in their primary slot. I was thinking about creating one fake client and hiding them off the map but again, it feels so damn hackish. I'm thinking there has to be a way to look at any weapon and without anyone holding it, get the reserve ammo?

I'm thinking maybe SetEntProp on the m_hOwnerEntity to the client requesting the reserve? If you know a better approach, can you please share? Thanks!

hleV 09-28-2017 10:09

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Supposedly the reserve ammo is held by the player, not the weapon.

NgBUCKWANGS 09-28-2017 11:07

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by hleV (Post 2551283)
Supposedly the reserve ammo is held by the player, not the weapon.

if I equip the weapon, I have no problem getting the reserve. but just looking at a weapon on the floor get's tricky as hell. short of equipping it I'm trying to mess with some netprops to sort of simulate having it equipped but without moving it. I tried changing the m_hOwnerEntity (and others) of the weapon but it's unreliable. I tried just grabbing a random survivor, getting the ammo type of the weapon and then just going for the m_iAmmo and no luck.

There's got to be a way to grab the reserve (without equipping/moving the weapon) reliably and I'm stumped.

Powerlord 09-29-2017 04:57

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by NgBUCKWANGS (Post 2551289)
if I equip the weapon, I have no problem getting the reserve. but just looking at a weapon on the floor get's tricky as hell. short of equipping it I'm trying to mess with some netprops to sort of simulate having it equipped but without moving it. I tried changing the m_hOwnerEntity (and others) of the weapon but it's unreliable. I tried just grabbing a random survivor, getting the ammo type of the weapon and then just going for the m_iAmmo and no luck.

There's got to be a way to grab the reserve (without equipping/moving the weapon) reliably and I'm stumped.

Actually, are you sure the entities for the weapons on the floor are the same entities when a player is carrying them? I don't have L4D datamap and netprop dumps to check.

NgBUCKWANGS 09-29-2017 08:05

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by Powerlord (Post 2551426)
Actually, are you sure the entities for the weapons on the floor are the same entities when a player is carrying them? I don't have L4D datamap and netprop dumps to check.

Not 100% but I did as a last hack resort kind of thing, scripted in OnPlayerRunCmd that when ever I looked at a weapon, I'd get a bot to immediately use that weapon. I did only check to see if their original item changed and if so, I'd get them to use it again. Now while they were actually holding the weapon in question, I tried getting the reserve and that was unreliable. I tried quite a few things and it gotten pretty ridiculous.

For those googling and curious, you'd get dumps of most stuff (e.g., datamaps, netprops) with
PHP Code:

"sm_dump_admcache"
 
Dumps the admin cache for debugging
"sm_dump_classes"
 
Dumps the class list as a text file
"sm_dump_datamaps"
 
Dumps the data map list as a text file
"sm_dump_handles"
 
Dumps Handle usage to a file for finding Handle leaks
"sm_dump_netprops"
 
Dumps the networkable property table as a text file
"sm_dump_netprops_xml"
 
Dumps the networkable property table as an XML file
"sm_dump_teprops"
 
Dumps tempentity props to a file 

Yesterday, I kept at it for a while and couldn't reliably within the same frame get the reserve of a weapon just laying on the ground without moving it (I know it has ammo, I put it there). My attempts would sometimes work but most of the time they won't. All my methods were in the end just completely unreliable. As far as what I'm working on, I don't technically need to even do this but it's a problem I'm really curious about and I'm fascinated by it.

I mean, even if it's the client that has that information, why can't I as a client get it without moving the weapon? If I make any progress on this, I'll report back. Thanks fellas :)

MasterMind420 10-31-2017 02:16

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by hleV (Post 2551283)
Supposedly the reserve ammo is held by the player, not the weapon.

This is correct. The only way I can think of buckwangs is to track the reserve ammo count and entindex of the weapon. When the weapon is dropped store reserve count and entindex. When the weapon is picked back up set the ammo reserve amount to whatever that entindex has stored. That should effectively track the reserve ammo per gun and not just on the player.

NgBUCKWANGS 10-31-2017 10:59

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by MasterMind420 (Post 2557683)
This is correct. The only way I can think of buckwangs is to track the reserve ammo count and entindex of the weapon. When the weapon is dropped store reserve count and entindex. When the weapon is picked back up set the ammo reserve amount to whatever that entindex has stored. That should effectively track the reserve ammo per gun and not just on the player.

Your idea will work but I'm kind of urked knowing that that information is in the ether somewhere :(

MasterMind420 10-31-2017 20:12

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Quote:

Originally Posted by NgBUCKWANGS (Post 2557756)
Your idea will work but I'm kind of urked knowing that that information is in the ether somewhere :(

I know exactly what you mean, its more of a workaround to store it somewhere and be able to retrieve it. Totally not ideal, I think it was pretty stupid the way valve handled reserve ammo in L4D2, should have been stored same way clips are using a netprop/datamap, and not on the players, not sure the logic behind that decision. Maybe they had a good reason but I don't know...having to basically hack it is just a dirty way of doing it...

xZk 03-27-2020 13:15

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
I know that it may be too late, but perhaps this will be of some use:
PHP Code:


int _GetReserve
(int weapon) { 
 return 
GetEntProp(weaponProp_Data"m_iExtraPrimaryAmmo");


pd: only work when weapon is dropped

credits to panxiaohai

Dragokas 03-27-2020 13:26

Re: L4D2, How to Get Reserve Ammo Without m_hOwnerEntity?
 
Perhaps, can be easily found using tEntDev (sm_ted_select) + Dev Cmds (sm_ent).

Make snapshot #1, shoot some ammo, make snapshot #2, compare 2 left4dead/kvtest.txt files using any tool like WinMerge.


All times are GMT -4. The time now is 19:09.

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