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

[L4D/L4D2] Reserve (Ammo) Control [20-Jan-2021]


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Orinuse
Junior Member
Join Date: Aug 2021
Plugin ID:
7791
Plugin Version:
1.1
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Individually control weapons's reserve counts independent of the ammo_* cvars.
    Old 09-11-2021 , 17:03   [L4D/L4D2] Reserve (Ammo) Control [20-Jan-2021]
    Reply With Quote #1

    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 (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.
    Attached Files
    File Type: zip l4d_reservecontrol_v1.1.zip (11.3 KB, 927 views)

    Last edited by Orinuse; 01-19-2022 at 15:56. Reason: v1.1 - thread title and other details
    Orinuse is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 09-11-2021 , 17:35   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #2

    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;

    __________________
    Silvers is offline
    Orinuse
    Junior Member
    Join Date: Aug 2021
    Old 09-12-2021 , 04:33   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #3

    Quote:
    Originally Posted by Silvers View Post
    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.

    Last edited by Orinuse; 09-12-2021 at 04:34. Reason: addendum
    Orinuse is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 09-12-2021 , 08:23   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #4

    Ahh that makes sense. Good job
    __________________
    Silvers is offline
    mikaelangelis
    Senior Member
    Join Date: Oct 2017
    Old 09-13-2021 , 05:16   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #5

    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
    mikaelangelis is offline
    Orinuse
    Junior Member
    Join Date: Aug 2021
    Old 09-13-2021 , 19:45   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #6

    Quote:
    Originally Posted by mikaelangelis View Post
    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?

    Last edited by Orinuse; 09-13-2021 at 19:48.
    Orinuse is offline
    mikaelangelis
    Senior Member
    Join Date: Oct 2017
    Old 09-13-2021 , 21:36   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #7

    Quote:
    Originally Posted by Orinuse View Post
    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
    Attached Thumbnails
    Click image for larger version

Name:	plugin.PNG
Views:	287
Size:	54.3 KB
ID:	191381  
    mikaelangelis is offline
    mikaelangelis
    Senior Member
    Join Date: Oct 2017
    Old 09-13-2021 , 22:28   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #8

    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

    Last edited by mikaelangelis; 09-13-2021 at 22:41.
    mikaelangelis is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 09-14-2021 , 15:19   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #9

    Suggestion: Change title to "Reserve Ammo Control" to make it clearer, when I opened the thread I didn't know what it meant.
    __________________
    Silvers is offline
    Orinuse
    Junior Member
    Join Date: Aug 2021
    Old 09-15-2021 , 01:57   Re: [L4D/L4D2] Reserve Control [12-Sep-2021]
    Reply With Quote #10

    Quote:
    Originally Posted by mikaelangelis View Post
    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 View Post
    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 View Post
    Suggestion: Change title to "Reserve Ammo Control" to make it clearer, when I opened the thread I didn't know what it meant.
    Done.
    Orinuse is offline
    Reply


    Thread Tools
    Display Modes

    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 17:25.


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