View Single Post
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