Jump to content

Recommended Posts

I got a script that creates ambient battle noises around the player.

I got this script from DayZ Medic from YouTube but just edited to suit my needs.

And when I execute it I randomly get unknown expression variables for variable "_cpbSound"

Any ideas why this is occuring?

 

Quote

private _cpbSoundList = 

[

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions1.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions2.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions3.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions4.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions5.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight1.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight2.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight3.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight4.wss"

];

 

private _cpbTarget = player; 

private _cpbSoundObject = player;

 

private _cpbMinDistance = 100;

private _cpbMaxDistance = 800;

private _cpbMedDistance = 400;

 

while {true} do 

{

    _dir = round random 360; 

    _dis = round random [_cpbMinDistance,_cpbMedDistance,_cpbMaxDistance];

 

    private _cpbSoundPosition = _cpbTarget getRelPos [_dis, _dir];

    private _cpbSoundNumber = random count _cpbSoundList;

    private _cpbSound = _cpbSoundList select _cpbSoundNumber;

 

    playSound3D [_cpbSound, _cpbSoundObject, false, _cpbSoundPosition, 5, 1, 0];

 

    private _sleepRandom = random 12;

    sleep _sleepRandom;

};

 

Share this post


Link to post
Share on other sites

_cpbSoundNumber = random count _cpbSoundList;

 

This is getting a random number that is almost always going to have a decimal, and I don't know how well select goes with that. But also, it looks like there's 9 sounds there (sorry, I'm on my phone) and so running random on 9 could result in a number greater than 8, which is a problem because arrays are counted from a 0 index. So if soundNumber were to be 9 (again, decimals and select, never done it) then select will try and select a non-existing array index. 

 

Easy solution, use https://community.bistudio.com/wiki/selectRandom to pick the sound file instead of counting and randomising etc.

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, beno_83au said:

_cpbSoundNumber = random count _cpbSoundList;

 

This is getting a random number that is almost always going to have a decimal, and I don't know how well select goes with that. But also, it looks like there's 9 sounds there (sorry, I'm on my phone) and so running random on 9 could result in a number greater than 8, which is a problem because arrays are counted from a 0 index. So if soundNumber were to be 9 (again, decimals and select, never done it) then select will try and select a non-existing array index. 

 

Easy solution, use https://community.bistudio.com/wiki/selectRandom to pick the sound file instead of counting and randomising etc.


Works! Thanks for the help.

Share this post


Link to post
Share on other sites
3 hours ago, sizraide said:


Works! Thanks for the help.


For anyone who wants to use it.

Here it is:
 

Quote

/*

Extra sounds you can add in _gSoundList:

 

"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli1.wss"

"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli2.wss"

"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli3.wss"

"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet1.wss"

"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet2.wss"

"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet3.wss"

*/

 

private _gSoundList = 

[

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions1.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions2.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions3.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions4.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions5.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight1.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight2.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight3.wss",

    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight4.wss"

];

 

private _gTarget = player; // Sound source (sound position).

private _gSoundObject = player; // Object - the object emitting the sound. If sound position is specified this param is ignored.

private _gVolume = 3; // Volume of sound.

private _gSoundPitch = 1; // Sound Pitch (Number) - 1: Normal, 0.5: Darth Vader, 2: Chipmunks, etc. Default: 1.

private _gSoundDistance = 0; // Sound distance from object, default = 0.

private _maxCountSleep = 15; // How much maximum time between sounds played.

 

private _gMinDistance = 200; // Minimum distance from sound.

private _gMaxDistance = 700; // Maximum distance from sound.

private _gMedDistance = 400; // Average or medium random distance (Number) you wish the sound to eminate from.

 

while {true} do 

{

    _dir = round random 360; 

    _dis = round random [_gMinDistance,_gMedDistance,_gMaxDistance];

 

    private _gSoundPosition = _gTarget getRelPos [_dis, _dir];

    private _gSound = selectRandom _gSoundList;

 

    playSound3D [_gSound, _gSoundObject, false, _gSoundPosition, _gVolume, _gSoundPitch, _gSoundDistance];

 

    private _sleepRandom = round random _maxCountSleep;

    sleep _sleepRandom;

};

 

Share this post


Link to post
Share on other sites

This is a better version, it seems to work very well.

 

private _cpbSoundList = 

[
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions1.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions2.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions3.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions4.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_explosions5.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight1.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight2.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight3.wss",
    "A3\Sounds_F\environment\ambient\battlefield\battlefield_firefight4.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli1.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli2.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_heli3.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet1.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet2.wss",
	"A3\Sounds_F\environment\ambient\battlefield\battlefield_jet3.wss"
];

private _cpbTarget = player;
private _cpbSoundObject = player;
private _cpbMinDistance = 400;
private _cpbMaxDistance = 900;
private _cpbMedDistance = 600;

while {true} do
{
    _dir = round random 360;
    _dis = round random [_cpbMinDistance,_cpbMedDistance,_cpbMaxDistance];
    private _cpbSoundPosition = _cpbTarget getRelPos [_dis, _dir];

    playSound3D [_cpbSoundList call BIS_fnc_selectRandom, _cpbSoundObject, false, _cpbSoundPosition, 5, 1, 0];

    sleep (random [30, 40, 60]);
};

 

Edited by jakeplissken
Fixed code.

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

×