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.