Jump to content
  • 0

having a sound loop from certain coords


insertcoins

Question

11 answers to this question

Recommended Posts

  • 0

I swear insertcoins, we must be cut from the same cloth because I've been working on this very thing for the past 2 days (well more of getting certain sounds to attach to ai and different static locations). I can spawn in a hacked bot that plays all of my custom sounds, however trying to get this to work from a script within the server is proving to be a pain. Can't find any tutorials on how to do it anywhere, closest thing I have found to an answer is what xBowBii said, the editor, I'm gonna be working on this tonight, if I get it going I'll be happy to share how I did it with you.

Link to comment
Share on other sites

  • 0

I swear insertcoins, we must be cut from the same cloth because I've been working on this very thing for the past 2 days (well more of getting certain sounds to attach to ai and different static locations). I can spawn in a hacked bot that plays all of my custom sounds, however trying to get this to work from a script within the server is proving to be a pain. Can't find any tutorials on how to do it anywhere, closest thing I have found to an answer is what xBowBii said, the editor, I'm gonna be working on this tonight, if I get it going I'll be happy to share how I did it with you.

customsounds.hpp included in the description.ext
 
class CfgSounds
{
	sounds[] = {sound1,sound2};

	// Definition for each sound
	class sound1
	{
		name = "sound1";
		sound[] = {custom\sounds\sound1.ogg, .1, 1}; // filename, distance to be heard, playback speed
		titles[] = {};
	};

	class sound2
	{
		name = "sound2";
		sound[] = {custom\sounds\sound2.ogg, .1, 1};
		titles[] = {};
	};	
};

server side sound code 

_sound = createVehicle ["HeliHEmpty", [0,0,0], [], 0, "NONE"];
_sound attachTo _aiUnit;
[nil, _sound, rSAY, "sound1"] call RE;
sleep 5; // or some other waitUntil code
deleteVehicle _sound;

You may be able to get away with just making the unit play the sound but I prefer to use a logic for the sound object so you can manipulate it

Link to comment
Share on other sites

  • 0

Let's say I want to have a sound clip playing at a building, continuously. How would I go about doing that? Would placing a trigger be the best way or just have it looping regardless of players closeby?

 

You could pretty much use the code I posted above but make it loop instead of delete, or you could add a check to see if there are any players nearby and then start the playback loop until they leave, I used this method once to add electricity sound to working powerlines and it was a good result

Link to comment
Share on other sites

  • 0

 

customsounds.hpp included in the description.ext
 
class CfgSounds
{
	sounds[] = {sound1,sound2};

	// Definition for each sound
	class sound1
	{
		name = "sound1";
		sound[] = {custom\sounds\sound1.ogg, .1, 1}; // filename, distance to be heard, playback speed
		titles[] = {};
	};

	class sound2
	{
		name = "sound2";
		sound[] = {custom\sounds\sound2.ogg, .1, 1};
		titles[] = {};
	};	
};

server side sound code 

_sound = createVehicle ["HeliHEmpty", [0,0,0], [], 0, "NONE"];
_sound attachTo _aiUnit;
[nil, _sound, rSAY, "sound1"] call RE;
sleep 5; // or some other waitUntil code
deleteVehicle _sound;

You may be able to get away with just making the unit play the sound but I prefer to use a logic for the sound object so you can manipulate it

 

I have the custom sounds.hpp, I use them to make my hacked AI use them to sound like they are talking. Where would you place that second line of code? For instance here is a piece of my AI script that basically repeats that I am using to spawn in simple AI that I place at certain coordinates via my init:

private["_aiunit","_xpos","_ypos","_unitpos","_aiGroup","_wppos","_wpradius","_wpnum","_numunits","_unitType","_faction","_rndLOut","_ailoadout","_aiwep","_aiammo","_wp","_aispawnpos"];

        _aiunit = objNull;

        _aispawnpos =_this select 0;

        _wpradius = _this select 1;

        _wpnum = _this select 2;

        _numunits = _this select 3;

       _unitType = _this select 4;

       _faction = _this select 5;

        _xpos = _aispawnpos select 0;

        _ypos = _aispawnpos select 1;

       // Faction 0 settings (aka Resistance [locals])

       _resistanceRandomSkin = "gangsta_merc2";

       _resistanceSniperSkin = "gangsta_merc1";

       _resistanceGunnerSkin = "gangsta_merc7";

       _resistanceMilitiaSkin = "gangsta_merc2";

       _resistanceRandomGear = ["ItemMatchbox","FoodCanBakedBeans","ItemSodaPepsi"];

       _resistanceSniperRifle = "MeleeMachete";

       _resistanceSniperAmmo = "Machete_Swing";

       _resistanceSniperGear = ["ItemMatchbox","FoodCanBakedBeans","ItemSodaPepsi"];

       _resistanceGunnerRifle = "MeleeHatchet";

       _resistanceGunnerAmmo = "Hatchet_Swing";

       _resistanceGunnerGear = ["ItemMatchbox","FoodCanBakedBeans","ItemSodaPepsi"];

       _resistanceMilitiaRifle = "MeleeCrowbar";

       _resistanceMilitiaAmmo = "Crowbar_swing";

       _resistanceMilitiaGear = ["ItemMatchbox","FoodCanBakedBeans","ItemSodaPepsi"];

       

       // Faction 1 settings (aka East [Military])

       _eastRandomSkin = "gangsta_merc2";

       _eastSniperSkin = "gangsta_merc1";

       _eastGunnerSkin = "gangsta_merc7";

       _eastMilitiaSkin = "gangsta_merc2";

       _eastRandomGear = ["ItemGPS","NVGoggles"];

       _eastSniperRifle = "MeleeMachete";

       _eastSniperAmmo = "Machete_Swing";

       _eastSniperGear = ["ItemGPS","NVGoggles"];

       _eastGunnerRifle = "MeleeHatchet";

       _eastGunnerAmmo = "Hatchet_Swing";

       _eastGunnerGear = ["ItemGPS","NVGoggles"];

       _eastMilitiaRifle = "MeleeCrowBar";

       _eastMilitiaAmmo = "Crowbar_Swing";

       _eastMilitiaGear = ["ItemGPS","NVGoggles"];

       switch (_faction) do {

          case 0 : {_aiGroup = createGroup east;         

             for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do {

             _unitpos = [_xpos+x,_ypos+x,0];

                switch (_unitType) do {

                   case 0 : {

                      _rndLOut=floor(random 3);

                      _ailoadout=

                      switch (_rndLOut) do {

                        case 0: {[_resistanceSniperRifle,_resistanceSniperAmmo,_resistanceSniperGear]};

                        case 1: {[_resistanceGunnerRifle,_resistanceGunnerAmmo,_resistanceGunnerGear]};

                        case 2: {[_resistanceMilitiaRifle,_resistanceMilitiaAmmo,_resistanceMilitiaGear]};

                      };

                      

                      _resistanceRandomSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];

                                   

                      _aiunit enableAI "TARGET";

                      _aiunit enableAI "AUTOTARGET";

                      _aiunit enableAI "MOVE";

                      _aiunit enableAI "ANIM";

                      _aiunit enableAI "FSM";

                      _aiunit allowDammage true;

                      _aiunit setCombatMode "RED";

                      _aiunit setBehaviour "COMBAT";

                   

                      //clear default weapons / ammo

                      removeAllWeapons _aiunit;

                      //add weapon

                      _aiwep = _ailoadout select 0;

                      _aiammo = _ailoadout select 1;

                      _aiunit addweapon _aiwep;

                      _aiunit addMagazine _aiammo;

                      _aiunit addMagazine _aiammo;

                      _aiunit addMagazine _aiammo;

                      _gearCount = count _resistanceRandomGear;

                      for [{z = 0},{z >= _gearCount},{z = z + 1}] do {

                         _currentItem = _resistanceRandomGear select z;

                         _aiunit addMagazine _currentItem;

                      };

                                     

                      //set skills

                    _aiunit setSkill ["aimingAccuracy",1];

                    _aiunit setSkill ["aimingShake",1];

                    _aiunit setSkill ["aimingSpeed",1];

                    _aiunit setSkill ["endurance",1];

                    _aiunit setSkill ["spotDistance",1];

                    _aiunit setSkill ["spotTime",1];

                    _aiunit setSkill ["courage",1];

                    _aiunit setSkill ["reloadSpeed",1];

                    _aiunit setSkill ["commanding",1];

                    _aiunit setSkill ["general",1];        

                   };

                   case 1 : {

                      _ailoadout=[_resistanceSniperRifle,_resistanceSniperAmmo,_resistanceSniperGear];

                      

                      _resistanceSniperSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];

                                   

                      _aiunit enableAI "TARGET";

                      _aiunit enableAI "AUTOTARGET";

                      _aiunit enableAI "MOVE";

                      _aiunit enableAI "ANIM";

                      _aiunit enableAI "FSM";

                      _aiunit allowDammage true;

                      _aiunit setCombatMode "RED";

                      _aiunit setBehaviour "COMBAT";

                   

                      //clear default weapons / ammo

                      removeAllWeapons _aiunit;

                      //add weapon

                      _aiwep = _ailoadout select 0;

                      _aiammo = _ailoadout select 1;

                      _aiunit addweapon _aiwep;

                      _aiunit addMagazine _aiammo;

                      _aiunit addMagazine _aiammo;

                      _aiunit addMagazine _aiammo;

                      _gearCount = count _resistanceSniperGear;

                      for [{z = 0},{z >= _gearCount},{z = z + 1}] do {

                         _currentItem = _resistanceSniperGear select z;

                         _aiunit addMagazine _currentItem;

                      };

                                     

                      //set skills

                    _aiunit setSkill ["aimingAccuracy",1];

                    _aiunit setSkill ["aimingShake",1];

                    _aiunit setSkill ["aimingSpeed",1];

                    _aiunit setSkill ["endurance",1];

                    _aiunit setSkill ["spotDistance",1];

                    _aiunit setSkill ["spotTime",1];

                    _aiunit setSkill ["courage",1];

                    _aiunit setSkill ["reloadSpeed",1];

                    _aiunit setSkill ["commanding",1];

                    _aiunit setSkill ["general",1];                

                   };

and thank you for helping me!

Link to comment
Share on other sites

  • 0

That' tricky maaan! :3

If that player goes near traders and someone buys a vehicle the vehicle will spawn where he was standing ^-^

Maybe change it by another object like a can?

LOL, well in cases where I used it, it would never have a chance to get near a trader, I use it on garage doors when they open and Ai will never be in trader zones either.

 

Where would you place that code xBowBii?

well I would do something like this

_resistanceRandomSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];
_aiunit spawn {
	private ["_unit","_sound","_playerPresent"];
	_unit = _this;
	_sound = createVehicle ["HeliHEmpty", position _unit, [], 0, "NONE"];
	_sound attachTo _unit;
	while {alive _unit} do {
		_playerPresent = false;
		{if((isPlayer _x) && (_x distance _position <= 150)) then {_playerPresent = true};}forEach playableUnits;
		if (_playerPresent) then {
			[nil, _sound, rSAY, "sound1"] call RE;
			for "_i" from 0 to 50 do { // 5 second delay with enough pausing to stop dead unit talking
				sleep .1;
				if !(alive _unit) exitWith {
					_sound setDamage 1;
					deleteVehicle _sound;			
				};
			};
		};
	};
	_sound setDamage 1;
	deleteVehicle _sound;			
};
Link to comment
Share on other sites

  • 0

Ok I inserted the code to look like this:

switch (_faction) do {


          case 0 : {_aiGroup = createGroup east;         
             for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do {
             _unitpos = [_xpos+x,_ypos+x,0];
                switch (_unitType) do {
                   case 0 : {
                      _rndLOut=floor(random 3);
                      _ailoadout=
                      switch (_rndLOut) do {
                        case 0: {[_resistanceSniperRifle,_resistanceSniperAmmo,_resistanceSniperGear]};
                        case 1: {[_resistanceGunnerRifle,_resistanceGunnerAmmo,_resistanceGunnerGear]};
                        case 2: {[_resistanceMilitiaRifle,_resistanceMilitiaAmmo,_resistanceMilitiaGear]};
                      };
                      
                      _resistanceRandomSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];
              _aiunit spawn {
                  private ["_unit","_sound","_playerPresent"];
                  _unit = _this;
                  _sound = createVehicle ["HeliHEmpty", position _unit, [], 0, "NONE"];
                  _sound attachTo _unit;
                  while {alive _unit} do {
                    _playerPresent = false;
                    {if((isPlayer _x) && (_x distance _position <= 150)) then {_playerPresent = true};}forEach playableUnits;
                    if (_playerPresent) then {
                        [nil, _sound, rSAY, "z_scream_4"] call RE;
                        for "_i" from 0 to 50 do { // 5 second delay with enough pausing to stop dead unit talking
                            sleep .1;
                            if !(alive _unit) exitWith {
                                _sound setDamage 1;
                                deleteVehicle _sound;            
                            };
                        };
                    };
                };
                _sound setDamage 1;
                deleteVehicle _sound;            
            };
                                   
                      _aiunit enableAI "TARGET";
                      _aiunit enableAI "AUTOTARGET";
                      _aiunit enableAI "MOVE";
                      _aiunit enableAI "ANIM";
                      _aiunit enableAI "FSM";
                      _aiunit allowDammage true;
                      _aiunit setCombatMode "RED";
                      _aiunit setBehaviour "COMBAT";
                   
                      //clear default weapons / ammo
                      removeAllWeapons _aiunit;
                      //add weapon
                      _aiwep = _ailoadout select 0;
                      _aiammo = _ailoadout select 1;
                      _aiunit addweapon _aiwep;
                      _aiunit addMagazine _aiammo;
                      _aiunit addMagazine _aiammo;
                      _aiunit addMagazine _aiammo;
                      _gearCount = count _resistanceRandomGear;
                      for [{z = 0},{z >= _gearCount},{z = z + 1}] do {
                         _currentItem = _resistanceRandomGear select z;
                         _aiunit addMagazine _currentItem;
                      };
                                     
                      //set skills
                    _aiunit setSkill ["aimingAccuracy",1];
                    _aiunit setSkill ["aimingShake",1];
                    _aiunit setSkill ["aimingSpeed",1];
                    _aiunit setSkill ["endurance",1];
                    _aiunit setSkill ["spotDistance",1];
                    _aiunit setSkill ["spotTime",1];
                    _aiunit setSkill ["courage",1];
                    _aiunit setSkill ["reloadSpeed",1];
                    _aiunit setSkill ["commanding",1];
                    _aiunit setSkill ["general",1];  

                   };

 

This is a lot better than what I have been able to produce, because any changes I make causes issues with the AI, yours does not, however they still are not playing any sounds, but at least it is a step in the right direction. I tried using custom sounds and it was a no go, I tried using organic sounds like z_scream_4 and still a no go. I tried replacing [nil, _sound, rSAY, "z_scream_4"] call RE; with [nil,_sound,rSAY,[["z_scream_4","z_scream_w_0"] call BIS_fnc_selectRandom, 20]] call RE; but that didn't work either. That code sequence look correct to you? I'm gonna keep fiddling with it and see if I can get it going, I have a feeling it's probably one small little thing that is keeping this from working properly. Thanks again!!!

Link to comment
Share on other sites

  • 0

So what I noticed is that when I changed the createvehicle from the helipad to Land_Church_tomb_2, they units will spawn in and place a Land_Church_tomb_2 in the ground where they spawned, they're still not talking. So the script is kinda working, the vehicle is being created, and perhaps the sound occurs once and I just haven't heard it but it's not looping. Hmmm..

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...