Jump to content

Noel Collins

Member
  • Content Count

    9
  • Joined

  • Last visited

  • Medals

Posts posted by Noel Collins


  1. 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! 


  2. On 11/7/2021 at 7:24 PM, mrcurry said:

     

     

    So I just test ran @pierremgi's code and had a hiccup.
    When I copied from his forum post to the init.sqf a "ghost character" showed up which would prevent the script from working. This is why running test-benches with startup parameter -showScriptErrors is important.

    p.png?fv_content=true&size_mode=5

    Pierre could be messing with us... :suspicious: 

    ...but more likely its an artifact from the forum formatting of the code.

     

    So check if you are also getting this in your init-file.

    To be safe retype "profileNamespace getVariable".

     

    After I busted the ghost the code ran fine on my test-bench.

     

    If it still doesn't work here's a couple of things you could do:

     1. Check your CfgRemoteExec so that "spawn" is allowed.

     2. Check the .rpt if some other error is being printed when you disconnect / connect.

     3. If running with mods, give it a try without them to see if they are interfering somehow.

    Thanks, trying that now but no avail.

     

    the image you posted has not come through, so i cannot see what you are trying to show.

     

    as its sits now in my init.sqf:

     

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

    if (isServer) then {
      profileNamespace setVariable ["TAG_disconnectedLoadouts",nil];  // only for resetting the variable on server. Important if not previously a hashmap !

      addMissionEventHandler ["HandleDisconnect",
        {
          params ["_body", "_id", "_uid", "_name"];
          if(!isNull _body) then {
            private _loadout = getUnitLoadout _body;
            private _position = getPos _body;
            private _direction = getDir _body;
            if(isNil {profileNamespace getVariable "TAG_disconnectedLoadouts"}) then {
            profileNamespace setVariable ["TAG_disconnectedLoadouts",createHashMapFromArray [[_uid,[_loadout,_position,_direction]]]];
            } else {
              (profileNamespace getVariable "TAG_disconnectedLoadouts") set [_uid,[_loadout,_position,_direction]];
            };
    diag_log [_uid,(profileNamespace getVariable "TAG_disconnectedLoadouts")];
          };
          false
        }
      ];

      addMissionEventHandler ["PlayerConnected",
        {
          params ["_id", "_uid", "_name", "_jip", "_owner"];
          if(_jip) then {
            private _clientData = profileNamespace getVariable ["TAG_disconnectedLoadouts", []];
            if (_clientData isEqualTo []) exitWith {};
            private _value = _clientData get _uid;
    diag_log ["<<<<<after connect>>>>",_value,_this];
          [_value,TAG_fnc_loadClientData] remoteExec ["spawn", _owner];
          };
        }
      ];
    };


  3. Original Attempt was with code in init.sqf exactly as above on hosted server, with nothing else done.

    This attempt the same code was as below, only change marked in red.:

    i dont see a namespace in the handle disconnect EH?

     

    thanks

     

     

     

    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 = profileNamespace getVariable ["TAG_disconnectedLoadouts", []];

                                   private _uidIndex = _clientData find _uid;

                                   if(_uidIndex > -1) then {

                                          private _loadoutIndex = _uidIndex + 1;

                                          (_clientData select _loadoutIndex) remoteExec ["TAG_fnc_loadClientData", _owner];

                                   };

                           };

                   }

            ];

    };


  4. I tried to use the script above over the weekend:

    - blank mission with one playable character, an arsenal and a vehicle.

    - The code above copied into in it.sqf.

    - on joining I walked about 15 metres and to the right, turned 180 from starting orientation, and dripped numerous weapons and items from inventory.

    - I then disconnected and logged back on. 

     

    I spawned back in original position, with original gear.

     

    Can anyone confirm this script still works, and if there are any other server side settings I need to make it work?

     

    Thanks!

×