Jump to content

Lua script - play random sound ?


R.E.Z.
 Share

Recommended Posts

Hello,

 

I am working on a level,

where different messages should be played in the backround.

 

Do You know a scrit in Lua, that does this:

randomise different sounds in the Backround?

That would be really neat smile.png

 

Does anyone knew help for this purpose?

 

Have a nice day,

 

C.U. R.E.Z.

Leadwerks Standart Edition RTS Creator

Link to comment
Share on other sites

http://www.leadwerks.com/werkspace/files/download/420-random-output-scripts/

 

Place a pivot in your scene and attach this script to it (pick how many different sounds you want from 2-4 (if you need more you can see how to alter the script).

 

Place pivots in your scene for each sound and attach the already available noise.lua script in your Scripts directory to them and assign your sounds.

 

http://www.leadwerks.com/werkspace/files/file/419-scene-loaded/

 

Place another pivot in your scene and attach this script to it.

 

Open the flowgraph editor and drag from the scene tab all these entities into the flowgraph.

 

Drag the startup node output to the random node input. Then drag each random output to 1 noise play input. You are saying that when your scene starts call this random node which will randomly pick one of it's outputs to fire. That output is connected to the noise input to play the sound.

 

If you want this to repeat then on each noise node finished output you can link it back to the random node input.

 

This is the beauty of the flowgraph. Being able to piece together more complex functionality from basic components instead of having to rewrite everything specifically for your game!

 

If you want a delay between sounds then place a pivot in the scene and attach http://www.leadwerks.com/werkspace/files/file/412-le3-timer-node/ . Fill out it's properties. Drag it into the flowgraph and link all noise nodes outputs to this timer nodes start and enable and then link it's tick output back to the random node input AND to itself disable to stop the timer.

 

If you need help I can create the flowgraph tonight and show you the picture of how it should look. All of this functionality with 0 programming from your side smile.png

  • Upvote 1
Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...