Question about chests

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
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Question about chests

Post by vanblam »

1. I can't find a way to change the sound ( seems to be hard coded).
2. I'm looking to find a way to access when its opened or closed. It calls the animations but how do you catch when it does call the animations?
For example when you open a chest I know you can mess around with the clickable component, but when you back away and the chest closes how do
access that? I tried doing onOpen and onClosed in the animation component with no success. Basically I'm trying to add additional sounds for when it
opens and closes WITH out messing with the clickable component.

BTW I'm still very much a newb with coding :P ( but I'm learning, thanks to all of you out there :D )
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Question about chests

Post by minmay »

vanblam wrote:1. I can't find a way to change the sound ( seems to be hard coded).
Correct. If you want to play a different sound, overwrite the chest_open and chest_close sounds with a silent sound*, then define animation events to play your preferred sound:

Code: Select all

defineSound{
	name = "chest_open",
	filename = "mod_assets/dmcsb_pack/samples/silence.wav",
	loop = false,
	volume = 0,
	minDistance = 0,
	maxDistance = 0,
}
defineSound{
	name = "chest_close",
	filename = "mod_assets/dmcsb_pack/samples/silence.wav",
	loop = false,
	volume = 0,
	minDistance = 0,
	maxDistance = 0,
}
defineAnimationEvent{
	animation = "assets/animations/env/treasure_chest_open.fbx",
	event = "playSound:chest_open_2",
	frame = 0,
}
defineAnimationEvent{
	animation = "assets/animations/env/treasure_chest_close.fbx",
	event = "playSound:chest_close_2",
	frame = 0,
}
defineSound{
	name = "chest_open_2",
	filename = "assets/samples/env/chest_open_01.wav",
	loop = false,
	volume = 0.8,
	minDistance = 1,
	maxDistance = 10,
}
defineSound{
	name = "chest_close_2",
	filename = "assets/samples/env/chest_close_01.wav",
	loop = false,
	volume = 0.8,
	minDistance = 1,
	maxDistance = 10,
}
*(I use a true silent sound file, but really it doesn't matter much since volume 0 is always silent)
vanblam wrote:2. I'm looking to find a way to access when its opened or closed. It calls the animations but how do you catch when it does call the animations?
For example when you open a chest I know you can mess around with the clickable component, but when you back away and the chest closes how do
access that? I tried doing onOpen and onClosed in the animation component with no success. Basically I'm trying to add additional sounds for when it
opens and closes WITH out messing with the clickable component.
Again, easiest to use AnimationEvents:

Code: Select all

defineAnimationEvent{
	animation = "assets/animations/env/treasure_chest_open.fbx",
	event = "open",
	frame = 0,
}
defineAnimationEvent{
	animation = "assets/animations/env/treasure_chest_close.fbx",
	event = "close",
	frame = 0,
}
Then add this field to the AnimationComponent:

Code: Select all

onAnimationEvent = function(self, event)
  if event == "open" then
    -- do whatever you wanted to do when the chest opens
  elseif event == "close" then
    -- do whatever you wanted to do when the chest closes
  end
end,
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Question about chests

Post by vanblam »

Awesome! .. thanks minmay :D... you rock.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Question about chests

Post by vanblam »

have a question. How can I use those animation events to trigger other things in my dungeon such as a
door or to disable something. Example if I open the chest a door opens somewhere or a fire ball fires at you.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Question about chests

Post by minmay »

onAnimationEvent is a hook called whenever an animation event occurs in one of that AnimationComponent's animations. It's just an arbitrary function, you can put whatever you want in it, which could include a opening a door or spawning a fireball.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Question about chests

Post by vanblam »

I've been at it for hours trying to figure out how to connect it to a door.
I feel like a pest now, but how do I connect it to a door or to disable another game object?

BTW thank you very much for your help minmay :)
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Question about chests

Post by minmay »

Sounds like you need to read the modding guide and check the scripting interface documentation.

A connector from a component to a target with an action is equivalent to

Code: Select all

[target].controller:[action]()
if the target has a ControllerComponent named "controller". If the target instead has a ScriptControllerComponent named "controller", it is equivalent to

Code: Select all

[target].script.[action]([component])
where [component] is the component with the connector.

So a connector that "opens" an object is equivalent to

Code: Select all

[id of object].controller:open()
assuming that the object exists and has a ControllerComponent named "controller".
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply