Jump to content
  • 0

Start music only as new spawn


ftshill

Question

Currently on my server I have added start music. Every time you load into the server you are greeted by the start music which play for around 10-20 seconds. Some players have been complaining that the music can be distracting if they are loading into a sticky situation. Therefore I have been trying to find a way to only make the music play when the player is a new spawn. E.g. has no gear and is at one of the starting spawn.

If anyone has any ideas how to achieve this, please help me out!  :)

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

In your init.sqf;

if (!isNil "playersLoaded") then { playersLoaded = [];};

In your script that executes the sound;

if (!((getPlayerUID player) in playersLoaded)) then {
    //play sound code goes here
    playersLoaded = playersLoaded + [(getPlayerUID player)];
    publicVariable "playersLoaded";
};

In your publicvariable.txt add to the first line (The one that has 5 "");

!="playersLoaded"

This SHOULD work, but is untested as I just wrote it now :)

 

ALTERNATIVELY!

 

You could also optimise this to be more friendly on network traffic by using publicVariableServer calls.

 

In your server_functions.sqf;

if (isNil "serverPlayersLoaded") then { serverPlayersLoaded = [];};

fnc_HandleLoadedPlayers = {
    private ["_vars","_uid","_owner"];
    _vars = _this select 1;
    _uid = _vars select 0;
    _owner = _vars select 1;
    if (!(_uid in serverPlayersLoaded)) then {
        serverPlayersLoaded = serverPlayersLoaded + [_uid];
        serverHasUID = true;
        _owner publicVariableClient "serverHasUID";
    };
};

"serverCheckUID" addPublicVariableEventHandler fnc_HandleLoadedPlayers;

In your script that spawns the sounds;

if (isNil "serverHasUID") then { serverHasUID = false; };

serverCheckUID = [(getPlayerUID player),owner player];
publicVariableServer "serverCheckUID";

if (!serverHasUID) then {
    // play sound
};

This will make sure that the server only sends the network message to the client requesting it, instead of all clients simultaneously. Dont forget to add this in your publicvariable.txt;

!="serverCheckUID" !="serverHasUID"
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...