Hey
I'm getting this weird error when I use Entity.Kill();
Here's a short version of what I'm doing:
Code:void OnHammerHit(BasePlayer player, HitInfo info) { if (info.HitEntity.GetComponent<BuildingBlock> != null) if(!info.HitEntity.isDestroyed) info.HitEntity.Kill(BaseNetworkable.DestroyMode.None); }
For some reason, when I then hit a structure (eg twig wall) with a hammer, I get disconnected from the server with the error "RPC Error: playerattack", and a NullReferenceException in the console.
Any ideas?
Edit: I should also mention, despite this not working with my plugin, RemoverTool works fine which afaik is using pretty much the same code.
Solved RPC Error: playerattack
Discussion in 'Rust Development' started by PsychoTea, Dec 11, 2016.
-
Wulf Community Admin
I wouldn't assume that HitEntity is always valid, so I'd add a null check for that.
-
I added a null check
Code:if (info.HitEntity != null) info.HitEntity.Kill(...);
[DOUBLEPOST=1481495153][/DOUBLEPOST]I wonder, is Entity.Kill() the 'proper' way of destroying a structure/buildingblock or is there a better way of doing it? -
The default destroy mode is none so I removed that, but it doesn't make a difference. Killing the entity next frame seems to work fine.
Code:void OnHammerHit(BasePlayer player, HitInfo info) { if (info.HitEntity != null) if (!info.HitEntity.isDestroyed) { NextFrame(() => { info.HitEntity.Kill(); }); } }
-
Please mark as solved. -
No problem also you should be able to mark it as solved yourself there is a ctrl + f and search for thread tools and edit the title.