1. Code:
    function PLUGIN:OnHammerHit(player,info)
     end
    I can get info.HitEntity.gameObject.name, but how do i find the item id or short prefab name?
    [DOUBLEPOST=1449541146][/DOUBLEPOST]Or how do i attempt to get GetItem() from info?
    [DOUBLEPOST=1449547161,1449536688][/DOUBLEPOST]Ahah..cmon anyone
     
  2. I'm not sure, but try add BaseEntity entity into function itself.
     
  3. Calytic

    Calytic Community Admin Community Mod

    Code:
    info.Weapon.GetOwnerItemDefinition()
     
  4. 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).
     
  5. Calytic

    Calytic Community Admin Community Mod

    Oh, I thought you wanted the hammer, not the HitEntity.

    try HitEntity.GetItem()
     
  6. If I have time I take a look that when I'm at home.
     
  7. 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);
                        }
                    }
                }
            }
    @Reneb Welp! :D
     
    Last edited by a moderator: Dec 9, 2015
  8. Calytic

    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);
    }
    
    All that does is store a itemid list keyed by prefab paths, this is then referenced when attempting retrieve the itemid by prefab path.
     
  9. so how do we do it? from HitEntity?
     
  10. Calytic

    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);
         }
    }
    Then do something like this with HitEntity

    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
          }
    }
    
    You'll have to work out how that translates to LUA or find one of those helpful LUA developers =)
     
  11. That was the trick, i was able to convert that code to LUA, thanks everyone.