AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [L4D/L4D2] Reserve (Ammo) Control [20-Jan-2021] (https://forums.alliedmods.net/showthread.php?t=334274)

Orinuse 09-11-2021 17:03

[L4D/L4D2] Reserve (Ammo) Control [20-Jan-2021]
 
1 Attachment(s)
Made possible with Psykotikism's Library of L4Ds Signatures!

Description
Individually control weapon reserve independent of "ammo_*" cvars. Primary intent is to let weapon modders set reserve ammo counts without fighting with ammo types :bee: (CSS Snipers, L4D1 Shotguns)

Customization
Go to the "/addons/sourcemod/data/l4d_reservecontrol.cfg" file after the plugin has been installed, and edit it.
Data File


Commands
Spoiler


Changelog
Spoiler


Requirements
  1. DHooks (Dynamic Detours) extension.

WARNING
  • Weapons via the give command won't spawn with the correct reserve counts till an ammo pile is used. Not sure why this happens, but its really minor practically.
  • If other plugins that edit reserve ammo are also present, their functionalities may conflict and fight with this plugin!
    • Unfortunately preventing this is simply not possible, every plugin is vastly different from each other in implementation.

Installing
Extract the .zip file's folders into /addons/sourcemod.

Silvers 09-11-2021 17:35

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
I don't think a detour is required. SDKHook clients SDKHook_WeaponEquip and SDKHook_WeaponDrop and modify the reserve ammo with the following code.

You could track the entity each time someone equips or drops a weapon and set the ammo value accordingly. For example have g_iAmmo[2048][2] where g_iAmmo[weapon][0] is the EntIndexToEntRef() of the weapon to verify itself is the same weapon, and [1] would be the ammo you read/set when picked up/dropped. That would work for all weapons without issue from what I can think.

PHP Code:

// Plugin start:
g_iOffsetAmmo FindSendPropInfo("CTerrorPlayer""m_iAmmo");
g_iPrimaryAmmoType FindSendPropInfo("CBaseCombatWeapon""m_iPrimaryAmmoType");

// The function
int GetOrSetPlayerAmmo(int clientint iWeaponint iAmmo = -1)
{
    
int offset GetEntData(iWeapong_iPrimaryAmmoType) * 4// Thanks to "Root" or whoever for this method of not hard-coding offsets: https://github.com/zadroot/AmmoManager/blob/master/scripting/ammo_manager.sp

    // Get/Set
    
if( offset )
    {
        if( 
iAmmo != -SetEntData(clientg_iOffsetAmmo offsetiAmmo);
        else return 
GetEntData(clientg_iOffsetAmmo offset);
    }

    return 
0;



Orinuse 09-12-2021 04:33

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Quote:

Originally Posted by Silvers (Post 2757523)
I don't think a detour is required. SDKHook clients SDKHook_WeaponEquip and SDKHook_WeaponDrop and modify the reserve ammo with the following code.

-snip-

I did tried an approach without detours (or gamedata), but these issues arise:
  1. Ammo piles. I used to hijack the ammo refilling an SDKHook_Use, but that leaded to more issues:
    • Hijacking means I need to now manually give ammo to everyone, so I need to iterate through their inventory's items.
    • There are special ammo refilling gamerules, like how L4D2 ammo piles give extra ammo to compensate for empty clips (used a SDKCall to resolve), or that M60 / GL ammo can't be refilled. I'd need to account for it all.
    • No HUD notification, or ammo refill sound. (Need to replicate, or make my own)
    • Bots hog these ammo piles for eternity with the ammo pile forcing their ammo counts, since they don't think their weapon is refilled. (and subsequently, they "idle")
  2. Weapon equips with SDKHook_WeaponEquipPost (a SDKHook_WeaponEquip is too slow)
    • A player equipping a weapon doesn't necessarily mean its from a source that refills ammo, so now I have more complexity to deal with on top of the hijacked ammo pile. (last thing I want)
    • I made a system that clamps reserve ammo to the desired max reserve counts incase the player picked up a dropped weapon ("item_pickup" game event), but that also means these:
      • Manually account for all places a player can get a weapon before I edit their "m_iExtraPrimaryAmmo" (and also determining if said event should clamp reserve ammo, not refill it), which is hooking all the relevant game events manually. ("spawner_give_item", "player_first_spawn", "item_pickup", "map_transition"... there could be more too)
      • Some game events only give strings and not entity index, so I needed to compare the string to the player's inventory. (I made a function called BestWeaponStringIndex() for this)

It just ain't pretty and a big mess, and I don't even know if that's the full list of the issues, there could be more but I rather not find out. Its currently more maintainable than its state with no use of detours, and I find it uneasy to be going back now.

Silvers 09-12-2021 08:23

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Ahh that makes sense. Good job :up: :bacon!:

mikaelangelis 09-13-2021 05:16

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
It only works when I pick up weapon, but not when I refill from Ammo stash
E.g: AK 200 reserve when picked up, but goes back to 360 when refill from ammo stash

Orinuse 09-13-2021 19:45

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Quote:

Originally Posted by mikaelangelis (Post 2757673)
It only works when I pick up weapon, but not when I refill from Ammo stash
E.g: AK 200 reserve when picked up, but goes back to 360 when refill from ammo stash

Mind showing me the list of plugins you have installed? (sm plugins list)

Additionally, is this on a dedicated or local server?

mikaelangelis 09-13-2021 21:36

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
1 Attachment(s)
Quote:

Originally Posted by Orinuse (Post 2757715)
Mind showing me the list of plugins you have installed? (sm plugins list)

Additionally, is this on a dedicated or local server?

I am on local host myself
here is the list of plugin I use

mikaelangelis 09-13-2021 22:28

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Nevermind I found my problem. It is the l4d2_upgradesreloaded.smx which caused the issue. Inside that plugin there is upgrade that enables extended ammo reserve for primary weapon. It is sad that If I love both your plugin and this one. Guess I have to choose. Just a reminder: Any reserve ammo related plugin like l4d2_guncontrol also conflicts with your plugin.

P.S: I wish you could update the feature of looting residual ammo of the same gun like guncontrol plugin. Anyway, nice plugin

Silvers 09-14-2021 15:19

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Suggestion: Change title to "Reserve Ammo Control" to make it clearer, when I opened the thread I didn't know what it meant.

Orinuse 09-15-2021 01:57

Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
 
Quote:

Originally Posted by mikaelangelis (Post 2757726)
Nevermind I found my problem. It is the l4d2_upgradesreloaded.smx which caused the issue. Inside that plugin there is upgrade that enables extended ammo reserve for primary weapon. It is sad that If I love both your plugin and this on.

Oh that's good to know. Conflicts were something I couldn't tell myself on how to worry about them, so I didn't bothered. At the very least for now, what I can do is probably setting up natives.

Quote:

Originally Posted by mikaelangelis (Post 2757726)
P.S: I wish you could update the feature of looting residual ammo of the same gun like guncontrol plugin. Anyway, nice plugin

Its this?
Spoiler

Gotta first make it clear that no promises its made within reasonable time expectations (Valve Time), but when it happens, the suggestion could be a separate plugin that uses this plugin's if-scenario natives. Would be in the same thread as this to let others post their plugins.

Quote:

Originally Posted by Silvers (Post 2757770)
Suggestion: Change title to "Reserve Ammo Control" to make it clearer, when I opened the thread I didn't know what it meant.

Done. :bee:


All times are GMT -4. The time now is 14:38.

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