Hello, I was wonderinhg how to get a players held item and than repair the condition on it.
How to get held item
HeldEntity heldEntity = player.GetHeldEntity() as HeldEntity;
if (heldEntity != null)
{
//Work out how to repair it.
} You would want to get the Item of the held entity since thats where durability etc is handled (if I'm not mistaken). Pretty sure you can do "player.GetActiveItem()".
Ok thank you, I have now worked it out. Though I am wondering how to check if the items health is already full or 100. I've tried
But that doesn't seem to work.
else if (heldEntity.Health() > 100)
{
PrintToChat("This item is already Repaired!");
} Try heldEntity.GetOwnerItem().condition.
or "player.GetActiveItem().condition" :)
Oh ok, well what if the player isn't holding anything? It seems to give me an error in console if i run the command with no active item.
Failed to call hook 'RepairCommand' on plugin 'Repairs v2.0.0' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.Repairs.RepairCommand (BasePlayer player, System.String Command, System.String[] args) [0x00079] in <3c7036e0347448819a28f0ed2480f34b>:0
at Oxide.Plugins.Repairs.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00032] in <3c7036e0347448819a28f0ed2480f34b>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <3606d2af539c45e4b5c61658e6a8b307>:0
1kb/s in, 2kb/s out
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <c2afd8354b8b4f3ca451cf5a1aa111c3>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <c2afd8354b8b4f3ca451cf5a1aa111c3>:0 You would need to handle that case with null checks.