Page 1 of 1

Question about chests

Posted: Mon Feb 01, 2016 9:34 am
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 )

Re: Question about chests

Posted: Mon Feb 01, 2016 10:40 am
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,

Re: Question about chests

Posted: Mon Feb 01, 2016 5:38 pm
by vanblam
Awesome! .. thanks minmay :D... you rock.

Re: Question about chests

Posted: Tue Feb 02, 2016 7:51 am
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.

Re: Question about chests

Posted: Tue Feb 02, 2016 8:42 am
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.

Re: Question about chests

Posted: Tue Feb 02, 2016 7:28 pm
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 :)

Re: Question about chests

Posted: Tue Feb 02, 2016 11:34 pm
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".