Jump to content
Sign in to follow this  
Wraith_last

Help with a Loadout script I have

Recommended Posts

Hello, I have the following script from an old post and it works about 50%.
It is for saving loadout and position when logging. The Problem is it saves pos data but the loadouts are reset every time I log back in. Meaning I could log out in an area where enemies spawn with high powered rifles and I am running around with the starter pistol.
He she is:


TAG_fnc_loadClientData = {
    _this params ["_loadout", "_positionASL", "_dir"];
    player setUnitLoadout _loadout;
    player setDir _dir;
    player setPosASL _positionASL;
};

if(isServer) then {
    addMissionEventHandler [
        "HandleDisconnect",
        {
            params ["_body", "_id", "_uid", "_name"];
            
            if(!isNull _body) then {            
                //Init storage var
                if(isNil "TAG_disconnectedLoadouts") then {
                    TAG_disconnectedLoadouts = [];
                };
                
                //Get data
                private _loadout = getUnitLoadout _body;
                private _position = getPos _body;
                private _direction = getDir _body;
                    
                //Find in storage
                private _uidIndex = TAG_disconnectedLoadouts find _uid;
                if(_uidIndex > -1) then {
                    //Found -> update
                    private _loadoutIndex = _uidIndex + 1;
                    TAG_disconnectedLoadouts set [_loadoutIndex, [_loadout, _position, _direction]];
                } else {
                    //Not found -> Add new
                    TAG_disconnectedLoadouts pushBack _uid;
                    TAG_disconnectedLoadouts pushBack [_loadout, _position, _direction];
                };
            };
            false
        }
    ];

    addMissionEventHandler [
        "PlayerConnected",
        {
            params ["_id", "_uid", "_name", "_jip", "_owner"];
            if(_jip) then {
                private _clientData = missionNamespace getVariable ["TAG_disconnectedLoadouts", []];
                private _uidIndex = _clientData find _uid;
                if(_uidIndex > -1) then {
                    private _loadoutIndex = _uidIndex + 1;
                    (_clientData select _loadoutIndex) remoteExec ["TAG_fnc_loadClientData", _owner];
                };
            };
        }
    ];
};

 

Any help would be gladly recived.

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
Sign in to follow this  

×