Jump to content

Weaponry Stat Infinite Max Ammo Bug

Closed 1.7.4 1.7.6

Hi, the weaponry stat is currently bugged. It boosts mag size correctly the first time someone uses it. However, after each server restart or reload of plugin, the maxammo setting is multiplied again each time the plugin loads. I tried swapping the hook and it had the same result. Please see the video below:

https://files.markiii-rust.co.uk/monthly/xp_maxammo_bug.mp4

Edited by ZEODE

Share this comment


Link to comment

After looking into this more, I am noticing that the XPWeaponData.json file is being wiped on plugin load.

I added simple debug code to the plugin:

            try
            {
                Puts($"DEBUG: Loading WeaponData...");
                _weaponData = _WeaponData.ReadObject<WeaponData>();
                _weaponCache = _weaponData.WeaponRecords;
                Puts($"DEBUG: Loading WeaponData Done!");
            }
            catch
            {
                Puts($"DEBUG: Error, creating new WeaponData");
                _weaponData = new WeaponData();
            }

The console output:

XPerience was compiled successfully in 2570ms
Unloaded plugin XPerience v1.7.4 by MACHIN3
[XPerience] DEBUG: Loading WeaponData...
[XPerience] DEBUG: Error, creating new WeaponData
[XPerience] Checking Config for invalid settings..
[XPerience] Config Check Complete

For some reason the plugin is failing to load existing WeaponData, therefore it is catching the error and creating a new data. Then, when someone reloads their weapon with an already modified primaryMagazine.capacity, it saves this as the defaultammo amount in the data file, then each time calculates off this incorrect and increasing defaultammo value:

            if (!_weaponCache.ContainsKey(projectile.net.ID))
            {
                int defaultammo = projectile.primaryMagazine.capacity;

As we can see from your code, if the weapon is not in the WeaponData, then it adds it and initially uses the primaryMagazine.capacity as the defaultammo amount. This would be fine, but because the weapon is already modified, it creates this problem which is compounded each time the server restarts or plugin is reloaded.

Do you have any ideas why the WeaponData is failing to load? Thanks.

Edited by ZEODE

Share this comment


Link to comment

ok so the issue is due to the last major update and how they changed the ulong IDs to a NetworkableID so the storage method is not correct. I thought changing everything to the new NetworkableID would correct the issue and it loaded fine but it can't read the data correctly. I am working on a fix now

Share this comment


Link to comment
1.1m

Downloads

Total number of downloads.

5.7k

Customers

Total customers served.

83.1k

Files Sold

Total number of files sold.

1.6m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.