Forum Jump :

Author Message


Posts: 89
Rank:


Level: Member

Country: in
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2015-12-30 22:08        
     
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.

musicplayer.sqf
//Musicplayer.sqf
_vehicle = _this select 0;

hintSilent "Music player switched on!";

sleep 2;

hintsilent "";

sleep 2;
playtrack1 = _vehicle addaction ["Track 1","music.sqf",1];
playtrack2 = _vehicle addaction ["Track 2","music.sqf",2];
playtrack3 = _vehicle addaction ["Track 3","music.sqf",3];
playrandomsong = _vehicle addaction ["Play Random song","music.sqf",4];
closePlayer = _vehicle addaction ["Close Music player","music.sqf",5];

sleep 0.1;
_vehicle removeaction PlaySongs;

exit;

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)


Author Message


Posts: 11
Rank:


Level: Member

Country: it
Location:
Occupation: Hating Arma's .bin
Age: 21
In-game name: Frapax

 
#2 Posted at 2016-01-12 19:17        
     
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 :

http://imgur.com/gallery/rtAYhzy/new

I hope that you will help me , thank you in advance. :-)


Advertisement


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#3 Posted at 2016-01-12 21:42        
     
you should try :
playmusic = this addaction ["Start music player","musicplayer.sqf",true,1,false,true,"","_this in _target"]; instead.

_songs select floor(random((count _songs) - 0.5 ) ??? You don't need - 0.5

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 11
Rank:


Level: Member

Country: it
Location:
Occupation: Hating Arma's .bin
Age: 21
In-game name: Frapax

 
#4 Posted at 2016-01-13 16:13        
     
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.

http://imgur.com/gallery/VLR6u4Y/

Greetings ,
Frapax


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#5 Posted at 2016-01-13 19:40        
     
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

Author Message


Posts: 89
Rank:


Level: Member

Country: in
Location:
Occupation:
Age:
In-game name:

 
#6 Posted at 2016-01-13 20:05        
     
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"];

};
};
or choose any other small items classname from here- https://community.bistudio.com/wiki/Arma_3_CfgVehicles_EMPTY#Land_FMradio_F
And preview mission.

EDIT - I have edited the script and have now used Playsongs as new addaction name.

This post was edited by warbird (2016-01-16 00:32, ago)


Author Message


Posts: 11
Rank:


Level: Member

Country: it
Location:
Occupation: Hating Arma's .bin
Age: 21
In-game name: Frapax

 
#7 Posted at 2016-01-15 10:34        
     
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)


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#8 Posted at 2016-01-15 15:35        
     
Now, your car looks like a vending machine.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS