Data Driven Items Question

edited September 2015 in Questions

I need to make an item that people can carry but can't use unless they meet the intelligence requirement. I managed to apply the modifier directly to the hero when the item is picked up but i can't seem to find a way to remove the modifier when the item is dropped.

Does anyone have any suggestions?

my function

function ItemCheck( event )
    local itemName = event.ability:GetAbilityName()
    local hero = EntIndexToHScript( event.caster_entindex )
    local itemTable = GameMode.ItemInfoKV[itemName]
    print("Checking Restrictions for "..itemName)
    DeepPrintTable(itemTable)

    -- if there is no subtable for this item, end this script
    if itemTable == nil then
        print("no subtable for this item!")
        return true
    end

    -- This timer is needed because OnEquip triggers before the item actually being in inventory
    Timers:CreateTimer(0.1,function()
        -- Go through every item slot
        for itemSlot = 0, 5, 1 do 
            local Item = hero:GetItemInSlot( itemSlot )
            --print("test1")
            --print(item)
            -- When we find the item we want to check
            if Item ~= nil and itemName == Item:GetName() then
                DeepPrintTable(Item)

                -- Check Int Restriction
                if itemTable.intRequired then
                    --print("Name","int Req","Hero Int")
                    --print(itemName,itemTable.intRequired,hero:GetIntellect())
                    -- If the hero doesn't met the int required, show message and disable item
                    if itemTable.intRequired > hero:GetIntellect() then
                        FireGameEvent( 'custom_error_show', { player_ID = pID, _error = "You need int "..itemTable.intRequired.." to use this." } )
                        --DropItem(Item, hero)                      
                    else
                        print("applying data driven modifier")
                        Item:ApplyDataDrivenModifier( hero, hero, itemTable.Modifiers, {duration=-1} )
                    end
                end

            end
        end
    end)
end

My Item

"item_storage_cell"
    {
        "ID"                            "1250" // anything above 1250 should be safe to use.
        "BaseClass"                     "item_datadriven"
        "AbilityTextureName"            "item_storage_cell"

        "ItemCost" "500"
        "ItemKillable" "0" 
        "ItemSellable" "1"
        "ItemPurchasable" "1"
        "ItemDroppable" "1"


        "ItemStockMax" "10"
        "ItemStockTime" "180"
        "ItemStockInitial" "0"

        "ItemShareability" "ITEM_FULLY_SHAREABLE"

        "ItemAliases" "Storage Cell"
        "ItemDeclarations" "DECLARE_PURCHASES_TO_TEAMMATES"

        "OnEquip" 
        {   
            "RunScript"
            {
                "ScriptFile"    "scripts/vscripts/itemfunctions.lua"
                "Function"  "ItemCheck"
            }
        }

        "OnOwnerDied"
        {
            "RunScript"
            {
                "ScriptFile"    "scripts/vscripts/itemfunctions.lua"
                "Function"  "DropItemOnDeath"
            }
        }
        "Modifiers"
        {
            "modifier_item_storagecell_datadriven"
            {
                "Passive"   "0"
                "IsHidden"   "1"
                "Attributes"   "MODIFIER_ATTRIBUTE_MULTIPLE"    
                "Properties"
                {
                    "MODIFIER_PROPERTY_MANA_BONUS"  "250"
                }
            }
        }


    }

    }

my data table

"Items"
{
    "item_storage_cell" //change it to a custom items
    {
        "intRequired" "105" 
        "Modifiers" "modifier_item_storagecell_datadriven"          
    }   
}

Comments

  • edited September 2015 Posts: 8

    OnUnequip not listed in wiki. gg wp valve

  • edited September 2015 Posts: 130

    you could use: DOTA_UNIT_ORDER_DROP_ITEM in FilterExecuteOrder, but it will probably remove the modifier before the item is dropped.
    aside from that, there might be some item dropped events that you can listen to here: https://developer.valvesoftware.com/wiki/Dota_2_Workshop_Tools/Scripting/Built-In_Engine_Events
    not sure though, never touched items before

    edit: according to Noya's datadriven abilities thread, it is working, just not listed lol

    OnUnequip (not listed in the wiki)

  • edited September 2015 Posts: 8

    I've got this so far for my function:

    function RemoveItemModifierStats( event )
        local itemName = event.ability:GetAbilityName()
        local hero = EntIndexToHScript( event.caster_entindex )
        local itemTable = GameMode.ItemInfoKV[itemName]
    
        -- if there is no subtable for this item, end this script
        if itemTable == nil then
            print("no subtable for this item!")
            return true
        end
    
        Item:ApplyDataDrivenModifier( hero, hero, itemTable.ModifiersRemove, {duration=-1} )    
    
    end
    

    I'm having trouble getting the Item object.

    Normally, I iterate through the inventory and grab the item like this: (line 3)

    -- Go through every item slot
            for itemSlot = 0, 5, 1 do 
                local Item = hero:GetItemInSlot( itemSlot )
                --print("test1")
                --print(item)
                -- When we find the item we want to check
                if Item ~= nil and itemName == Item:GetName() then
                    --DeepPrintTable(Item)
    
                    -- Check Int Restriction
                    if itemTable.intRequired then
                        --print("Name","int Req","Hero Int")
                        --print(itemName,itemTable.intRequired,hero:GetIntellect())
                        -- If the hero doesn't met the int required, show message and disable item
                        if itemTable.intRequired > hero:GetIntellect() then
                            FireGameEvent( 'custom_error_show', { player_ID = pID, _error = "You need int "..itemTable.intRequired.." to use this." } )
                            --DropItem(Item, hero)                      
                        else
                            print("applying data driven modifier")
                            Item:ApplyDataDrivenModifier( hero, hero, itemTable.ModifiersAdd, {duration=-1} )
                        end
                    end
    
                end
            end
    

    but since the item is no longer in the inventory, i can't do it this way.

    any ideas?

  • the solution was to use event.ability