Jump to content
Sign in to follow this  
bangtail

Radio in Car

Recommended Posts

If I want to have a sound playing while Im in a car (Car Radio). How can I accomplish this, I would like it so that when I exit the car it stops playing and starts when I get in.

Cheers

E

Share this post


Link to post
Share on other sites

put this in the initilization line of any vehicle

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["getin", {playMusic "ATrack24"}];this addEventHandler ["getout", {playMusic ""}]

this would work for a single player game.

Share this post


Link to post
Share on other sites

damn it works but not with custom music sad_o.gif

i put a music folder containing trance.ogg in the mission directory, then added this line to the cars init.

this addEventHandler ["getin", {playMusic "\music\trance.ogg"}];this addEventHandler ["getout", {playMusic ""}]

what am i doing wrong ?

Share this post


Link to post
Share on other sites

it is probabbly possible to play a sound direcly from your mission folder , but a workaround would be to place all the songs you want to use in a PBO with a little config containing these lines.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class CfgSounds

{

class song1

{name="song1";

sound[]={"\PboName\song1.ogg",80.000000,1.000000};titles[]={};

};

};

Share this post


Link to post
Share on other sites

i use a similar config in my description.ext for playing custom music with triggers,but i can't figure out how to just have the music playing when i enter a car,and have it stop when disembark.

Share this post


Link to post
Share on other sites

it does not find the sound because it is not properly defined in the config , if you search a little more i'm sure you'll find the solution tounge2.gif

from sounds.pbo config :<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class CfgMusic {

class ATrack6 {

name = "01 Street Combat";

sound[] = {"\ca\Sounds\Music\aa_rock_theme_vi.ogg", db0, 1.0};

};

}

Share this post


Link to post
Share on other sites
Guest

You know, u could go just a tad farther after getting the initialization thru event handler, and instead of playing the music at that point, addaction to player for the radio, that way player can actually turn on/off the radio (cd player, whatever tounge2.gif). Then still use the event handler out to shut it off if radio was left on...

Share this post


Link to post
Share on other sites
You know, u could go just a tad farther after getting the initialization thru event handler, and instead of playing the music at that point, addaction to player for the radio, that way player can actually turn on/off the radio (cd player, whatever tounge2.gif). Then still use the event handler out to shut it off if radio was left on...

K, thats awesome, thanks a lot guys!

E

Share this post


Link to post
Share on other sites
You know, u could go just a tad farther after getting the initialization thru event handler, and instead of playing the music at that point, addaction to player for the radio, that way player can actually turn on/off the radio (cd player, whatever tounge2.gif). Then still use the event handler out to shut it off if radio was left on...

Can you elaborate on that buddy?

Cheers

E

Share this post


Link to post
Share on other sites
Guest

Gimme a few more, im finishing up this. Ill post the scripts that can be copied and pasted, been more of a pain then I thought, but it works wink_o.gif Basically, its ready to go, u get in, u can select radio on/ radio off and it plays music depending on selection. I wanted to try using sound instead of music for 3d positioning, but cant find a way to stop the sound from playing at any time going this route, so itll have to be music. Right now tho, u always get the radio on/ radio off options, and im seeing if I can just allow editor (you) to put in length of time that the particular .ogg length is thats being played, and allow radio/On after its been turned on only if song/radio chatter has fully played, this way player cant hit 'radio on' and restart the music fifty times half way thru.

Share this post


Link to post
Share on other sites

I added a few more options to the Vehicle...(goes well when flying around).

so now when you get in a vehicle you have......

Radio On

Radio off

Next Song

Prev Song

Start with you might need a mp3 to ogg converter

Audacity open source.

description.ext

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class CfgMusic

{

tracks[]={};

class Track1

{

name = "track1";

sound[] = {\music\track1.ogg, db+0, 1.0};

};

class Track2

{

name = "track2";

sound[] = {\music\track2.ogg, db+0, 1.0};

};

class Track3

{

name = "track3";

sound[] = {\music\track3.ogg, db+0, 1.0};

};

class Track4

{

name = "track4";

sound[] = {\music\track4.ogg, db+0, 1.0};

};

};

Veh_Radio.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;args: [vehicle]

_veh = _this select 0

SQ_Playing = 1

playMusic "track1";

_veh addAction ["Radio off","TurnOff.sqs"];

_veh addAction ["Next Song","NextSong.sqf"];

_veh addAction ["Prev song","PrevSong.sqf"];

NextSong.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">SQ_Playing = SQ_Playing + 1;

if(SQ_Playing == 5)then {SQ_Playing = 1};

switch (SQ_Playing) do

{

case 1:

{

playMusic "track1";

};

case 2:

{

playMusic "track2";

};

case 3:

{

playMusic "track3";

};

case 4:

{

playMusic "track4";

};

};

exit;

PrevSong.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">SQ_Playing = SQ_Playing - 1;

if(SQ_Playing == 0)then {SQ_Playing = 4};

switch (SQ_Playing) do

{

case 1:

{

playMusic "track1";

};

case 2:

{

playMusic "track2";

};

case 3:

{

playMusic "track3";

};

case 4:

{

playMusic "track4";

};

};

exit;

Turnoff.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">playMusic ""

exit;

Make sure you don't mix up the sqs and sqf extensions.

and you still need this line in the init of the vehicle :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["getin", {this addAction ["radio on", "veh_radio.sqs"]}];this addEventHandler ["getout", {playMusic ""}]

Since I'm learning any comments on mistakes or better options are most welcome help.gif

Share this post


Link to post
Share on other sites
Guest

SpedsVehicleRadio v1.1

Updated:

Works on multiple vehicles

Single player mission use only

Make a name for each vehicle that u want the radio in, then put the following in each vehicles init, and be sure to put the name of the vehicle in the two areas here that say :ThisVehicleName

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

this addEventHandler ["getin",{[1,ThisVehicleName] exec "Radio.sqs"}];this addEventHandler ["getout",{[2,ThisVehicleName] exec "Radio.sqs"}]

For reference, heres a description.ext you can copy and paste, then just use your own music file name, if your using your own instead of one imbedded in Arma

Description.ext

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class CfgMusic

{

tracks[]={};

class Spaced

{

name = "";

sound[] = {\music\Spaced.ogg, db+0,1.0};

};

};

//End of file

Heres the scripts:

Radio.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_InorOut = _this select 0

_vehicle = _this select 1

#IN

? _InorOut > 1:goto "OUT"

; if you dont want ugly action for radio on stuck on screen, this part is needed (it will force players to hit enter twice tho)

;both lines below, where you see 'hummer' put in the name of your vehicle (named thru the editor)

_vehicle addaction ["", "nothing.sqs"]

_vehicle addaction ["Radio on", "musicOn.sqs"]

Exit

#OUT

;Unit has gotten out of vehicle

;stop the music

playmusic ""

;set this variable to zero for use as a counter below

_NextIdNumber = 0

#RemoveActions

;added many removeactions to ensure no matter what the id are numbers are for the added actions, they will be removed

;id numbers for each addaction created do stack on a particular object, so this many is being safe

_vehicle removeaction _NextIdNumber

_NextIdNumber = (_NextIdNumber +1)

?_NextIdNumber > 1000: goto "EndScript"

goto "RemoveActions"

#EndScript

EXIT

musicOn.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;play music and add in the action 'radio off'

_vehicle = _this select 0

_id = _this select 2

playMusic "Spaced"

; remove the action once it is activated

_vehicle removeAction _id

_vehicle addaction ["Radio off", "musicOff.sqs"]

Exit

musicOff.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;turn off the music (play empty music file) and remove 'turn off' action

_vehicle = _this select 0

_OffId = _this select 2

playMusic ""

; remove the action once it is activated

_vehicle removeAction _OffId

_vehicle addaction ["Radio on", "musicOn.sqs"]

Exit

nothing.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

Exit

This has been thorughoughly tested, works perfect. There is one thing tho. Due to the fact that addAction likes to keep text in center of screen for new actions, I added in the 'nothing' script, which adds an action that has no text, although this removes that issue, there is still a slightly lingering(10 secs or so) appearance of players action list (and their corresponding icons/text, depending on what player has selected) during each action selection in that vehicle, but text no longer stays 'stuck' on screen from the new added actions (which it did previously until the 'nothing' action was added). Its a small inconvenience, and I dont think theres a better way to do this. Due to the added 'nothing' action, players initially - that is only for the first time they have entered the vehicle- will have to hit enter twice for that vehicle to bring up the action menu (so what tounge2.gif).

So, anyhow, its a fully funcitonal on/off switch for a vehicle radio. I did try to find a way to 'timeout' the sound play per sound, but its not reasonably possible, so, if the song ends, one can just hit 'radio off' and then radio on and can replay it.

This will also deactivate addactions for the vehicle when player has disembarked, so you cant activate the actions from outside the vehicle, will only keep 'radio on' or 'radio off' on your action menu, depending on if your playing music or not, and will also remove chances of actions 'stacking' on a vehicle from leaving and entering multiple times (unless one does that like 200 times in a mission tounge2.gif). And of course, this will also remove ugly center screen text that initially would come up as soon as you enter the vehicle.

This was kinda fun, a major lesson in the workings of addaction/removeAction, and took a heck of a long time to get around the stupid text showing at center screen. Thinking might make a 'cd' version of this too, where one can select multiple tracks, wouldnt be too hard to add in.

Btw - Ethne, I can also send you the whole radio test mission if you got msn messenger or yahoo messenger, just let me know.

//Can see someone else got here just before me, whichever works best wish u luck on this m8 smile_o.gif

Share this post


Link to post
Share on other sites

K, that rox guys! I only just woke up but as soon as I get it going Ill add you to MSN! I will need your E-mail, so PM it to me!

Cheers again

E

**EdiT** K, got them both going. Tx very much guys, they both work fine. I ended up using Senseless's ONLY because I needed it for more than one vehicle!

Cheers Again

E

Share this post


Link to post
Share on other sites
Guest

Updated to version 1.1, now can be ran on any number of vehicles, Single player mission use only.

Changes have been made to my previous posting of script above

Share this post


Link to post
Share on other sites

Nice one, will test it out a bit later as I am testing mission dynamics right now .... will let you know. Very much appreciated!

E

Share this post


Link to post
Share on other sites
Guest

Single player use only for my version of radio scripts

Share this post


Link to post
Share on other sites
damn it works but not with custom music sad_o.gif

i put a music folder containing trance.ogg in the mission directory, then added this line to the cars init.

this addEventHandler ["getin", {playMusic "\music\trance.ogg"}];this addEventHandler ["getout", {playMusic ""}]

what am i doing wrong ?

This :

Quote[/b] ]this addEventHandler ["getin", {playMusic "\music\trance.ogg"}];this addEventHandler ["getout", {playMusic ""}]

never worked becuase your track name is not called \music\trance.ogg smile_o.gif

it should be:

Quote[/b] ]this addEventHandler ["getin", {playMusic "trance.ogg"}];this addEventHandler ["getout", {playMusic ""}]
or just the name you called it in the description one of the two..

Share this post


Link to post
Share on other sites

Plus there was already something about a vehicle radio all you needed to do was search.

MP Car Radio.

With Example Mission.. Its good to search.

Share this post


Link to post
Share on other sites
Guest

Ya, theres no way im messing with the mp thing ,just spent hours trying to get it right, and deleted the whole thing. Id suggest trying out that link provided by Matt, my radio scripts version 1.1 are final, and they wont be mp compatable.

Gl

Share this post


Link to post
Share on other sites
description.ext
class CfgMusic

{

tracks[]={};

class Track1

{

 name = "track1";

 sound[] = {\music\track1.ogg, db+0, 1.0};

};

...

There are no quotes around \music\track1.ogg !?

I've been experimenting with playmusic yesterday and it always says 'can't find xxx' (were xxx would be Track1 in this case)

But i've always used doublequotes around the ogg file path. Would that be the reason? (I'm at work so i can't test it myself but am curious)

Share this post


Link to post
Share on other sites
description.ext
class CfgMusic

{

tracks[]={};

class Track1

{

name = "track1";

sound[] = {\music\track1.ogg, db+0, 1.0};

};

...

There are no quotes around \music\track1.ogg !?

I've been experimenting with playmusic yesterday and it always says 'can't find xxx' (were xxx would be Track1 in this case)

But i've always used doublequotes around the ogg file path. Would that be the reason? (I'm at work so i can't test it myself but am curious)

No the double quotes is not the reason you receive that error.

I had the same problem when writing that code so i named my song trackX, and eveything in the Cfg trackx to cover all base's and it worked so I left it at that.

Share this post


Link to post
Share on other sites

resurrecting an old post here, but for completeness sake here's some info.

sound[] = {"track1.ogg", db+0, 1.0};

is all that's needed, the folder the oggs need to be in should be called

{missionname}\Sound

I have been reasonable successful prototyping a working radio for MP using the say command instead of playSound, working from an addAction on the vehicle that runs a script to check it's the driver activating the radio. That script then sets a couple of variables locally, publicVariable's those up to the server, which catches those in a trigger, then in turn set's another flag variable and re-transmits the request to all clients using more publicVariable commands. The clients then catch this in their own triggers and then they all action a 'say' command against the notified vehicle.

Long way round, but it does work.

The problem I am getting is that if you switch it on whilst IN the vehicle the thing is much quieter for anyone inside, even when you/they get out again.

If you switch it on, and folks are outside, then they hear it properly at the required volume.

The db0 or db+X or db-X part of the cfgSounds definition doesn't affect the volume, but only seems to affect the range at which the sound can be heard. No other setting, anywhere at all, seems to affect the actual volume at all.

I know that this difference in sound with inside/outside activation will be due to the dampening/attenuating effect on sounds in the model's configs and the engine of ArmA, affecting the initial setting of the played sound when those listening are already inside, however - no matter what I try I cannot find a workaround for this.

Why should 'say' command be attenuated whilst inside? Perhaps due to shared code between the 'say' command and the environmental or engine noise? If that is so, why should the 'say' sound not get louder again when you do get back out of the vehicle?

If there's no workaround for this, then perhaps an additional item could be put onto the BIS gargantuan to-do list to provide a command that will not attenuate, or could a boolean non-attenuate option be added onto the end of the existing 'say' command?

Obviously that'll be a low priority if even considered, but I remember having the same problem with the OFP 'say' command years ago, and for it still to be awkward now is slightly annoying, given that the rest of the structure to support this radio thing has been in place for years. If a simple boolean option could be easily added onto 'say' to make the resulting sound un-attenuated, then PLEASE can this be done?

Share this post


Link to post
Share on other sites

I'd *REALLY* like to know if anyone got a working car radio in MP where you could get in the car, and hear the radio, and change songs from a custom list in description.ext...

Any help or links, appreciated great.

Russ

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  

×