onUse - playsound

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

onUse - playsound

Post 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,
		},

	},
}
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: onUse - playsound

Post 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! :)
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: onUse - playsound

Post by bongobeat »

thanks :)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: onUse - playsound

Post 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,
},
},
}
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: onUse - playsound

Post by Batty »

These two lines:

Code: Select all

secondaryAction = "fear",
impactSound = "impact_blunt",
belong in the Item class, not the UsableItem class.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: onUse - playsound

Post by Eleven Warrior »

Thxs Batty for that info :D
Post Reply