Jump to content
'Darkruffian

Problem with looping a songfile while synchronizing it for all players

Recommended Posts

Hello folks,

 

I've searched far and wide throughout different forums via Google to find a way to fix my problem. And maybe I suck at searching or it's a rare issue for people to be had.

I'm building a multi-part multiplayer campaign to be played on a dedicated server with a focus on immersion and am trying to get a music file to loop.

 

Sadly, I have a couple of problems to address, and I'm sure I'm just not acquainted enough with the scripting in Bohemias' Engine and just need to use a whole other call-method.

 

My entire script works in theory (meaning in SP and if I'm the only person on a hosted multiplayer server. Didn't verify being alone in a dedicated server), however I fear that I need to use remoteExec. And I couldn't grasp its usage by looking at the wiki and in any forum mentioning it they seem to expect people to be already familiar with how it works and - especially - in what *file* it goes (as in if the init.sqf is fine or it needs a whole other file)

 

___


What's supposed to happen is - there's a mechanic with a phone laying in front of him. As long as the dude is alive, a songfile consisting of 3 songs is supposed to loop. It's 675 seconds long, which is why I added a lee-way of 15 additional seconds of pause before the loop begins (aka 690 seconds of sleep). My code for it is inside my "init.sqf", tho I also tried spawning it ingame via a trigger. It didn't change a thing:

 

[] spawn {

    while{alive phone} do{
        playSound3D [getMissionPath "sounds\Rock2.ogg", handy, false, getPosASL handy, 3, 1, 10];
        uiSleep 690;
    };
    
};

 

 

It's apparent to me that my script triggers for each client as uiSleep seems to count for each individual player. I tested it with a friend of mine and after some time it starts the loop way too soon - meaning it plays on top of each other. 

It also doesn't synchronize the soundfile. If I alt+tab the song "pauses" for my client until I get back into the game, whereas it will pick up where it left off while my friend was already a song ahead. So it gets even worse when it starts another song-session on top of that one.

And even if I stay ingame the whole time - the script still will start a 2nd round, playing music on top of each other for me - but my friend hears it fine for some time. He only claimed minutes later, that he too started noticing it looping too soon.

 

It seems to happen randomly, too. Sometimes I had the script trigger again within the first song, sometimes only close to the end of the third song.

Putting the script into a serverInit.sqf made it that, when I hosted the mission, only I could hear it (since I'm the "server", I'd reckon) and my friend heard nothing. It still didn't help, tho, as the same problem still transpired.

 

I'm familiar with the Initialization Order , tho couldn't think of any other init-file to put the code - and don't think that it is the sole problem of my script. Also I  know that sleep is a tricky thing to work with in multiplayer environments. uiSleep however didn't help either, as in this case.

I was looking for a more persistant time measure to use - but using "time" apparently would be the worst thing to do yet, same for "serverTime". Also I'm uncertain whether using another time measure with a "waitUntil" would do the trick.

 

 

I need the soundfile to loop for the entire duration of the mission - with a timer that doesn't count for each player (hence triggering the script up to 20x - once per player) - and (if possible) synchronized with all players. So that if one decides to Alt+Tab and then gets back to the game the song is at the same spot for each player.

 

If any veteran script-builder or anyone familiar with this topic would kindly show me the way to succeed with this endeavour I'd be indebted to him.

 

 

Also also - I already found some code examples to have the songfile terminate immediately, should the mechanic die. I just didn't incorporate it yet, as I want to fix this tedious problem before adding other flavour things.

 

 

I thank you in advance for any input that might help me resolve my issue.

Share this post


Link to post
Share on other sites

Ahh, the joys of MP scripting. So, remoteExec is the most powerful command for MP around. If you want to do something synchronized you have to synchronize it for all machines. this means that you loop a timer on one machine (usually the server) and broadcast the information over the network periodically. So I would go for the following setup:

Create a function that handles the music locally. This includes the stopping of the previous song and the playing of the next one.

// functions\Music\fn_handyMusic.sqf
params ["_track"];
if (!isNil "TAG_fnc_handyMusic_sound") then {
    // Remove old sound source
    deleteVehicle TAG_fnc_handyMusic_sound;
};
TAG_fnc_handyMusic_sound = handy say3D [
    _track, // CfgSounds class
    10 // distance
];

Handle the timer on the server with initServer.sqf from where you broadcast the function every x seconds.

// initServer.sqf
while {alive obj} do {
    ["Track1"] remoteExec ["TAG_fnc_handyMusic", 0];
    sleep 690;
};

Make sure that all the settings in the description.ext are set:

// description.ext
class CfgSounds
{
	...

class CfgFunctions
{
	class TAG
	{
		class Music
		{
			class handyMusic;
		};
	};
};

 

Synchroizing the music so that every player hears the same at any given time is possible but would take up more network.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Now I implemented your solution and so far it seems to work exactly how it should. Tho today I won't find anyone to test it out in a multiplayer environment with me.

I trust, however, that with the usage of remoteExec it will refrain from having the exact same issues.

 

Should further problems arise then I'll post them here.

 

Thanks to your solution I might also be able to now reverse engineer usage of remoteExec for future reference. Practical examples I can deal much better with than with a wikis' explanation.

 

I appreciate your input and the time you took to scribble it down, 7erra

 

 

Synchronizing it so the music plays at the same time stamp for everyone is a secondary objective anyway, since I trust that no one will have the need of alt+tabbing throughout the missions.

And even then, I assume the

 

Quote

if (!isNil "TAG_fnc_handyMusic_sound") then { // Remove old sound source

deleteVehicle TAG_fnc_handyMusic_sound;

 

will just stop it for everyone and restart it for everyone aswell, which is fine.

Share this post


Link to post
Share on other sites
17 hours ago, 'Darkruffian said:

Tho today I won't find anyone to test it out in a multiplayer environment with me.

You can start arma 3 twice via the command line. that way you can connect to your own server twice, once as host and once as client.

  • Like 2

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

×