Home   Help Search Login Register  

Author Topic: addAction Audio Script  (Read 3348 times)

0 Members and 1 Guest are viewing this topic.

Offline aceking

  • Members
  • *
addAction Audio Script
« on: 04 Feb 2009, 18:51:59 »
Hi, I had a questing regarding an addAction script that I put on a humvee so that you could "Turn on speakers" and it will play an audio sample from the vehicle. For some reason, when I tested the mission with some human players, they could not hear the audio after I turned it on. However, they were only able to hear it after they themselves turned it on, so apparently only the person that uses the action can hear the audio. Is there a way to make it so that everyone can hear the audio from the vehicle after anybody uses the action once. Also, how do I create a "Turn off speaker" script that would stop the audio from playing from the vehicle, cuz I've got the "Turn on speader" spript in a loop. And lastly, is there a way to make it so that the "Turn on speaker" option is replaced by the "Turn off speaker" option after it has been selected, so that the audio sample don't play more than once over each other when players select "Turn on speakers" more than once?

speaker1.sqs
Code: [Select]
#loop
hummvee1 say "Sample1"
~15
?!(alive hummvee1):exit
goto "loop"

hummvee1 initialization
Code: [Select]
this addAction ["Turn on speakers","speaker1.sqs"]

Offline i0n0s

  • Former Staff
  • ****
Re: addAction Audio Script
« Reply #1 on: 04 Feb 2009, 19:17:58 »
say is local and addAction too.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addAction Audio Script
« Reply #2 on: 04 Feb 2009, 19:31:34 »
Easiest is this I think:

Change the addAction script to:
speakerOn = true
publicVariable "speakerOn"
exit

Trigger, repetedly.
Condition: speakerOn
onActivation: []  exec "speaker1.sqs"; speakerOn = false

This solution will make everyone hear the sound in MP.

To turn off the speaker instantly... I don't know if that is possible. Maybe by creating and setpos'ing a gameLogic that "says sound" right next to the car on a tight loop.

To my knowledge there is no way to stop a "living and existing" object/unit from saying sound until the sound file is done. The gameLogic could be repetedly created and deleted though.

Stopping the script that plays the sound could be done by adding another action that sets a variable to true.
That variable is then checked for in the speaker1.sqs script and if true : exit

Laggy
« Last Edit: 04 Feb 2009, 19:36:58 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Rommel92

  • Members
  • *
Re: addAction Audio Script
« Reply #3 on: 04 Feb 2009, 20:44:07 »
Making easier sense of laggy's solution, as he forgot to leave the say in the add action.
Code: (Init Line of HUMMER) [Select]
this addAction ["Turn on Speakers","speaker1.sqf"];

Code: (init.sqf) [Select]
AK_Speaker = false;
"AK_Speaker" addPublicVariableEventHandler {if (_this select 1 select 0) then {hummvee1 say "Sample1"} else {};}

Code: (speaker1.sqf) [Select]
if (AK_Speaker) then {} else
{
private"_i";
_i = 0;
while{alive humvee1} do {
_i = _i + 1;
AK_Speaker = [true, _i];
hummvee1 say "Sample1";
publicVariable "AK_Speaker";
sleep 15;
};
AK_Speaker = [false, _i];
publicVariable "AK_SpeakerOn";
};
« Last Edit: 04 Feb 2009, 20:47:38 by Rommel92 »

Offline aceking

  • Members
  • *
Re: addAction Audio Script
« Reply #4 on: 05 Feb 2009, 01:07:56 »
Thanks for the help you guys. Okay, so I've placed all the codes just as it is above and it plays the audio track, but when I select it again, an error message will pop up, which I'm guessin is becuase I don't have a "Turn off speaker" action yet So, how would I make it so that I could "Turn off speakers"? Also, once I've made a "Turn off speakers", would it come up with that error message if I did "Turn on speakers" again?

I tried making an action that turned the variable true like this, but it didn't work.
Code: [Select]
AK_Speaker = [true, _i];
publicVariable "AK_SpeakerOn";

Also, I'm making a 2nd hummvee (hummvee2) that would also have the same speaker action. Could I just simply assign the same script as the 1st hummvee, except change all the "hummvee1"s to "hummvee2"s? If so, then wouldn't the varable get mixed up between the two hummvee's, like one hummmvee changes the variable, then the second hummvee's doesnt work?
I tried making another script for the 2nd hummvee except with "AK_Speaker2" and "hummvee2", but for some reason, I keep getting an error message.
« Last Edit: 05 Feb 2009, 06:34:14 by aceking »

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: addAction Audio Script
« Reply #5 on: 07 Feb 2009, 01:43:28 »
In this case you want to pass the hummv name to the script that way it could be added to any vehicle.


Code: [Select]
this addAction ["Turn on Speakers","speaker1.sqf", [_this]];

then in your script... fetch the variable...

Code: [Select]
_vehicle = ((_this select 3) select 0);

then use _vehicle in place of hummer.

Xbox Rocks

Offline Rommel92

  • Members
  • *
Re: addAction Audio Script
« Reply #6 on: 08 Feb 2009, 01:42:31 »
<UPDATED NEXT POST>

Forgive me if this doesn't work, once I get home I may jump into ArmA and give it a burl and get rid of any kinks and possible issues.
« Last Edit: 08 Feb 2009, 12:11:54 by Rommel92 »

Offline aceking

  • Members
  • *
Re: addAction Audio Script
« Reply #7 on: 08 Feb 2009, 07:34:31 »
<UPDATED NEXT POST>

Hey Rommel92, thanks again for helping me out. I put the codes in, but there seems to be no added action options on the vehicle in the menu. Also, when I start the mission, I get this error message:
« Last Edit: 08 Feb 2009, 13:15:55 by aceking »

Offline Rommel92

  • Members
  • *
Re: addAction Audio Script
« Reply #8 on: 08 Feb 2009, 12:12:38 »
Sorry, forgot a little pre-requisite.

Code: (HWMMV Init Line) [Select]
nil = [this,"","",-1] execVM "ROMM_carAudio.sqf"
Code: (ROMM_carAudio.sqf) [Select]
// 0 : Turn on Speakers
// -1 : Turn off Speakers

private["_car","_id","_arg","_var"];
_car = _this select 0;
_id = _this select 2;
_arg = _this select 3;

switch (_arg) do {
case 0: {
_car removeAction _id;

if (alive _car) then {
call compile format["ROMM_%1AUDIO = true", _car];
[_car] spawn {
_car = _this select 0;
_var = call compile format["ROMM_%1AUDIO", _car];
while {_var AND alive _car} do {
_car setvehicleinit "this say 'sample1'";
processinitcommands;
sleep 15;
};
};
_car addaction ["Disable Audio","ROMM_carAudio.sqf",[1]];
};
};
case -1: {
if NOT(isnil format["ROMM_%1AUDIO", _car]) then {_car removeAction _id};
if (alive _car) then {
call compile format["ROMM_%1AUDIO = false", _car];
_car addaction ["Enable Audio","ROMM_carAudio.sqf",[0]];
};
};
};
« Last Edit: 08 Feb 2009, 12:14:13 by Rommel92 »

Offline aceking

  • Members
  • *
Re: addAction Audio Script
« Reply #9 on: 08 Feb 2009, 13:15:30 »
Hey Rommel92, I do get a "enable audio" option from the action menu this time. But I still get no sound and I get another error message at the beginning of the mission: