Jump to content
Sign in to follow this  
CaptainBravo

Attaching sound to a pickable object

Recommended Posts

Hey everyone,

I am trying to attach a looping sound to an object which is simple enough. The issue is that object is pickable (can pick it up via action menue as an item). Once it is picked up the sound stops.

Example: Radio with looping music coming from it. Regardless if pick up or not, the music will always come from it. Anyway to have the sound loop going regardless if it is picked or not and regardless of who picks it up??

Your feed back is highly appreciated.

Share this post


Link to post
Share on other sites

Not directly, as the object is technically deleted when 'picked up'. What you'd have to do is start the sound playing again on the player (i.e. the unit who picked up the object), when the item is added to the inventory.

Share this post


Link to post
Share on other sites

Not sure how to do that as it could be picked up by one of a few players.

Anychance of a simple script, please :)

Share this post


Link to post
Share on other sites

I'm not in front of A2 at the moment, but I'll point you in the right sort of direction. Say now your Item is "ItemMap" (just as an example): you already know that the sound stops when you pick it up, so you can do this in one of two ways:

If you made the pick-up script/added the action, use the same script to play the sound on the unit initiating the action (see the addAction entry on the wiki for info).

Otherwise, you may want to consider a trigger and the use of the hasWeapon command to see when the unit has the item in their inventory (and then begin playing the sound on the unit).

Share this post


Link to post
Share on other sites

Thanks James for your help. So to clarify: once "radio" picked up by player ?!(player hasWeapon "radio1") : player unit say "music1"

Is that correct? If yes, what happens if he drops it ? what if someone else picks it up? how do you get it to play sound everytime radio exchanges hands??

The whole mission will be based on the radio exchanging hands between players.

Thaks for your help.

Share this post


Link to post
Share on other sites

Just don't add it to the inventory. attach it To the unit who picked it up, you can make it look like a backpack then. Easiest way.

The other solution would look like this:

waitUntil {player hasWeapon "radio1"};

player say "music1";

Thats SQf. Stop using SQS! :D

Or...

Simply create a HeliHEmpty at the radios location. Let this HeliHEmpty say the sound.

If unit picks up radio -> attach HeliHEmpty to unit.

And please be advised: Sounds like you're creating a multiplayer mission. Say is a local command. You have to execute it on every client.

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thanks sxp2high. A bit higher than my level. WHat if you have 8-10 human players. Which one will play sound? Any chance of a a simple demo mission. Promise you will be the first to try mission :)

Edited by CaptainBravo

Share this post


Link to post
Share on other sites
WHat if you have 8-10 human players. Which one will play sound?

On the say command each client starts a sound for itself, with that in mind you just have get sure that every client gets the say command. Thats what we call local.

Here you go:

You can start the radio sound with:

RadioPlaying = true; publicVariable "RadioPlaying";

and stop it with:

RadioPlaying = false; publicVariable "RadioPlaying";

in a trigger or script.

Just place a Invisible H an name it "RadioDummy".

Put this into its init:

[font="Fixedsys"]this attachTo [Radio,[0,0,0]];[/font]

Place the Radio and name it "Radio".

Put something like this into its init:

[font="Fixedsys"]this addAction [("<t color=""#f5ead0"">" + ("Take Radio") + "</t>"), "RadioTakeAndDrop.sqf", ["Take"], 555];[/font]

Put this into your init.sqf:

[font="Fixedsys"]//// Receive the publicVariable status
if (isNil "RadioPlaying") then { RadioPlaying = false; };


//// And exec the loop
nul = execVM "RadioPlayLoop.sqf";[/font]

RadioPlayLoop.sqf:

[font="Fixedsys"]//// Local only
if (!local player) exitWith {};


//// while playing true, play
//// This does not stop imminently after setting RadioPlaying to FALSE,
//// it will just stop the loop! The current sound will play till its over.
//// So, get sure to wait some time between switching RadioPlaying on/off.
while {true} do {

//// Wait until the radio gets command to start
waitUntil {RadioPlaying};

//// And play
RadioDummy say "MySound"; [color="Red"]//// Name of the sound[/color]
sleep 60; [color="Red"]//// How long the sound is, for repeat...[/color]
};[/font]

RadioTakeAndDrop.sqf:

[font="Fixedsys"]//// Variables
_RadioDummy = RadioDummy;
_Radio = Radio;
_Unit = _this select 1;
_Selected = (_this select 3) select 0;


//// If drop
if (_Selected == "Drop") exitWith {

//// Detach radio from player
deTach _Radio;
deTach _RadioDummy;

//// And put it on the ground
_Radio setPos (getPos _Unit);
_RadioDummy setPos (getPos _RadioDummy);

//// Remove the drop action
_Unit removeAction RadioDropAcion;
};


//// If take
if (_Selected == "Take") exitWith {

//// Attach radio to unit
sleep 0.5;
_Radio attachTo [_Unit,[0,0,-20]]; [color="Red"]//// -20 height means invisible (under the ground)[/color]
_RadioDummy attachTo [_Unit,[0,0,0]];

//// Set direction of the radio
_Radio setDir 45;

//// Add the drop action
RadioDropAcion = _Unit addAction [("<t color=""#f5ead0"">" + ("Drop Radio") + "</t>"), "RadioTakeAndDrop.sqf", ["Drop"], 555];
};[/font]

:yay:

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thanks sxp2high for your detailed response. I have tried but for some reason its not working and not sure what I have missed??

I have attahced the sample testing mission. I have also included the working pickupdrop script. Now only if I can get the attach sound to work :confused:http://www.filefront.com/17275917/Testing_Sound.utes.rar

Thanks again.

Share this post


Link to post
Share on other sites

You should b more careful with copy&paste. You simply missed a }; at the very end of the file. :D

Your case.sqf was also bugged, because you forgot to delete 2 lines at the end. Was working, but causing low fps. I also fixed this.

You should start your ArmA using the -showscripterrors parameter to see whats wrong. :) Having script errors in your mission is very bad. It's causing lag, low fps and may affect other scripts and functions.

Well, here's the fixed version.

Maybe a useful command for trigger condition, activated by blufor or any: Radio in thisList

This detects whenever the radio is inside the trigger. (for delivering, etc.)

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thanks sxp2high! This certainly works well. :)

A couple of quick questions:

- Is is possible to make the carrying unit drop the radio automatically on the ground when killed (as in the other script) ?

- Is is possible to attach a marker to the object (radio) (like sound) to follow it be it on ground or being carried?

Thanks for your help

Edited by CaptainBravo

Share this post


Link to post
Share on other sites

Let's include that into the existing files... :D

RadioTakeAndDrop.sqf

[font="Fixedsys"]//// Variables
_RadioDummy = RadioDummy;
_Radio = Radio;
_Unit = _this select 1;
_Selected = (_this select 3) select 0;


//// If drop
if (_Selected == "Drop") exitWith {

   [color="Blue"]RadioDropped = true;[/color]

   //// Detach radio from player
   deTach _Radio;
   deTach _RadioDummy;

   //// And put it on the ground
   _Radio setPos (getPos _Unit);
   _RadioDummy setPos (getPos _RadioDummy);
   _RadioDummy attachTo _Radio,[0,0,0]];

   //// Remove the drop action
   _Unit removeAction RadioDropAcion ;
};


//// If take
if (_Selected == "Take") exitWith {

   //// Attach radio to unit
   sleep 0.5;
   _Radio attachTo [_Unit,[-0,-0,-20]];    //// -2 height means invisible (under the ground)
   _RadioDummy attachTo [_Unit,[0,0,0]];

   //// Set direction of the radio
   _Radio setDir 45;

   //// Add the drop action
   RadioDropAcion  = _Unit addAction [("<t color=""#f5ead0"">" + ("Drop Radio") + "</t>"), "RadioTakeAndDrop.sqf", ["Drop"], 555];

[color="Blue"]    //// Wait until dropped. In case unit dies.
   waitUntil {(!alive _Unit) || (RadioDropped)};
   RadioDropped = false;
   if (!alive _Unit) then {
       deTach _Radio;
       deTach _RadioDummy;
       _Radio setPos (getPos _Unit);
       _RadioDummy setPos (getPos _RadioDummy);
       _RadioDummy attachTo _Radio,[0,0,0]];
   };[/color]
};[/font]

RadioPlayLoop.sqf:

[font="Fixedsys"]//// Local only
if (!local player) exitWith {};

[color="Blue"]/// spawn
[] spawn {
   //// Create marker
   _Marker = createMarkerLocal["Radiomarker",(getPos Radio)];
   _Marker setMarkerShapeLocal "ICON";
   _Marker setMarkerTypeLocal "DOT";
   _Marker setMarkerTextLocal "Radio position";

   //// Attach marker
   while {alive Radio} do {
       _Marker setMarkerPosLocal (getPos Radio);
       sleep 0.5;
   };
};[/color]


//// while playing true, play
//// This does not stop imminently after setting RadioPlaying to FALSE,
//// it will just stop the loop! The current sound will play till its over.
//// So, get sure to wait some time between switching RadioPlaying on/off.
while {true} do {

   //// Wait until the radio gets command to start
   waitUntil {RadioPlaying};

   //// And play
   RadioDummy say "beep1";
   sleep 9.4; //// How long the sound is, for repeat...
};[/font]

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thanks sxp2high. I have replaced files with the new ones but now the radio can not be picked up? I see it in action menue but it not working :confused:

Thanks for your help.

Share this post


Link to post
Share on other sites

any luck with a fix please? :)

Edit

---------------------------

Never mind, got it working now. I shall post mission later on. Thanks for your great help again :)

Edited by CaptainBravo
Got it working

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
Sign in to follow this  

×