Facepunch / garrysmod-requests

Feature requests for Garry's Mod
84 stars 24 forks source link

Official ammo limit implemented #1100

Closed BreakinBenny closed 6 years ago

BreakinBenny commented 6 years ago

It's probably just me, but I believe the ammo limit being uncapped without using add-ons is a little insane. I feel like we miss the limit built into Half-Life 2 and its various games, though they all use skmax%weaponammo% which are probably clientside.

If you add it, be sure to make it disabled by default!

robotboy655 commented 6 years ago

If we disable something by default, what's the point of adding it? The ammo limit is capped at 9999.

BreakinBenny commented 6 years ago

It's mainly for convenience reasons, or proper roleplaying (take that what you will, though). The HL2 limits should be the default, but the admin should also be able to change it serverside.

Of course, it would be pretty fun to just be able to remove all weapons and ammo with a simple click… and optionally, the HEV suit. (Speaking of HEV suit, would you kindly make the suitvolume command work again? That sound is pretty damn annoying and TV Tropes agrees.)

Kefta commented 6 years ago

Could ammo limits at least work for ammo types that declare a max?

robotboy655 commented 6 years ago

From one side I agree, but from another, do we really want to change this behavior? Mods can (and do) implement their own ammo limits if it is necessary, and changing this might bring unexpected behavior to existing mods. What if a Sandbox user wants to have 9999 ammo, and not be limited by a random value set by a modder when it didn't really affect actual maximum ammo count?

Kefta commented 6 years ago

Doing it with mods is still not 100% accurate since it does not affect engine calls to GiveAmmo - if there were a hook for that, I could see it replacing ammo limits.

robotboy655 commented 6 years ago

If we were to add a hook for ammo count change, when should it be called? When it is changed from Lua? What about when weapon reloads? What arguments/return values should it have? Do we add separate hook for ammo removal? What should happen with RemoveAllAmmo()?

Kefta commented 6 years ago

One hook, PlayerChangeAmmo( Player pPlayer, number iAmmoAmount, number iAmmoIndex ), which returns a number for the new amount. nil return means stick with iAmmoAmount's value. iAmmoAmount will be positive for ammo gains and negative for losses.

The hook will be called after the iAmmoIndex check in CBaseCombatCharacter::GiveAmmo (the integer index version), after the iCount check in CBaseCombatCharacter::RemoveAmmo, and for every iteration of CBaseCombatCharacter::RemoveAllAmmo (-m_iAmmo[iAmmoIndex] can be used as the value for iAmmoAmount here, and retNum + m_iAmmo[iAmmoIndex] for the m_iAmmo.Set call).

If the hook returns <= 0 in GiveAmmo or >= 0 in Remove(All)Ammo, the function returns (or the loop continues) before m_iAmmo is set or any sounds are played. That should allow for every kind of ammo manipulation in Lua, including infinite ammo and max carry limits.

robotboy655 commented 6 years ago

RemoveAllAmmo() may lose its functionality in this case is my worry.

Kefta commented 6 years ago

I guess RemoveAllAmmo could just skip the hook and just strip all ammo unconditionally.

robotboy655 commented 6 years ago

I am also not sure how useful delta of ammo would be, I am thinking more towards oldValue, newValue where you can just domath.min(newValue,game.GetAmmoMax(type))

Kefta commented 6 years ago

Yeah, that would be a bit more intuitive. I just used the delta since GiveAmmo passes it