Here is a script in which one can play music in a vehicle.(civil cars & other vehicles)
In this script you can-
- Edit the script and add more songs.
- Play/stop any songs.
- Play a random song.
First open any map and place a empty vehicle and in its init place code-
PlaySongs = this addaction ["Start music player","musicplayer.sqf",true,1,false,true,"","player in _target"];
And save as mission.
Next open your mission folder and create a folder named as music.
Inside the music folder place your songs in .ogg format and name them as track1,track2,track3 or any other name.
Then create description.ext with notepad and place this code-
class CfgSounds
{
sounds[]={song1,song2,song3};
class song1
{
name = "song1";
sound[] = {"music\track1.ogg",0.5,1};
titles[] = { };
};
class song2
{
name = "song2";
sound[] = {"\music\track2.ogg",0.5,1};
titles[] = { };
};
class song3
{
name = "song3";
sound[] = {"\music\track3.ogg",0.5,1};
titles[] = { };
};
};
And place description.ext in mission folder.
Next open notepad and create scripts as written below.
NOTE- To run this in MP then add line - if (!isServer) exitWith {}; at top of music.sqf
music.sqf
//Music.sqf
_vehicle = _this select 0;
_playtracks = _this select 3;
sleep 2;
switch (_playtracks) do {
case 1: //playing song 1
{
soundsource1 = "can_small" createVehicle [0,0,0];
hideObject soundsource1;
sleep 1;
soundsource1 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource1 say3d "song1";
closesong1 = _vehicle addaction ["stop song 1","stopsong.sqf",1];
};
case 2: //playing song 2
{
soundsource2 = "can_small" createVehicle [0,0,0];
hideObject soundsource2;
sleep 1;
soundsource2 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource2 say3d "song2";
closesong2 = _vehicle addaction ["stop song 2","stopsong.sqf",2];
};
case 3: //playing song 3
{
soundsource3 = "can_small" createVehicle [0,0,0];
hideObject soundsource3;
sleep 1;
soundsource3 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource3 say3d "song3";
closesong3 = _vehicle addaction ["stop song 3","stopsong.sqf",3];
};
case 4://playing random song.
{
soundsource4 = "can_small" createVehicle [0,0,0];
hideObject soundsource4;
sleep 1;
soundsource4 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing any song!.....";
sleep 3;
_songs = ["song1","song2","song3"];
soundsource4 say3d (_songs select floor(random(count _songs)));
closerandomsong = _vehicle addaction ["stop random song","stopsong.sqf",4];
};
case 5: //closing music player
{
_vehicle removeaction playtrack1;
_vehicle removeaction playtrack2;
_vehicle removeaction playtrack3;
_vehicle removeaction playrandomsong;
_vehicle removeaction closeplayer;hint "Music player switched off!";
PlaySongs = _vehicle addaction ["Start music player","musicplayer.sqf",true,1,false,true,"","player in _target"];
};
};
stopsong.sqf
//Stopsong.sqf
_vehicle = _this select 0;
_stopsongs = _this select 3;
sleep 2;
switch (_stopsongs) do {
case 1: //stopping song 1.
{
hint "select other song!";
deletevehicle soundsource1;
sleep 0.1;
_vehicle removeaction closesong1;
};
case 2://stopping song 2.
{
hint "select other song!";
deletevehicle soundsource2;
sleep 0.1;
_vehicle removeaction closesong2;
};
case 3: //stopping song 3.
{
hint "select other song!";
deletevehicle soundsource3;
sleep 0.1;
_vehicle removeaction closesong3;
};
case 4://closing random song.
{
hint "Random song stopped!....";
deletevehicle soundsource4;
sleep 0.1;
_vehicle removeaction closerandomsong;
};
};
Place musicplayer.sqf, music.sqf and stopsong.sqf in mission folder and preview mission.
To use this script ingame in a vehicle -
- Open music player with scrollmenu.
- Select & Play/stop songs with addaction.
- Close music player with scrollmenu.
This post was edited by warbird (2016-01-13 20:22, ago)
Hi , thank you for this script , but is it compatible with arma 3?
I'm asking this because the language that you are using for this script is similar with some arma 3 scripts.
I tried to insert this in arma 3 , but when I put the init code in the empty car , I get this error :
Nothing... same problem , but if i remove "playmusic = it accept the init.
But when i try to play the song n.1 nothing happen , it seems like the script starts but I can't hear the music.
OK, i see, playmusic is an arma command. You can't use it for a variable (it's already an engine variable in fact). So, change playmusic for any word you want but no command name. Something like my_radio.
then, be sure you have all ogg files in a created sub directory music in mission folder.
PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS
This script uses createVehicle command with object classname from A2, therefore to use in A3 u should
edit this line - soundsource1 = "can_small" createVehicle [0,0,0]; in music.sqf to this
soundsource1 = "Land_FMradio_F" createVehicle [0,0,0];
similarly for soundsource2,soundsource3,soundsource4 etc.
like this-
//Music.sqf
_vehicle = _this select 0;
_playtracks = _this select 3;
sleep 2;
switch (_playtracks) do {
case 1: //playing song 1
{
soundsource1 = "Land_FMradio_F" createVehicle [0,0,0];
hideObject soundsource1;
sleep 1;
soundsource1 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource1 say3d "song1";
closesong1 = _vehicle addaction ["stop song 1","stopsong.sqf",1];
};
case 2: //playing song 2
{
soundsource2 = "Land_FMradio_F" createVehicle [0,0,0];
hideObject soundsource2;
sleep 1;
soundsource2 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource2 say3d "song2";
closesong2 = _vehicle addaction ["stop song 2","stopsong.sqf",2];
};
case 3: //playing song 3
{
soundsource3 = "Land_FMradio_F" createVehicle [0,0,0];
hideObject soundsource3;
sleep 1;
soundsource3 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource3 say3d "song3";
closesong3 = _vehicle addaction ["stop song 3","stopsong.sqf",3];
};
case 4://playing random song.
{
soundsource4 = "Land_FMradio_F" createVehicle [0,0,0];
hideObject soundsource4;
sleep 1;
soundsource4 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing any song!.....";
sleep 3;
_songs = ["song1","song2","song3"];
soundsource4 say3d (_songs select floor(random(count _songs)));
closerandomsong = _vehicle addaction ["stop random song","stopsong.sqf",4];
};
case 5: //closing music player
{
_vehicle removeaction playtrack1;
_vehicle removeaction playtrack2;
_vehicle removeaction playtrack3;
_vehicle removeaction playrandomsong;
_vehicle removeaction closeplayer;hint "Music player switched off!";
PlaySongs = _vehicle addaction ["Start music player","musicplayer.sqf",true,1,false,true,"","player in _target"];
};
};
Ok thank you guys for help , i'll try this as soon as possible.
Greetings ,
Frapax
Added 29 minutes later:
Ok I did what warbird wrote , but I've another problem...(sorry if i'm wasting your time)
Only the first song works , meanwhile i can't hear the others.
I tryied to set for every sound source an object but it doesn't work. (I did this after I tried as Warbird wrote)
//Music.sqf
_vehicle = _this select 0;
_playtracks = _this select 3;
sleep 2;
switch (_playtracks) do {
case 1: //playing song 1
{
soundsource1 = "Land_FMradio_F" createVehicle [0,0,0];
hideObject soundsource1;
sleep 1;
soundsource1 attachTo [_vehicle,[0,0,0]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource1 say3d "song1";
closesong1 = _vehicle addaction ["stop song 1","stopsong.sqf",1];
};
case 2: //playing song 2
{
soundsource1 = "Land_Can_V2_F" createVehicle [0,0,2];
hideObject soundsource2;
sleep 1;
soundsource2 attachTo [_vehicle,[0,0,2]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource2 say3d "song2";
closesong2 = _vehicle addaction ["stop song 2","stopsong.sqf",2];
};
case 3: //playing song 3
{
soundsource1 = "Land_TacticalBacon_F" createVehicle [0,0,3];
hideObject soundsource3;
sleep 1;
soundsource3 attachTo [_vehicle,[0,0,3]];
sleep 1;
hint "playing song!.....";
sleep 3;
soundsource3 say3d "song3";
closesong3 = _vehicle addaction ["stop song 3","stopsong.sqf",3];
};
case 4://playing random song.
{
soundsource1 = "Land_Can_V1_F" createVehicle [0,0,4];
hideObject soundsource4;
sleep 1;
soundsource4 attachTo [_vehicle,[0,0,4]];
sleep 1;
hint "playing any song!.....";
sleep 3;
_songs = ["song1","song2","song3"];
soundsource4 say3d ( _songs select floor(random((count _songs) - 0.5 )));
closerandomsong = _vehicle addaction ["stop random song","stopsong.sqf",4];
};
case 5: //closing music player
{
_vehicle removeaction playtrack1;
_vehicle removeaction playtrack2;
_vehicle removeaction playtrack3;
_vehicle removeaction playrandomsong;
_vehicle removeaction closeplayer;hint "Music player switched off!";
playmusic = _vehicle addaction ["Start music player","musicplayer.sqf",true,1,false,true,"","player in _target"];
};
};
Greetings ,
Frapax.
Added 7 minutes later:
Ok ,my bad i found the error .
I wrote soundsource1 for all the cases so only the first was working.
Thank you for the help
This post was edited by Frapax (2016-01-15 11:54, ago)