Can i get Item or ItemDefinition object from BaseEntity?
Im trying to get this from hook OnHammerHit from HitInfo.HitEntity.GetItem(), but its always null. I want to know ingredients of object which i have hit. How can i to do that?
BaseEntity.GetItem() always returns null reference
Discussion in 'Rust Development' started by Typedef, Apr 10, 2016.
-
?Code:
if (info.HitEntity is BuildingBlock) { var block = (BuildingBlock) info.HitEntity; if (block?.blockDefinition.grades[(int)block.grade] == null) return; var cost = block.blockDefinition.grades[(int)block.grade].costToBuild as List<ItemAmount>; foreach (var itemAmount in cost) Puts("{0} {1}", itemAmount.itemid, itemAmount.amount); } -
Yes, this is the way to get ingredients if entity is building (foundation, wall, floor etc.). But if entity is for example wooden box this method won't work.
-
Look at the RemoverTool plugin.
-
RemoverTool cant get ingredients of objects. It sets with parameters. Like:
Besides, for any objects except buildings sets one price (deployable field).Code:"0": { "wood": "1" }, "1": { "wood": "100" }, "2": { "stones": "150", "wood": "100" }, "3": { "metal fragments": "75", "stones": "50", "wood": "100" }, "4": { "high quality metal": "25", "metal fragments": "75", "stones": "350", "wood": "250" }, "deployable": { "wood": "50" }
But i saw the plugin which returns a half of price to craft item which player have removed. For example for removing big wooden box player recieve wood x125 and metalfragments x5. The same for other items. But unfortunately it is paid
And there are no way to get source code( Attached Files:
Last edited by a moderator: Apr 11, 2016 -
-
Code:
if (info.HitEntity.GetComponentInParent<Deployable>()) { var deployable = info.HitEntity.GetComponentInParent<Deployable>(); var deployableName = deployable.name.Substring(deployable.name.LastIndexOf("/") + 1).Replace(".prefab", ""); foreach(var def in ItemManager.GetItemDefinitions()) { if (def.shortname == deployableName) { var bp = def.GetComponent<ItemBlueprint>(); if (bp) foreach(var ingredient in bp.ingredients) Puts("{0} {1}", ingredient.itemid, ingredient.amount); break; } } }Last edited by a moderator: Apr 11, 2016 -
Thank you a lot, bro! It will work with some manipulations

