Jump to content

Weaponry Stat Infinite Max Ammo Bug

Closed 1.7.4 1.7.6

ZEODE
ZEODE

Posted (edited)

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
ZEODE

Posted (edited)

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
MACHIN3

Posted

Changed Status from Pending to Work in Progress

MACHIN3

Posted

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

MACHIN3

Posted

I got it fixed and will release a beta in discord shortly

  • Like 1
MACHIN3

Posted

Changed Status from Work in Progress to Closed

Changed Fixed In to Next Version

ZEODE

Posted

Thank you, all good. 

1.4m

Downloads

Total number of downloads.

6.9k

Customers

Total customers served.

102.3k

Files Sold

Total number of files sold.

2m

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.