fix: respect CustomWeapon ClipSize and preserve ammo on drop - #819
Conversation
|
The IsWeapon check was added in #763 by MS |
:( |
|
I’ll build it tomorrow, check for possible errors, verify that the changes are correct, and make the PR ready for review 🤓 |
d74890d to
148959f
Compare
|
fahhh |
There was a problem hiding this comment.
Pull request overview
This PR fixes CustomWeapon firearm spawning/giving/reloading so custom ClipSize is respected by the underlying firearm magazine cap, and so dropped weapons preserve the actual remaining ammo (issue #817).
Changes:
- Fixes an inverted firearm-type guard in
CustomWeapon.Spawn(Vector3, Player?)so firearms are actually spawned. - Raises the firearm magazine maximum to
ClipSizeacross spawn/give/reload flows to prevent base-game clamping back to default capacity. - Preserves actual magazine ammo when spawning a pickup from an existing firearm item (death/escape drops) by removing the unconditional refill to
ClipSize.
Bro i disabled you in setting why are you there |
louis1706
left a comment
There was a problem hiding this comment.
Other than this comment i will approved it (i will approve it if there a good reason would still try to found to make it work without setting it at every reload)
…red instead of on every reload
* fix: respect CustomWeapon ClipSize and preserve ammo on drop (#817) * fix(CustomItems): re-assert CustomWeapon ClipSize capacity in OnAcquired instead of on every reload

Description
Describe the changes
Fixes three defects in
CustomWeaponthat caused custom weapon configuration to be silently lost (issue #817).What is the current behavior? (You can also link to an open issue here)
Closes #817.
ClipSizelarger than the stock magazine is silently truncated.firearm.MagazineAmmo = ClipSizewrites toMagazineModule.SyncDatabut the base game still caps the magazine atAmmoMax = _defaultCapacity + attachmentModinOnAdded,ServerLoadAmmoFromInventory, andOnAttachmentsApplied. Nothing inCustomWeaponraised_defaultCapacity, so reload / give / respawn truncate back to stock.ClipSize. The drop path (CustomItem.OnInternalOwnerDying->Spawn(Vector3, Item, Player?)) unconditionally wrotefirearm.MagazineAmmo = ClipSize, discarding the player's actual round count.CustomWeapon.Spawn(Vector3, Player?)returnsnullfor every firearm. The type guard introduced in fix: Item leaks #763 is inverted relative to its log message:if (Type.IsWeapon(false))returns null when the type IS a firearm.What is the new behavior? (if this is a feature change)
Firearm.MaxMagazineAmmo(which writes_defaultCapacity) toClipSizeinSpawn,Spawn(Item),Give, andOnInternalReloadedso the custom value survives every base-game clamp.MagazineAmmo = ClipSizewrite inSpawn(Vector3, Item, Player?)so the dropped pickup preserves whatever ammo the player actually had on death/escape. Initial-fill semantics stay in the no-Itemoverload and inGive.Spawn(Vector3, Player?)so it matches its log message and the method actually runs for firearms.Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No.
Other information:
N/A.
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other