Jump to content

Recommended Posts

Hello All,

 

Struggling to get my head around playSound3D.

I have read through this http://killzonekid.com/arma-scripting-tutorials-mission-root/ but it is as good as a different language to me...

Trying to get a custom sound in my mission file "soundz\" to play on the server for all clients.

Was using say3D before which worked but seemed to me only for 1 client and was local.

 

Currently I have a trigger set for Server Side and Repeatable with this inside the onAct: 

playSound3D ["soundz\generator", gen, [], [], [], [], 50];

Any help would be appreciated.

 

Thanks,

Aurora

Share this post


Link to post
Share on other sites

From what I've read, I think playSound3D and drawIcon3D doesn't look for the file in your mission directory but in the game directory or another more general one... Well what KK did, is give us a simple tool to recover that path and tell Arma easily where our sound or/and picture is.

First you need to create a function in the init.sqf, this function will automatically look for the path of the mission and return a valid path:

MISSION_ROOT = call {
    private "_arr";
    _arr = toArray __FILE__;
    _arr resize (count _arr - 8);
    toString _arr
};

now, each time you use "MISSION_ROOT" it will run that code and return a good path for us to use, mix this with your function above and you got what you wanted!

playSound3D [MISSION_ROOT + "soundz\generator", gen, [], [], [], [], 50];
//BTW isn't there supposed to be a file extension in your path?

 

Thanks a lot to kk👍

Edited by Erwin23p
spelling
  • Like 1

Share this post


Link to post
Share on other sites

Hi @Erwin23p, thanks for responding. 🙂

 

I have put the function into the init.sqf and put the script into the trigger to activate the sounds. However, I am now getting an error on mission start saying that: 

playSound3D [MISSION_ROOT + "soundz\radio.wav", radio, [], [], [], [], 15];

This is returning an error for an array whilst its expecting a number?

 

Any ideas?

 

Regards,

Aurora

Share this post


Link to post
Share on other sites
33 minutes ago, aurora1-4 said:

playSound3D [MISSION_ROOT + "soundz\radio.wav", radio, [], [], [], [], 15];

I think what is wrong is the other arguments:

playSound3D [filename, soundSource, isInside, soundPosition, volume, soundPitch, distance]

so, 3rd element should be a boolean, not an array, 4th should be the position where you want the sound to source from, in your case if it's the radio:

getPosASL radio

5th, is an integrer, is the volume: Default: 1 Maximum value: 5

6 is another integrer, is the pitch: 1: Normal, 0.5: Darth Vader, 2: Chipmunks, etc. Default: 1

and last the one where you set 15, is the distance: How far is sound audible (0 = no max distance) Default: 0.

So your function should look something like this:

playSound3D [MISSION_ROOT + "soundz\radio.wav", radio, false, getPosASL radio, 1, 1, 15];

Now it should work.

  • Like 1

Share this post


Link to post
Share on other sites

@Erwin23p

 

Just pasted that in the trigger and I'm still getting the same error?

 

"Error type Array, expected Number" with the # before playSound3D.

 

EDIT: I was just being an idiot. fixed the error. However, sounds still not playing.

 

EDIT2: The sound files are only 30 seconds long to reduce file size. This may be the problem. I have the trigger set for anybody inside zone and repeatable. Would this repeat the sound as it finishes or would I have to create a loop to keep repeating the sound after 30 seconds? If so, how?

 

Share this post


Link to post
Share on other sites

Remember that if a player gets in, and then after a few seconds another gets in, the trigger will reproduce again the sound over the one already playing, so maybe use some variable and for the loop you could spawn a simple for loop in the trigger onAct with a sleep command:

Spoiler

_null = [] spawn {for "_i" from 1 to 4 do {
playSound3D [MISSION_ROOT + "soundz\radio.wav", radio, false, getPosASL radio, 1, 1, 15];
sleep 30;
};
};

//Sleep 30 means 30 seconds between each cycle, with a for loop from 1 to 4, this means the sound will play for 2 minutes.

 

But then, if the sound should execute only one time and keep sounding for the time you want, don't make it repeatable.

  • Like 1

Share this post


Link to post
Share on other sites

I see. I have put the condition to...

alive radio

...as I have an action on the radio to be able to turn it off via setting its damage to 1.

I have pasted the loop in with this condition but still no sound? Now im getting an error undefined variable "MISSION_ROOT"...

 

 

Share this post


Link to post
Share on other sites
4 minutes ago, h - said:

Maybe use the more modern method of getting the mission root:
https://community.bistudio.com/wiki/getMissionPath

 

So would I just have to put... 

private _root = getMissionPath "";

...into my init.sqf and then put...

_null = [] spawn {for "_i" from 1 to 240 do { 
playSound3D [_root + "soundz\radio.wav", radio, false, getPosASL radio, 1, 1, 15]; 
sleep 30; 
}; 

into the trigger?
 

Share this post


Link to post
Share on other sites

Or would I just have to put...

_null = [] spawn {for "_i" from 1 to 240 do { 
playSound3D [getMissionPath "soundz\radio.wav", radio, false, getPosASL radio, 1, 1, 15]; 
sleep 30; 
}; 
};

 

with nothing in the init.sqf?

 

This one seems to have worked! Hurray!

 

Thankyou @Erwin23p and @h - for all the help! Very much appreciated!

Share this post


Link to post
Share on other sites

Yes.
Variables with the underscore (like _root) are private variables so they are not available outside the script they were defined in. So _root will not be accessible in any trigger.

Just a slight correction in your code:

playSound3D [getMissionPath "" + "soundz\radio.wav", radio, false, getPosASL radio, 1, 1, 15]


getMissionPath "" means it gives you the path to the mission root, need those quotes after it.
And the + means that what ever the getMissionPath "" returns gets "soundz\radio.wav" added to it.

EDIT:
Ah, obviously the getMissionPath "soundz\radio.wav" works, should probably read the wiki a bit more carefully.. 😛

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×