[SOLVED] Change "party_land" sound volume?

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
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

[SOLVED] Change "party_land" sound volume?

Post by Lark »

I've searched and studied this for a few days, but I can't find a way to temporarily change the volume of a built in sound. I want a script to change the volume of the "party_land" sound, let the sound play, then set it back to normal. Alternately, I could set it to a sound I define, then set it back to "party_land". This is the sound played be default when the party steps off of a ledge to one level below. Does anyone know how to do this?

Thanks, -Lark

EDIT: I solved this by having the script move the party to the lower elevation incrementally using setWorldPosition, then setting their correct final location using party:setPosition as setWorldPosition does not update the actual coordinates of the party. This avoids the fall entirely and the sound is not played.

I will post the script soon... thanks everyone!
Last edited by Lark on Tue Nov 15, 2016 2:45 am, edited 3 times in total.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Change "party_land" sound volume?

Post by Isaac »

One [off the cuff] option that seems to work:
(Likely needs altered if you are using a framework that handles the party hooks.)

Code: Select all

defineSound{
	name = "party_land",
	filename = "assets/samples/characters/party_fall_01.wav",
	loop = false,
	volume = 0,
}

defineSound{
	name = "party_land2",
	filename = "assets/samples/characters/party_land_01.wav",
	loop = false,
	volume = 1,
}

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
			class = "Party",
			onDrawAttackPanel = function(self) end,
		},
	},
}

Code: Select all

useSound = false
party:createComponent("Sound", "landing")
party.party:addConnector('onDrawAttackPanel', self.go.id, 'fallTest')

function fallTest()
	if party.party:isFalling() then
		useSound = true
		return
	end
	if useSound then 
		party.landing:setVolume(3.5)
		party.landing:play("party_land2")
		useSound = false
	end
end
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Change "party_land" sound volume?

Post by Lark »

Thank you Isaac,

I'll try to work with this tonight. I think the "party hook"(?) might be the key to what I need - I've never played with those yet. This script will fire just before the party falls off a ledge, so I'll know that the system is going to play the "party_landing" sound when they hit. I'm not playing the sound myself. I basically need to lessen the volume or completely eliminate the sound as the party is "caught" and the default sound is inappropriate (or inappropriately loud). Once the party lands, another part of the script is triggered where I'd set the sound back to normal so when they fall off a "normal ledge", the sound is correct.

Thank you again, -Lark
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Change "party_land" sound volume?

Post by Isaac »

It should be possible to remove the connector while on maps or in areas where it's impossible to fall.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Change "party_land" sound volume?

Post by Lark »

Sorry Isaac, I don't understand what you mean... Remove what connector from what? Thanks, -Lark
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Change "party_land" sound volume?

Post by Isaac »

From the code in the post above:

useSound = false
party:createComponent("Sound", "landing")
party.party:addConnector('onDrawAttackPanel', self.go.id, 'fallTest')

This statement adds a connector to the 'ondrawAttackPannel' party hook, and in so doing, calls the fallTest() function every frame. (To check for falls)
This adds a negligible amount of overhead, but a delay that could still be removed when exploring those areas of the map where it is impossible to fall;
IE. where the test could never ~ever detect a fall, or need play the party_landing sound effect.

To remove the connector, one calls: party.party:removeConnector('onDrawAttackPanel', self.go.id, 'fallTest')
and later call: party.party:addConnector('onDrawAttackPanel', self.go.id, 'fallTest')
to restore it at a time [place] when it's possible for the party to fall, and need the sound effect.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Change "party_land" sound volume?

Post by Lark »

Thank you for the hook idea. I think I can learn from this as I've yet to do any party hooks and some of this is still over my head. I'm learning, however, thank you!

I did solve this a different way. I'm actually writing a "safe ladder" script that allows the party to descend any number of ladders stacked on top of each other without falling. I will post it on its own thread soon as I have a bit more to do. But, if the script didn't allow the party to "fall" into the last square, the party's location wasn't updated until they moved horizontally, so climbing the ladder again didn't always work because they hit their heads! I didn't like the falling sound, so I wanted to disable or soften it.

To solve that, I lower them all the way to the bottom elevation with setWorldPosition, then set their final location using party:setPosition as I exit. The party now has the correct location and all is well for reclimbing or moving somewhere else. I should have explained the whole issue instead of just asking for a way to solve one problem. This part now works.

Thank you everyone! -Lark
Post Reply