Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Fuzzy Bandit

Music only playing locally...

Recommended Posts

Hello!

I'm creating a sort of comedy mission where there's a suicide bomber. Now at the moment everything works fine. He has an action is his menu which makes him explode, and I'd tell you the objective of the game but you'd steal it 'cause it's genius! :P

Anyway, there's a sound which should play, followed by a 6 second gap, followed by the explosion every time the civilian uses the action in his scroll menu. At the moment everything is functional but the sound only plays locally, meaning that only the civilian can hear it. I'm not sure if it's a 'Server <-> Client' problem, or whether it's just because the civilian is on a different 'team' as it were, but I want everybody in the server to be able to hear the sound, as currently only the bomber can hear it, and it's essential that everybody in the game hears.

Currently I've got the following in my mission folder:

init.sqf

(Placed in same folder as 'mission.sqm')

suibomber addAction ["Explode", "bombit.sqf"];

bombit.sqf

(Placed in same folder as 'mission.sqm')

playMusic "killyou";
sleep 5;
bomb = "Bo_GBU12_LGB" createVehicle getPos suibomber;

Description.ext

(Placed in same folder as 'mission.sqm')

showCompass = 1;
showGPS = 1;
showWatch = 1;

respawn = "BASE";
respawnDelay = 15;

class CfgMusic
{
tracks[] = {killyou};

class ST_1
{
	name = "killyou"; 
	sound[] = {\music\killyou.ogg, db + 0, 1.0};
	titles[] = {0, ""};
};
};

killyou.ogg

(Inside the mission folder I have created a folder called 'music' and put the file 'killyou.ogg' inside there)

So is there something specific I need to do to enable the sound to be heard server-wide? Also if it's any consolation this most probably won't be played on a large scale. It'll most probably be played with a few friends on my own (hosted from my computer) server.

So yeh, anyone who can tell me how I can get everyone in the server to hear the sound file?

Cheers!

Share this post


Link to post
Share on other sites

Try placing a trigger with the condition !isNil "killyou" and on act: playMusic "killyou". In bombit.sqf replace the playMusic line with killyou=true;publicVariable "killyou".

It's a locality problem in the action script because not everyone has it executed. Making a global switch that activates the music in a trigger that everyone has makes the music play for everyone.

Share this post


Link to post
Share on other sites

Fabulous! I'll try that tomorrow when I've got access to ARMA - sound very promising!

So basically only the bomber is executing the script, so only he is executing the sound, so only he is hearing it, right?

Thanks very much and I'll give you a holler tomorrow to see if it works! ^_^

Share this post


Link to post
Share on other sites
In bombit.sqf replace the playMusic line with killyou=true;publicVariable "killyou".

Could I also do something like:

killyou = true;publicVariable "killyou";
sleep 0.01;
killyou = false;publicVariable "killyou";

I need the ability to call the sound again and again, but this doesn't seem to be working!

Share this post


Link to post
Share on other sites

ehm, why not just writing

playMusic "killyou"; killyou = false

into the triggers init line, and in the condition goes just

killyou

Would be better to initialize killyou with false somewhere in your init.sqf.

Share this post


Link to post
Share on other sites

Ok I set up a test mission for repeating sounds. Ideally this would be done all inside a script as opposed to creating any triggers what-so-ever.

At the moment I've got this in my init.sqf:

suibomber addAction ["Explode", "killyou.sqf"];
killyou=false;publicVariable "killyou";

'killyou.sqf' simply has:

killyou = true;

in it.

Then there's a trigger with:

killyou

playMusic "killyou"; killyou = false

I can play the sound once, and others can hear it, but the sound won't play again.

Share this post


Link to post
Share on other sites

Think again. Something is not necessary and something is missing. ;)

Share this post


Link to post
Share on other sites

On in all honesty I've sat here for a while trying to figure it out and just can't! :D

Just tell me damn it! :P

Share this post


Link to post
Share on other sites

In your Init.sqf goes

killyou = false;

We initialize the variable killyou, nothing more, and nothing less. Also regard that, whatever is written in the init.sqf, it is executed on every machine. So absolutely no point in broadcasting it.

You want the trigger to activate on all machines once a single machine sets the variable killyou to true. So at this point the variable has to be broadcasted. In the killyou.sqf goes

killyou=true; publicVariable "killyou";

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

My approach would be to use publicVariable together with publicVariableEventhandler, as it completely separates your script from the editor/mission.sqm:

In init.sqf goes:

"killyou" = true; //or whatever you want it to initialize with, it doesn't matter
"killyou" addPublicVariableEventHandler {playMusic "killyou"};

In killyou.sqf goes:

playMusic "killyou";
publicVariable "killyou";

No more triggers etc. needed.

Please make yourself familiar with publicVariable and addpublicVariableEventHandler and try to understand what exactly happens here and why - its in your own interest.

Edited by Bon

Share this post


Link to post
Share on other sites

Ok, I've got what's going on! :P

As you say, '"killyou" = false;' just creates a variable called 'killyou' with the value 'false'. We do that in the init.sqf so that everybody's machine creates the variable.

Adding the Event Handler to the variable 'killyou' means that when that variable's value changes, some code will be initiated. In this case, 'playMusic "killyou"'.

When a player then executes 'killyou.sqf', it will play the music 'killyou' to that player, and also broadcast to all machines the value of the variable 'killyou'.

As a last question (as I don't currently have access to ARMA, and so can't actually test the damned mission at the moment!):

Does the simple line 'publicVariable "killyou";' trigger the Event Handler in the init.sqf? If so, that would indeed mean that I could play the sound over and over again by simply executing 'killyou.sqf' from an action, correct?

Thank you tonnes for the help. If I'm right in the text above, then I've learnt a fab lesson, and I can go on to perfect a multiplayer artillery script I've been painstakingly working on for a while!

Cheers again!

Share this post


Link to post
Share on other sites

Yep, all correct. :ok:

Using publicVariable you broadcast a variable to all machines. A broadcasted variable triggers the code in the publicvariableeventhandler on all machines that deliver the broadcasted variable, but not on the sending machine itself. That's why we also have to playMusic in killyou.sqf.

Share this post


Link to post
Share on other sites

You're a star Bon! Thanks very much! I'm learning bits and bobs here and there - every little helps! :P

Share this post


Link to post
Share on other sites

I looked through that link, but I'm still not totally sure about how to implement that into a game.

Also Bon, I finally got some time to test out the code you sent me. It works, and I can repeatedly play a sound whenever I want, but nobody else can hear it. I also tested with another player being the "Sound Man" (the man with the ability to call in the sounds). They themselves could hear it, but nobody else could.

So, the repeating issue is all fine now, and I can play the sound again and again, but now we're back to locality issues. Only the person calling the sound can hear them. By the way, I've just got a simple mission with 2 playable characters along with the exact code you supplied in the previous post. All that is added is the following to the init.sqf:

man1 addAction ["Kill You!", "killyou.sqf"];

Przemek_kondor - if I wanted to play a sound to everybody in the server, would I just use the following code?

[nil,nil,rPLAYMUSIC,"killyou"] call RE;

Share this post


Link to post
Share on other sites
Sign in to follow this  

×