Jump to content

Custom item


Recommended Posts

You use setmultisymbolexchange like the example below

local function OnEquip(inst, owner)

owner.AnimState:OverrideSymbol("swap_object", "swap_wand_wristbow", "wand")
        owner.AnimState:SetMultiSymbolExchange("swap_object", "hand")

end

local function OnUnequip(inst, owner)

owner.AnimState:ClearSymbolExchanges()

end

Link to comment
Share on other sites

For characters to spawn with the item usually you put the prefab name in the start_inv in the character lua like this:

local start_inv = {
    "wand_weapon",
}

and for the item only to have the character only equip it put this in the weapon lua:

inst.components.inventoryitem.onputininventoryfn = function(inst, player)
    if not player:HasTag("acharactertaginyourcharacterlua")  then
    inst:DoTaskInTime(0.1, function()
    player.components.inventory:DropItem(inst)
    end)
    end
    end

last he can't drop it well Idk how to do, heard the golem mod has something your looking for.

Link to comment
Share on other sites

Man I hate this format, either way you have quite a bit of errors especially that components are being called when they haven't been initialized.

local function MakeSword(gauntlets, damage)
    local assets =
    {
        Asset("ANIM", "anim/gauntlets.zip"),
        Asset("ANIM", "anim/swap_gauntlets.zip"),
        Asset("IMAGE", "images/inventoryimages/gauntlets.tex"),
        Asset("ATLAS", "images/inventoryimages/gauntlets.xml"),
        Asset("ANIM", "anim/gloves_leather.zip")
    }

   local function onequip(inst, owner)
    inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")

inst.components.inventoryitem.cangoincontainer = false
    if inst.skin_build_name ~= nil then
 owner.AnimState:OverrideSymbol("hand", inst.skin_build_name, "hand" )
  else owner.AnimState:OverrideSymbol("hand", "gloves_leather", "hand")

  end
    owner:AddTag("thorny_protection")
    inst.equipped = true
    inst.owner = owner.userid
--owner.components.combat:SetAttackPeriod(15)
 end

 local function onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("hand")
    owner:RemoveTag("thorny_protection")
  
   inst.equipped = false
    inst.owner = nil
--owner.components.combat:SetAttackPeriod(.1)
end
   

    local function onattack(inst, attacker, target)
     
    if  attacker.components.health then attacker.components.health:DoDelta(-20)
 
     end
 
 
end
    
    
    
    
    
    
    local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("gloves")
    inst.AnimState:SetBuild("gloves_leather")
    inst.AnimState:PlayAnimation("idle")
    inst:AddTag("gloves")
    inst:AddTag("punch")

    inst:AddTag("gloves")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end


    
        inst:AddComponent("weapon")
        inst.components.weapon:SetDamage(200) --the code is used to set damage  
   inst.components.weapon:SetOnAttack(onattack)
   
        
        inst:AddComponent("inspectable")

        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/gauntlets.xml"
        inst.components.inventoryitem.imagename = "gauntlets"

inst.components.inventoryitem.onputininventoryfn = function(inst, player)
    if not player:HasTag("acharactertaginyourcharacterlua")  then
    inst:DoTaskInTime(0.1, function()
    player.components.inventory:DropItem(inst)
    end)
    end
   end

        inst:AddComponent("equippable")
        inst.components.equippable:SetOnEquip(onequip)
        inst.components.equippable:SetOnUnequip(onunequip)
        

        MakeHauntableLaunch(inst)

        return inst
    end
    return Prefab( "common/inventory/gauntlets", fn, assets)
end

return MakeSword("gauntlets",20)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...