...as there can be thousands of backpacks in \data on wipe depending on how active a server is and plugins used.
Disable Backpacks for NPCSuggestion
In response to Findles ():...as there can be thousands of backpacks in \data on wipe depending on how active a server is and p...
This should fix it.
public static Backpack LoadOrCreate(ulong id)
{
if (_backpacks.ContainsKey(id))
return _backpacks[id];
Backpack backpack = null;
if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{_instance.DataFileName}/{id}"))
LoadData(ref backpack, $"{_instance.DataFileName}/{id}");
else
{
backpack = new Backpack(id);
if (id < 2147483647) return null;
SaveData(backpack, $"{_instance.DataFileName}/{id}");
}
_backpacks.Add(id, backpack);
return backpack;
} Thanks for this fix. I got a NRE in OnEntityDeath when killing Scarecrows. A check for HTNPlayer in OnEntityDeath fixed it.
private void OnEntityDeath(BaseCombatEntity victim, HitInfo info)
{
if (victim is BasePlayer && !(victim is NPCPlayer) && !(victim is HTNPlayer))
{
var player = (BasePlayer)victim;
var backpack = Backpack.LoadOrCreate(player.userID);
backpack.ForceClose();
if (Configuration.EraseOnDeath)
backpack.EraseContents();
else if (Configuration.DropOnDeath)
backpack.Drop(player.transform.position);
}
} OMG, i just manually deleted 500Mo of empty backpacks from the http://FTP. Being new to c#, could you tell me where I should insert this code?
Hey,
Today i look in the datafolder and see that there are many of backpackfiles for NPC's.
Maybe you can bring a check in that this not happens?
Today i look in the datafolder and see that there are many of backpackfiles for NPC's.
Maybe you can bring a check in that this not happens?
After doing the fix posted by Default I get this in console.
Failed to call hook 'OnEntityDeath' on plugin 'Backpacks v2.1.6' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.Backpacks.OnEntityDeath (BaseCombatEntity victim, HitInfo info) [0x00029] in :0
at Oxide.Plugins.Backpacks.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00282] in :0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0Merged post
@Default Do you have any ideas how I can get rid of the NRE I'm having after changing the .cs as you posted above?
Thanks!
In response to Trillz ():After doing the fix posted by Default I get this in console.
Failed to call hook 'OnEnti...
This is OnEntityDeath.
I don't think I changed this at all, rather someone else posting that fix.
The only thing you should need is the one I posted, and nothing to do with OnEntityDeath.
I haven't taken a look at this in forever, but I'll investigate this a little further.
Thanks for the quick reply! I have changed nothing other than what you posted above.
if (id < 2147483647) return null;
public static Backpack LoadOrCreate(ulong id)
{
if (_backpacks.ContainsKey(id))
return _backpacks[id];
Backpack backpack = null;
if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{_instance.DataFileName}/{id}"))
LoadData(ref backpack, $"{_instance.DataFileName}/{id}");
else
{
backpack = new Backpack(id);
if (id < 2147483647) return null;
SaveData(backpack, $"{_instance.DataFileName}/{id}");
}
_backpacks.Add(id, backpack);
return backpack;
}
}
Thank you sir!
+1
This is needed badly.
Love the plugin but the amount of npc backpack data files is wow.
This is needed badly.
Love the plugin but the amount of npc backpack data files is wow.
You guys can also take a look at my post above. I am using it this way for along time without any issues.
There may be better solutions, but in the meantime...
There may be better solutions, but in the meantime...
I am guessing these edits need to be made to the CS file.
Both posted code changes/additions?
Both posted code changes/additions?
- 1
- 2