Jump to content
Northup

Remote Exec Play music?

Recommended Posts

The following code works, except for the music being played. No errors, just silence. What music plays is contingent upon if a player's side matches _winingside. I've tried not remote execing, same thing.

// Display the ending message without background
{
    private _playerSide = side _x;
     private _playerID = owner _x; // Get the player's ID
    if (_playerSide == _winningSide) then {
        titleText [_endingWinMessage, "PLAIN", -1, true, true];
       // playMusic ["LeadTrack01_F_Bootcamp", 132];
        ["LeadTrack01_F_Bootcamp", 132] remoteExec ["playMusic"];
    } else {
        titleText [_endingLoseMessage, "PLAIN", -1, true, true];
        //playMusic "BackgroundTrack03_F_EPC";
        
         ["BackgroundTrack03_F_EPC"] remoteExec ["playMusic"];
    };
} forEach allPlayers;

Not sure where I am going wrong. 

Share this post


Link to post
Share on other sites

The playMusic function seems correct to me and should work.

I would check if the code is reaching the respective position, for example, by using a hint.

 

One thing I noticed:

An issue is that using remoteExec causes the music to play for all players instead of just the player currently being processed by the forEach loop.

Without using remoteExec, the music will only play on the server, meaning the intended player still won't hear the music.

 

I would try to execute the entire code locally for each player and then call the playMusic function locally there.

 

I can't test the following code, but it should roughly work like this:

On the server (e.g., in initServer.sqf):

JFR_winningSide = _winningSide;
JFR_endingLoseMessage = _endingLoseMessage;
JFR_endingWinMessage = _endingWinMessage;
publicVariable "JFR_winningSide";
publicVariable "JFR_endingLoseMessage";
publicVariable "JFR_endingWinMessage";
"localScript.sqf" remoteExec ["execVM",0]; //remoteExec to every Player localy

 

In another script named "localScript.sqf":

private _playerSide = side player;
if (_playerSide == JFR_winningSide) then {
	titleText [JFR_endingWinMessage, "PLAIN", -1, true, true];
	playMusic ["LeadTrack01_F_Bootcamp", 132];
} else {
	titleText [JFR_endingLoseMessage, "PLAIN", -1, true, true];
	playMusic "BackgroundTrack03_F_EPC";
};

 

Alternatively, the variables _winningSide etc. could also be passed to the script instead of broadcasting them with publicVariable.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Joshua9797 said:

The playMusic function seems correct to me and should work.

I would check if the code is reaching the respective position, for example, by using a hint.

 

One thing I noticed:

An issue is that using remoteExec causes the music to play for all players instead of just the player currently being processed by the forEach loop.

Without using remoteExec, the music will only play on the server, meaning the intended player still won't hear the music.

 

I would try to execute the entire code locally for each player and then call the playMusic function locally there.

 

I can't test the following code, but it should roughly work like this:

On the server (e.g., in initServer.sqf):


JFR_winningSide = _winningSide;
JFR_endingLoseMessage = _endingLoseMessage;
JFR_endingWinMessage = _endingWinMessage;
publicVariable "JFR_winningSide";
publicVariable "JFR_endingLoseMessage";
publicVariable "JFR_endingWinMessage";
"localScript.sqf" remoteExec ["execVM",0]; //remoteExec to every Player localy

 

In another script named "localScript.sqf":


private _playerSide = side player;
if (_playerSide == JFR_winningSide) then {
	titleText [JFR_endingWinMessage, "PLAIN", -1, true, true];
	playMusic ["LeadTrack01_F_Bootcamp", 132];
} else {
	titleText [JFR_endingLoseMessage, "PLAIN", -1, true, true];
	playMusic "BackgroundTrack03_F_EPC";
};

Alternatively, the variables _winningSide etc. could also be passed to the script instead of broadcasting them with publicVariable.

Tried that. Oddly enough, same result.  I'm at a total loss.

Share this post


Link to post
Share on other sites

Does playMusic work when you execute it in the debug console?

Stupid question, but did you also set the music volume?

And where exactly are you calling the code?

Share this post


Link to post
Share on other sites

1. Assuming you mean playMusic "RadioAmbient1"; and hitting local exec,YES. playMusic ["LeadTrack01_F_Bootcamp", 132] also works.
2. LOL. I had someone in the discord ask me the same thing. Yes, I did. I have intromusic that plays on OnplayerRespawn that works fine.
3.I have 2 functions:
 

   //NUP\NUP_flagCapture\functions\NUP_fnc_updateScores.sqf

    {
        private _side = _x select 1;
        switch (_side) do 
        {
            case west: 
            {     
                NUP_points_BLUFOR = NUP_points_BLUFOR + 1; 
            };
            case east: 
            { 
                NUP_points_OPFOR = NUP_points_OPFOR + 1; 
            };
            case independent: 
            { 
                NUP_points_INDFOR = NUP_points_INDFOR + 1; 
            };
            case civilian: 
            { 
            NUP_points_CIV = NUP_points_CIV + 1; 
            };
        };
    } forEach (missionNamespace getVariable ["NUP_flagArray", []]);

    diag_log format ["Blu score: %1, Opf score: %2, Ind score: %3, Civ score: %4", NUP_points_BLUFOR, NUP_points_OPFOR, NUP_points_INDFOR, NUP_points_CIV];

    private _winningSide = []; // Array to store winning sides
    private _maxScore = NUP_points_maxScore;
    diag_log format ["_maxscore: %1", _maxScore];

    // Determine winning sides
    if (NUP_points_BLUFOR >= _maxScore) then { _winningSide pushBack west; };
    if (NUP_points_OPFOR >= _maxScore) then { _winningSide pushBack east; };
    if (NUP_points_INDFOR >= _maxScore) then { _winningSide pushBack independent; };
    if (NUP_points_CIV >= _maxScore) then { _winningSide pushBack civilian; };

    // Check if any side has reached the maximum score and trigger end mission if so
    if (count _winningSide == 1) then 
    {
        [_winningSide] call NUP_fnc_endMission;
        "endMusic.sqf" remoteExec ["execVM",0];
    };


 

// NUP_fnc_endMission:
params ["_winningSide"];

WinningSide = _winningSide select 0;


private _winnerOutcome = switch (WinningSide) do {
    case west: { "BLUFOR WINS!" };
    case east: { "OPFOR WINS!" };
    case independent: { "INDEPENDENT WINS!" };
    case civilian: { "CIVILIANS WIN!" };
};

WinMessage = format ["MISSION ACCOMPLISHED! %1", _winnerOutcome];
LoseMessage = format ["MISSION FAILED! %1 ", _winnerOutcome];

// Get the position of the NUP_endMissionCamera object
private _cameraPos = getPos NUP_endMissionCamera;

// Calculate starting and ending positions for the camera
private _startPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 10 // 10 meters above
];

private _endPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 50 // 50 meters above (40 meters up during 30 seconds)
];

// Create the camera
private _camera = "camera" camCreate _startPos;
_camera cameraEffect ["internal", "back"];
_camera camSetTarget NUP_endMissionCamera;
_camera camSetFOV 1;
_camera camCommit 0;

// Start the cinematic borders
[0, 0.5, false, true] call BIS_fnc_cinemaBorder;

// Move the camera over 30 seconds
_camera camSetPos _endPos;
_camera camCommit 30;

publicVariable "WinningSide";
publicVariable "LoseMessage";
publicVariable "WinMessage";

// Wait until the camera has finished it's trajectory
waitUntil { camCommitted _camera };

// Terminate the camera effect and destroy the camera
_camera cameraEffect ["terminate", "back"];
camDestroy _camera;

// Force all players back to the lobby after the outro
["END1", false] call BIS_fnc_endMission;

and in initServer:

if !(isServer) exitWith {};

NUP_flagArray = [];

NUP_points_BLUFOR = 0;
NUP_points_OPFOR = 0;
NUP_points_INDFOR = 0;
NUP_points_CIV = 0;

NUP_points_maxScore = 5;
NUP_scoring_interval = 5;

NUP_deadlock = 0;

[] spawn {
    while {true} do {
        [] call NUP_fnc_updateScores;
        sleep NUP_scoring_interval;
    };
};

  Both are registered.

 class NUP_flagCapture {
        tag = "NUP";
        class flagCapture {
            file = "NUP\NUP_flagCapture\functions";
            
            class initSafezone {};
            class initFlag {};
            class playerMarkers {};
            class captureFlag {};
            class addFlagHoldAction {};
            class getFlagSupplies {};
            class updateFlagSupplyActions {};
            class addMedicalHoldAction {};
            class addEquipmentHoldAction {};
            class addRespawnPosition {};
            class addVehicleServices {};
            class cinematicBorder {};
            class updateScores {};
            class endMission {};    
            };
    };


 

  • Like 1

Share this post


Link to post
Share on other sites

Does the exclamation mark work outside in "if !(isServer) exitWith {};" in initServer?

  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, Joshua9797 said:

Can you please share the code of endMusic.sqf?

private _playerSide = side player;
if (_playerSide == WinningSide) then {
    titleText [WinMessage, "PLAIN", -1, true, true];
    playMusic ["LeadTrack01_F_Bootcamp", 132];
} else {
    titleText [LoseMessage, "PLAIN", -1, true, true];
    playMusic "BackgroundTrack03_F_EPC";
};

 

8 minutes ago, Joshua9797 said:

Does the exclamation mark work outside in "if !(isServer) exitWith {};" in initServer?

Seems to. I've changed it. Will report back if anything changes.

Share this post


Link to post
Share on other sites

When I start the mission as Blufor and then enter "NUP_points_BLUFOR = 5" in the console, I get the outro and I can also hear the music.

Although it's a bit quiet, it's still there.

 

Then it can only be due to a mod or a setting, I suppose.

 

EDIT: Do you have this problem on a server or also in single player?

Share this post


Link to post
Share on other sites

I haven't bothered testing singleplayer. Perhaps it's how I am testing? I know there's a way to test as if it were dedicated server, however for the time being I've been testing in a local server environment. 

Mission is intended to be ran on dedi, but can run local host. Just PVP, no AI.

Only mods are 3den Enhanced, CompoT_dev and 3DEN Create as Simple Object. None create any dependencies for players.

Edit: I hadn't tried testing it that way, only by executing the gameplay loop. 

When doing it with console, not only do I NOT hear music, but the environmental sounds (rain, etc) stop, and this cascades into the next loading of the mission: i.e., no music OR environmental effects. 
Very weird!

Share this post


Link to post
Share on other sites

OK, I have now managed to get it running on a server. I made the following changes:

In the initServer.sqf, I defined WinMessage = "";. Additionally, I changed the loop from true to while {count(WinMessage) <= 0;} do {.

This way, the loop ends as soon as the text in WinMessage is longer than 0.

I did this because otherwise, the outro would start over again with each pass of the loop.

if (!isServer) exitWith {};

NUP_flagArray = [];

NUP_points_BLUFOR = 0;
NUP_points_OPFOR = 0;
NUP_points_INDFOR = 0;
NUP_points_CIV = 0;

NUP_points_maxScore = 5;
NUP_scoring_interval = 5;

NUP_deadlock = 0;
WinMessage = "";

[] spawn {
    while {count(WinMessage) <= 0;} do {
        [] call NUP_fnc_updateScores;
        sleep NUP_scoring_interval;
    };
};

 

Secondly, I adjusted fn_endMission.sqf. Here, I commented out everything from the point where everything should be executed locally and added the call to the new script localScript.sqf using remoteExec:
(The music and everything with the camera needs to be executed locally, otherwise only the server will be able to enjoy the nice outro.)

// NUP_fnc_endMission:
params ["_winningSide"];

Winner = _winningSide select 0;
publicVariable "Winner";

WinnerOutcome = switch (Winner) do {
    case west: { "BLUFOR WINS!" };
    case east: { "OPFOR WINS!" };
    case independent: { "INDEPENDENT WINS!" };
    case civilian: { "CIVILIANS WIN!" };
};
publicVariable "WinnerOutcome";

WinMessage = format ["MISSION ACCOMPLISHED! %1", WinnerOutcome];
LoseMessage = format ["MISSION FAILED! %1 ", WinnerOutcome];

publicVariable "WinMessage";
publicVariable "LoseMessage";

"localScript.sqf" remoteExec ["execVM",0]; //remoteExec to every Player localy

/*{
    private _playerSide = side _x;
     private _playerID = owner _x; // Get the player's ID
    if (_playerSide == Winner) then {
        titleText [WinMessage, "PLAIN", -1, true, true];
        ["LeadTrack01_F_Bootcamp", 132] call BIS_fnc_playMusic;
    } else {
        titleText [LoseMessage, "PLAIN", -1, true, true];
        playMusic "BackgroundTrack03_F_EPC";
    };
} forEach allPlayers;


// Get the position of the NUP_endMissionCamera object
private _cameraPos = getPos NUP_endMissionCamera;

// Calculate starting and ending positions for the camera
private _startPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 10 // 10 meters above
];

private _endPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 50 // 50 meters above (40 meters up during 30 seconds)
];

// Create the camera
private _camera = "camera" camCreate _startPos;
_camera cameraEffect ["internal", "back"];
_camera camSetTarget NUP_endMissionCamera;
_camera camSetFOV 0.5;
_camera camCommit 0;

// Start the cinematic borders
_start = diag_tickTime;
[0, 0.5, false, true] call BIS_fnc_cinemaBorder;

// Move the camera over 30 seconds
_camera camSetPos _endPos;
_camera camCommit 30;

// Wait until the camera has finished it's trajectory
waitUntil { camCommitted _camera };


// Terminate the camera effect and destroy the camera
_camera cameraEffect ["terminate", "back"];
camDestroy _camera;

// Force all players back to the lobby after the outro
["END1", true] call BIS_fnc_endMission;*/

 

 

Lastly, I created a script in the main folder named localScript.sqf:

 

private _playerSide = side player;
if (_playerSide == Winner) then {
	titleText [WinMessage, "PLAIN", -1, true, true];
	playMusic ["LeadTrack01_F_Bootcamp", 132];
} else {
	titleText [LoseMessage, "PLAIN", -1, true, true];
	playMusic "BackgroundTrack03_F_EPC";
};


// Get the position of the NUP_endMissionCamera object
private _cameraPos = getPos NUP_endMissionCamera;

// Calculate starting and ending positions for the camera
private _startPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 10 // 10 meters above
];

private _endPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 50 // 50 meters above (40 meters up during 30 seconds)
];

// Create the camera
private _camera = "camera" camCreate _startPos;
_camera cameraEffect ["internal", "back"];
_camera camSetTarget NUP_endMissionCamera;
_camera camSetFOV 0.5;
_camera camCommit 0;

// Start the cinematic borders
_start = diag_tickTime;
//[0, 0.5, false, true] call BIS_fnc_cinemaBorder;

// Move the camera over 30 seconds
_camera camSetPos _endPos;
_camera camCommit 30;

// Wait until the camera has finished it's trajectory
waitUntil { camCommitted _camera };


// Terminate the camera effect and destroy the camera
_camera cameraEffect ["terminate", "back"];
camDestroy _camera;

// Force all players back to the lobby after the outro
["END1", true] call BIS_fnc_endMission;

 

Please try and see if it works with these changes.

  • Like 2

Share this post


Link to post
Share on other sites

To trigger the end of the mission, entering the following into the console on the server was enough:
 

["", 132] call BIS_fnc_playMusic;
NUP_points_BLUFOR = 5;
publicVariable "NUP_points_BLUFOR";

 

  • Like 1

Share this post


Link to post
Share on other sites

 

Works! Made some small changes, but it finally works. 
THANKS!

 

BIS_endText =
{
    private["_blocks","_block","_blockCount","_blockNr","_blockArray","_blockText","_blockTextF","_blockTextF_","_blockFormat","_formats","_inputData","_processedTextF","_char","_cursorBlinks"];
    _blockCount = count _this;
    _invisCursor = "<t color ='#00000000' shadow = '0'>_</t>";

    // Get screen center position using safezone
    private _safeZoneX = (safezoneX + safezoneW / 2);
    private _safeZoneY = (safezoneY + safezoneH / 2);

    // Process the input data
    _blocks = [];
    _formats = [];
    {
        _inputData = _x;
        _block     = [_inputData, 0, "", [""]] call BIS_fnc_param;
        _format = [_inputData, 1, "<t align = 'center' shadow='1' size='2.0'>%1</t><br/>", [""]] call BIS_fnc_param;

        // Convert strings into array of chars
        _blockArray = toArray _block;
        {
            _blockArray set [_forEachIndex, toString [_x]]
        } forEach _blockArray;

        _blocks  = _blocks + [_blockArray];
        _formats = _formats + [_format];
    } forEach _this;

    // Do the printing
    _processedTextF  = "";

    {
        _blockArray  = _x;
        _blockNr = _forEachIndex;
        _blockFormat = _formats select _blockNr;
        _blockText   = "";
        _blockTextF  = "";
        _blockTextF_ = "";

        {
            _char = _x;
            _blockText = _blockText + _char;
            _blockTextF  = format[_blockFormat, _blockText + _invisCursor];
            _blockTextF_ = format[_blockFormat, _blockText + "_"];

            // Print the output at the center of the screen using safezone
            [(_processedTextF + _blockTextF_), 0, _safeZoneY, 35, 0, 0, 90] spawn BIS_fnc_dynamicText;
            playSoundUI ["a3\missions_f\data\sounds\click.wss", 0.25];
            sleep 0.08;
            [(_processedTextF + _blockTextF), 0, _safeZoneY, 35, 0, 0, 90] spawn BIS_fnc_dynamicText;
            sleep 0.02;
        } forEach _blockArray;

        if (_blockNr + 1 < _blockCount) then
        {
            _cursorBlinks = 5;
        }
        else
        {
            _cursorBlinks = 15;
        };

        for "_i" from 1 to _cursorBlinks do
        {
            [_processedTextF + _blockTextF_, 0, _safeZoneY, 35, 0, 0, 90] spawn BIS_fnc_dynamicText;
            sleep 0.08;
            [_processedTextF + _blockTextF, 0, _safeZoneY, 35, 0, 0, 90] spawn BIS_fnc_dynamicText;
            sleep 0.02;
        };

        // Store finished block
        _processedTextF  = _processedTextF + _blockTextF;
        // Do not clear the screen, to keep the text visible
        //["", _safeZoneX, _safeZoneY, 35, 0, 0, 90] spawn BIS_fnc_dynamicText;
    } forEach _blocks;
};

// Example usage
[
    ["MISSION COMPLETE","<t align='center' shadow='1' size='2.0'>%1</t><br/>"]
] spawn BIS_endText;

private _playerSide = side player;
if (_playerSide == Winner) then {
    // Display win message with typewriter effect
    [
        [WinMessage, "<t align='center' shadow='1' size='1.0'>%1</t><br/>"]
    ] spawn BIS_endText;

    playMusic ["LeadTrack01_F_Bootcamp", 132];
    0 fadeMusic 2;
} else {
    // Display lose message with typewriter effect
    [
        [LoseMessage, "<t align='center' shadow='1' size='1.0'>%1</t><br/>"]
    ] spawn BIS_endText;

    playMusic "BackgroundTrack03_F_EPC";
    0 fadeMusic 2;
};
_start = diag_tickTime;
[0, 1, true, false] call NUP_fnc_cinematicBorder;

// Get the position of the NUP_endMissionCamera object
private _cameraPos = getPos NUP_endMissionCamera;

// Calculate starting and ending positions for the camera
private _startPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 10 // 10 meters above
];

private _endPos = [
    (_cameraPos select 0), // Same X position
    (_cameraPos select 1), // Same Y position
    (_cameraPos select 2) + 50 // 50 meters above (40 meters up during 30 seconds)
];

// Create the camera
private _camera = "camera" camCreate _startPos;
_camera cameraEffect ["internal", "back"];
_camera camSetTarget NUP_endMissionCamera;
_camera camSetFOV 0.5;
_camera camCommit 0;

// Move the camera over 30 seconds
_camera camSetPos _endPos;
_camera camCommit 30;

waitUntil { diag_tickTime - _start >= 25 };
 5 fadeMusic 0;
  
// Wait until the camera has finished its trajectory
waitUntil { camCommitted _camera };

// Terminate the camera effect and destroy the camera
//_camera cameraEffect ["terminate", "back"];
//camDestroy _camera;

// Force all players back to the lobby after the outro
endMission "end";


Edit: A separate script appears to not be necessary.

By storing the above in a local variable in the actual endMission function, (_NUP_endSequence), I can then spawn that via remoteExec. So far, seems to work!

 

"_NUP_endSequence" remoteExec ["spawn", 0]; // remoteExec to every player locally

 

  • Like 1
  • Thanks 1

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

×