Jump to content

Music issues


Recommended Posts

I'm truing to make item, wich while equipped plays sound. It's working, and plays music, but it plays even when item not equipped. I know that I need to add smthinf to onunequip function, but i don't know what :p

local assets =
{
    Asset("ANIM", "anim/myamulets.zip"),
	Asset("ANIM", "anim/torso_myamulets.zip"),
	Asset("ATLAS", "images/inventoryimages/floweramulet.xml"),
	Asset("IMAGE", "images/inventoryimages/floweramulet.tex"),
	Asset("SOUND", "sound/ghost.fsb"),
}

local function onequip(inst, owner)
   owner.AnimState:OverrideSymbol("swap_body", "torso_myamulets", "floweramulet")
   owner.SoundEmitter:PlaySound("dontstarve/ghost/ghost_girl_howl_LP")
end

local function onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
	
	--inst.hauntsfxtask:Cancel()
    --inst.hauntsfxtask = nil
end


local function fn()
	local inst = CreateEntity()

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

	MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("amulets")
    inst.AnimState:SetBuild("myamulets")
    inst.AnimState:PlayAnimation("floweramulet")
	
    inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end


    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = FUELTYPE.MAGIC
    inst.components.fueled:InitializeFuelLevel(TUNING.RAINCOAT_PERISHTIME * 0.5)
    inst.components.fueled:SetDepletedFn(inst.Remove)
	
	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "floweramulet"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/floweramulet.xml"

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.NECK or EQUIPSLOTS.BODY
	inst.components.equippable.dapperness = TUNING.DAPPERNESS_HUGE*2 ---
	inst.components.equippable.walkspeedmult = 0

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

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab( "floweramulet", fn, assets, prefabs)

 

  • Like 1
Link to comment
Share on other sites

This should work

--In onequip change this:
owner.SoundEmitter:PlaySound("dontstarve/ghost/ghost_girl_howl_LP")
--to this:
owner.SoundEmitter:PlaySound("dontstarve/ghost/ghost_girl_howl_LP", "ghosthowl")

--and in the onunequip put this:
owner.SoundEmitter:KillSound("ghosthowl")

 

Edited by Aquaterion
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...