Page 1 of 1

onUse - playsound

Posted: Wed Dec 17, 2014 11:38 am
by bongobeat
Hello,
how to define an item that play a sound (like the horn) when normally used ?

the secondary option works great, the primary don't:
SpoilerShow

Code: Select all

defineObject{
	name = "charming_flute",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/flute.fbx",
		},
		{
			class = "Item",
			uiName = "Charming Flute",
			gfxIndex = 316,
			weight = 0.3,
			description = "A sharpened flute made of unknown material.",
-- sound primary
			onUse = function(self) -- wrong definition?
				playSound("flute01")
                                end,
			secondaryAction = "fear",
			impactSound = "impact_blunt",
		},
		{
			class = "CastSpell",
			name = "fear",
			uiName = "Cause Fear",
			charges = 12,
			buildup = 2,
			energyCost = 10,
			spell = "cause_fear",
			requirements = { "concentration", 3 },
			onAttack = function(self)
				playSound("flute02")
			end,
		},

	},
}

Re: onUse - playsound

Posted: Wed Dec 17, 2014 4:57 pm
by Batty
Remove the onUse function from the Item class then add this class:

Code: Select all

{
   class = "UsableItem",
   onUseItem = function(self)
      playSound("flute01")
      return false
   end
},
Tested it quickly with a different sound, it works. You have to return false otherwise the champion will eat the flute. :lol:

Nice idea for an item! :)

Re: onUse - playsound

Posted: Thu Dec 18, 2014 12:01 am
by bongobeat
thanks :)

Re: onUse - playsound

Posted: Thu Dec 18, 2014 12:47 am
by Eleven Warrior
Hi guys I am also trying this flute out. The 1st sound plays but the secondary actions are not working. Here is the code I have ATM. I am not sure what I am doing wrong surely it's something simple Yeah? The sounds will change to later, this is just a testing item ..

Code: Select all

defineObject{
name = "charming_flute",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/flute.fbx",
},
{
class = "Item",
uiName = "Charming Flute",
gfxIndex = 316,
weight = 0.3,
description = "A sharpened flute made of unknown material.",
},
{
class = "UsableItem",
onUseItem = function(self)
playSound("stone_philosopher_speak")
--playSound("flute01")--
return false
end,
secondaryAction = "fear",       ----Not working from here----
impactSound = "impact_blunt",
},
{
class = "CastSpell",
name = "fear",
uiName = "Cause Fear",
charges = 12,
buildup = 2,
energyCost = 10,
spell = "shield",
requirements = { "concentration", 1 }, --was 3--
onAttack = function(self)
playSound("fireball_launch")
end,
},
},
}

Re: onUse - playsound

Posted: Thu Dec 18, 2014 7:46 am
by Batty
These two lines:

Code: Select all

secondaryAction = "fear",
impactSound = "impact_blunt",
belong in the Item class, not the UsableItem class.

Re: onUse - playsound

Posted: Sat Dec 20, 2014 12:41 am
by Eleven Warrior
Thxs Batty for that info :D