Advertisement

Author Topic: Sound Loop Function (Accepted)  (Read 2236 times)

0 Members and 1 Guest are viewing this topic.

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Sound Loop Function (Accepted)
« on: 17 Dec 2008, 00:39:29 »
JBOY_soundLoop is a simple function that will have an object say a sound repeatedly.  This is useful for any object that you want to play a sound continously (say a radio playing a song loop, or a generator playing a generator noise, of flys buzzing around an outhouse, etc.). 

Here's a sample call:

Code: [Select]
dmy=[toilet, "fxFlies4secs", 3.95 , 10000] execvm "JBOY_soundLoop.sqf";   
Parameter 1: Object that will "say" the sound.
Parameter 2: Name of sound in quotes from your description.ext.
Parameter 3: Length of sound in seconds.
Parameter 4: # of times to execute the loop.  For infinite, pass in -1.

Pretty simple, but useful to me, so maybe useful to someone else...

Sorry, Schuler--I know this is bad for my reputation--but this script does not blow anything up! ;)

Script Updated per Wolfrug's suggestions:

- Modified so that -1 in Parameter 4 will cause the loop to run infinitely (if object is alive).
- Modified loop to only Say the sound if player is within 250 meters to save on resources.

Attached file has been updated.

OFPEC Download
« Last Edit: 07 Jan 2009, 18:20:33 by hoz »
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Sound Loop Function
« Reply #1 on: 17 Dec 2008, 10:19:47 »
I suggest you, instead of forcing people to put a "very large number" for infinite loops (this kind of script could be useful for looping a very very short sound too, especially in a long, or even infinite, mission - think Dynamic War), you script in that using for instance -1 will make it loop forever.

I suppose you could also put in a "distance check" if you really want to be fancy about it - right now it plays the sound whether you're close to it or not, which is a little unnecessary (eats up resources). A simple distance check to the player (who is the only one who can hear and appreciate the sounds anyway ;)) would solve that issue! Make it a variable for the user to pick, so that e.g. a looping song won't always randomly start from the beginning the moment the player gets close enough. :)

Looks good otherwise!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Sound Loop Function
« Reply #2 on: 17 Dec 2008, 17:45:28 »
Great suggestions Wolfrug.  Will do!

Edit:  I implemented Wolf's suggestions, modified the first post, and attached the modified test mission.
« Last Edit: 18 Dec 2008, 01:30:10 by johnnyboy »
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...