Jump to content
MrDj200

Save Loadout and Position on disconnect

Recommended Posts

@pierremgi 

In the test showed in the video (dedi-server with only client disconnecting/reconnecting) your code should still work with even with the nil-ing enabled. It does work on my test-bench.

 

Yes, using the profileNamespace version is a bit pointless if your going to be resetting every time the mission restarts but right now it doesn't even run in the basic use case.

 

@Noel Collins 

Since we know the code works by itself we need to go back to basics. Upload your test mission so we can take a closer look.

 

Correct link added to previous post.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

wait one, i have changed the mission while exploring other options, let me rebuild

 

And yes, im looking to save position and loadout from players to their own profilesnamespace, so that we can start from the same position and with the same gear thefollowing week.

 

https://drive.google.com/drive/folders/1i9-ks-ml41RtxMi3STlhRU_d3sdxY3oW?usp=sharing

mission folder and the multiplayer file

 

thanks for your patience gents, im really stuggling to get my head around this one! 

Share this post


Link to post
Share on other sites
On 11/16/2021 at 11:57 AM, Noel Collins said:

im looking to save position and loadout from players to their own profilesnamespace, so that we can start from the same position and with the same gear thefollowing week.

 

Well that's a different beast entirely! 🙂 

The original code was designed to handle involuntary disconnects of clients a.k.a. crashes, powercuts etc by saving the units loadout, position and direction on the server.

 

I downloaded the test mission and ran through the issues I found.

Here's some of them in no particular order.

  • When respawn isn't enabled and testing with a single slot this script won't work, the server will have to be restarted every time which means the PlayerConnected event won't load the data since its not a JIP-connection. This is by design.
  • When respawn is enabled it won't fire on the first loading of a mission. Successive connections will load properly though. This is also by design.
  • Sometimes when the player connects the position won't be applied properly. Easily fixed by implementing a quick sleep in TAG_fnc_loadClientData.

Something tells me that we're getting disparate results because we're asking it to do what it never was intended to do.

For what you want to do; Instead of hunting down and squashing every little bug one at a time I would ditch this code and start from scratch. 

That work doesn't belong in this thread though, I'll send you a PM to sort something out.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @mrcurry

 

i did exactly that over the weekend, went back to first principles and nuttted it out. i have something that works now, but it not fully teste.

 

i will put it up here when im 100% confident in it 🙂

 

thanks!

Share this post


Link to post
Share on other sites
On 10/24/2021 at 3:09 PM, pierremgi said:

 

Please tell me, I inserted your script into init.skf. But I have not one player slot in the mission, but several. and if the player remains in his slot, then the script works, and if he takes another slot, it does not work, and he appears in the default place. How or where to fix it?

Share this post


Link to post
Share on other sites
On 10/14/2022 at 3:35 AM, topden said:

if the player remains in his slot, then the script works, and if he takes another slot, it does not work, and he appears in the default place. How or where to fix it?

This is because PlayerConnected event, where player's loadout, position and direction are restored, occurs when a player connects to a server, not joins a mission. As a workaround, reconnect to the server. Or try this patch:

if (isServer) then {
    TAG_fnc_loadClientData = compileFinal ((str {
        params [
            ["_client", objNull, [objNull]]
        ];

        if (isNull _client) exitWith { };

        private _clientData = profileNamespace getVariable ["TAG_disconnectedLoadouts", createHashMap];

        private _clientDatum = _clientData getOrDefault [getPlayerUID _client, []];

        if (_clientDatum isEqualTo []) exitWith { };

        _clientDatum remoteExecCall ["TAG_fnc_applyClientData", _client];
    }) trim ["{}", 0]);
};
if (!isDedicated) then {
    TAG_fnc_applyClientData = compileFinal ((str {
        params [
            ["_loadout", [], [[]]],
            ["_position", [], [[]], [2, 3]],
            ["_direction", 0, [0]]
        ];

        if ((_loadout isEqualTo []) or { _position isEqualTo [] }) exitWith { false };

        player setUnitLoadout _loadout;
        player setDir _direction;
        player setPos _position;

        true
    }) trim ["{}", 0]);

    waitUntil { !(isNull player) };

    [player] remoteExecCall ["TAG_fnc_loadClientData", 2];
};

 

  • Like 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

×