I can get info.HitEntity.gameObject.name, but how do i find the item id or short prefab name?Code:function PLUGIN:OnHammerHit(player,info) end
[DOUBLEPOST=1449541146][/DOUBLEPOST]Or how do i attempt to get GetItem() from info?
[DOUBLEPOST=1449547161,1449536688][/DOUBLEPOST]Ahah..cmon anyone
Getting ItemID of HitEntity?
Discussion in 'Rust Development' started by Rusty, Dec 8, 2015.
-
I'm not sure, but try add BaseEntity entity into function itself.
-
Calytic Community Admin Community Mod
Code:info.Weapon.GetOwnerItemDefinition()
-
Ill try that, but essentially what i am trying to accomplish is, when i hit a workbench with a hammer, i need to get the item name, box.repair.bench instead of the prefab name that i am getting with info.HitEntity.gameObject.name (assets\blah\blah\workbench_deployed).
-
Calytic Community Admin Community Mod
Oh, I thought you wanted the hammer, not the HitEntity.
try HitEntity.GetItem() -
-
Didnt work...can someone unmark this one as solved? i really need help
[DOUBLEPOST=1449618369][/DOUBLEPOST]maybe another function to find item name shortname based on info.HitEntity.gameObject.name ??
[DOUBLEPOST=1449621051][/DOUBLEPOST]Maybe this is the key? But how to in lua?
Code:private void InitializeTable() { displaynameToShortname.Clear(); deployedToItem.Clear(); List<ItemDefinition> ItemsDefinition = ItemManager.GetItemDefinitions() as List<ItemDefinition>; foreach (ItemDefinition itemdef in ItemsDefinition) { displaynameToShortname.Add(itemdef.displayName.english.ToString().ToLower(), itemdef.shortname.ToString()); if (itemdef.GetComponent<ItemModDeployable>() != null) deployedToItem.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, itemdef.itemid); } }static void Refund(BasePlayer player, BaseEntity entity, RemoveType removeType) { if (removeType == RemoveType.All) return; if (refundDeployable && entity.GetComponentInParent<Deployable>() != null) { Deployable worlditem = entity.GetComponentInParent<Deployable>(); if (deployedToItem.ContainsKey(worlditem.gameObject.name)) player.inventory.GiveItem(deployedToItem[worlditem.gameObject.name], 1, true); } else if (refundStructure && entity is BuildingBlock) { BuildingBlock buildingblock = entity as BuildingBlock; if (buildingblock.blockDefinition == null) return; int buildingblockGrade = (int)buildingblock.grade; if (buildingblock.blockDefinition.grades[buildingblockGrade] != null && refundPercentage.ContainsKey(buildingblockGrade.ToString())) { decimal refundRate = decimal.Parse((string)refundPercentage[buildingblockGrade.ToString()]) / 100.0m; List<ItemAmount> currentCost = buildingblock.blockDefinition.grades[buildingblockGrade].costToBuild as List<ItemAmount>; foreach (ItemAmount ia in currentCost) { player.inventory.GiveItem(ia.itemid, Convert.ToInt32((decimal)ia.amount * refundRate), true); } } } }
Last edited by a moderator: Dec 9, 2015 -
Calytic Community Admin Community Mod
Code:foreach (ItemDefinition itemdef in ItemsDefinition) { displaynameToShortname.Add(itemdef.displayName.english.ToString().ToLower(), itemdef.shortname.ToString()); if (itemdef.GetComponent<ItemModDeployable>() != null) deployedToItem.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, itemdef.itemid); }
-
so how do we do it? from HitEntity?
-
Calytic Community Admin Community Mod
Well, you take this code
Code:Dictionary<string, int> deployedToItem = new Dictionary<string, int>();void OnServerInitialized() { List<ItemDefinition> ItemsDefinition = ItemManager.GetItemDefinitions() as List<ItemDefinition>; foreach (ItemDefinition itemdef in ItemsDefinition) { if (itemdef.GetComponent<ItemModDeployable>() != null) deployedToItem.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, itemdef.itemid); } }
Code:void OnHammerHit(BasePlayer player, HitInfo info) { if(deployedToItem.ContainsKey(info.HitEntity.name)) { int itemid = deployedToItem[info.HitEntity.name]; ItemDefinition def = ItemManager.FindItemDefinition(itemid); // do something } }
-
That was the trick, i was able to convert that code to LUA, thanks everyone.