Jump to content

item only working once? not sure why


Recommended Posts

Hello and thanks for looking GL

 

local assets=
{
Asset("ANIM", "anim/wouhat.zip"),
Asset("ANIM", "anim/swap_wouhat.zip"),
Asset("ATLAS", "images/inventoryimages/wouhat.xml"),
Asset("IMAGE", "images/inventoryimages/wouhat.tex"),
}
prefabs = {

}

local function doeffects(inst, pos)
SpawnPrefab("statue_transition").Transform:SetPosition(pos:Get())
SpawnPrefab("statue_transition_2").Transform:SetPosition(pos:Get())
end

local function poof (inst, owner)
local owner = inst.components.inventoryitem.owner
if not owner.components.inventory:Has("petals", 2) then
if owner.components.talker then
owner.components.talker:Say("You... Oink... YOU ate Our Flowers")

return true
end
end

local pt = inst:GetPosition()
local theta = math.random() * 2 * PI
local radius = math.random(3, 6)
local offset = FindWalkableOffset(pt, theta, radius, 12, true)


if offset then
local image = SpawnPrefab("bunnyman")
local pos = pt + offset
image.Transform:SetPosition(pos:Get())
doeffects(inst, pos)
image.components.follower:SetLeader(owner)
inst.SoundEmitter:PlaySound("dontstarve/maxwell/shadowmax_appear")
owner.components.sanity:DoDelta(-10)
return
end
end

local function OnEquip(inst, owner)
owner.AnimState:OverrideSymbol("swap_hat", "swap_wouhat", "swap_wouhat")
owner.AnimState:Show("HAT")
owner.AnimState:Show("HAT_HAIR")
owner.AnimState:Hide("HAIR_NOHAT")
owner.AnimState:Hide("HAIR")

if owner:HasTag("player") then
owner.AnimState:Hide("HEAD")
owner.AnimState:Show("HEAD_HAIR")
end
end

local function OnUnequip(inst, owner)
owner.AnimState:Hide("HAT")
owner.AnimState:Hide("HAT_HAIR")
owner.AnimState:Show("HAIR_NOHAT")
owner.AnimState:Show("HAIR")

if owner:HasTag("player") then
owner.AnimState:Show("HEAD")
owner.AnimState:Hide("HEAD_HAIR")
end
end
local function fn()
local inst = CreateEntity()
local trans = inst.entity:AddTransform()
local anim = inst.entity:AddAnimState()
local sound = inst.entity:AddSoundEmitter()
MakeInventoryPhysics(inst)

anim:SetBank("wouhat")
anim:SetBuild("wouhat")
anim:PlayAnimation("idle")

local minimap = inst.entity:AddMiniMapEntity()
minimap:SetIcon("wouhat.tex")

inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "wouhat"
inst.components.inventoryitem.atlasname = "images/inventoryimages/wouhat.xml"
--
inst:AddTag("hat")

inst:AddComponent("equippable")
inst.components.equippable:SetOnEquip( OnEquip )
inst.components.equippable:SetOnUnequip( OnUnequip )
inst.components.equippable.equipslot = EQUIPSLOTS.HEAD

inst:AddComponent("useableitem")
inst.components.useableitem:SetOnUseFn(poof)

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

 

This item only lets me use it once then, i have to log out and back on before the Use command shows back up  What am i missing or need to do ???

 

Any advise would be Helpful Thanks

Oh and i tired to use stuff like owner.components.useableitem:StopUsingItem() and learn from the components Thread Thanks Mobbstar but i am unable to get it working

 

Link to item:  wouhat.lua

Link to comment
Share on other sites

Since your item is not in use over an undefined time, you could adapt the component to your need by setting caninteractfn to

 

funtion canuse(inst)

    return inst.components.equippable.isequipped

end

 

which removes "inuse" from the conditions.

 

Let me know if it works!

Link to comment
Share on other sites

Since your item is not in use over an undefined time, you could adapt the component to your need by setting caninteractfn to

 

funtion canuse(inst)

    return inst.components.equippable.isequipped

end

 

 

Let me know if it works!

 It Works Added a

  local function canuse(inst)

    return inst.components.equippable.isequipped

end

 

and

 inst.components.useableitem:SetCanInteractFn (canuse)

 

Thanks Much

 

This Char im working on is getting closer,(Thinking about just posting it as a WIP)   

 Now to add when u trade the Hat a rabbit it spawns rabbits a bunnyman tail it spawns  bunnyman  was looking in to Birdcage for ideas how to do this,,

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...