Player persistence not working

  1. 4 years ago

    Hi all! I've had success in getting persistence to work for everything excep player position and gear - both reset to the default. I'm using the War Room, and have enabled persistence on the Data module and Player module. I have the following in my description file:
    -------------------------------------
    respawnOnStart = -1;
    briefing = 1;
    debriefing = 1;
    respawn = 3;
    respawnDelay = 5;
    RespawnDialog = 0;
    -------------------------------------

    In my init file, I have this at the top:

    -------------------------------------
    waituntil {(player getvariable ["alive_sys_player_playerloaded",false])};
    -------------------------------------

    Can anyone help me shed some light on this issue? I'm happy to post my mission, or any logs to assist with resolving!

  2. Edited 4 years ago by DrDetroit

    You need a init.sqf file and two more sqf files below, for your position and gear - create then place these files in your mission file:

    INIT.SQF:

    all compile preprocessFile "staticData.sqf";

    if(isServer) then {
    waitUntil {!isNil "ALiVE_STATIC_DATA_LOADED"};
    call compile (preprocessFileLineNumbers "staticData.sqf");
    };

    addMissionEventHandler ["entityKilled", {
    _victim = _this select 0;
    if (local _victim) then {
    [_victim, [missionNamespace, name _victim]] call BIS_fnc_saveInventory;
    _victim setVariable ["MGI_ammo1",_victim ammo (primaryWeapon _victim)];
    _victim setVariable ["MGI_ammo2",_victim ammo (handgunWeapon _victim)];
    _victim setVariable ["MGI_ammo3",_victim ammo (secondaryWeapon _victim)];
    _victim setVariable ["MGI_mags",magazinesAmmoFull _victim];
    _victim setVariable ["MGI_weapon",currentWeapon _victim];
    };
    }];

    addMissionEventHandler ["entityRespawned", {
    _unit = _this select 0;
    _corpse = _this select 1;
    if (local _unit) then {
    [_unit, [missionNamespace, name _unit]] call BIS_fnc_loadInventory;
    {_unit removeMagazine _x} forEach magazines _unit;
    _unit setAmmo [primaryWeapon _unit, 0];
    _unit setAmmo [handGunWeapon _unit, 0];
    _unit setAmmo [secondaryWeapon _unit, 0];
    {
    if (((_unit getVariable "MGI_mags") select _foreachindex select 3) <= 0) then {
    _unit addMagazine [_x select 0,_x select 1]
    }
    } forEach (_unit getVariable "MGI_mags");
    _unit setAmmo [primaryWeapon _unit,_unit getVariable "MGI_ammo1"];
    _unit setAmmo [handGunWeapon _unit,_unit getVariable "MGI_ammo2"];
    _unit setAmmo [secondaryWeapon _unit,_unit getVariable "MGI_ammo3"];
    _unit selectWeapon (_unit getVariable "MGI_weapon");
    removeAllWeapons _corpse;
    removeBackpackGlobal _corpse;
    removeVest _corpse;
    removeAllAssignedItems _corpse;
    removeAllItems _corpse;
    removeGoggles _corpse;
    removeHeadgear _corpse;
    {deleteVehicle _x} forEach nearestObjects [(getPosATL _corpse),["WeaponHolderSimulated","groundWeaponHolder"],5];
    };
    }];
    waituntil {(player getvariable ["alive_sys_player_playerloaded",false])};
    sleep 2;
    {
    if !(isPlayer _x) then {
    if !(_x getVariable ["Persistent_Teleport", false]) then {
    _x setPos (getPos player);
    _x setVariable ["Persistent_Teleport", true, true];
    sleep .5;
    };
    };
    } forEach units group player;

    Then the two other SQF below:

    onPlayerKilled.sqf:
    player setVariable["Saved_Loadout",getUnitLoadout player];

    onPlayerRespawn:
    removeAllWeapons player;
    removeGoggles player;
    removeHeadgear player;
    removeVest player;
    removeUniform player;
    removeAllAssignedItems player;
    clearAllItemsFromBackpack player;
    removeBackpack player;
    player setUnitLoadout(player getVariable["Saved_Loadout",[]]);

  3. Amazing, thank you! I'll try this today and report back. Where is this stuff documented? I thought I'd been thorough with the wiki!

  4. Edited 4 years ago by Somnolent

    Hi there. I did some testing on this, adding the code to the top of the init file, and creating the onPlayerKilled.sqf and onPlayerRespawn.sqf files with the code you gave. I then loaded the game, changed my loadout and moved to a new position. Then, I used the ALiVE player save option, and then server save and exit.

    When I rejoined however, I was in the same position, with the prior loadout. Is there something I can provide to help figure out what to do next? Many thanks!

  5. Edited 4 years ago by DrDetroit

    So you loaded in the new location, but spawned with original loadout? I think I have the code set to load with initial setup when you start the mission, and save new position, when you start the game.

    So when I load into the game, I'm at my new location, but I load in with equipment that I started the campaign with.

    I got these code from the wiki and poached some code from other missions. Check that out if you want to save loadout to your current loadout at Alive save. It's kinda hard to locate stuff in the wiki but it's there.

    Good luck~
    DrDetroit

  6. Hi there Dr.! Sorry for any ambiguity - when I load in, the position is the default starting position, and not the position I moved to - It seems that my player location is not saving, and my gear is also resetting to the default (although from what you said, the gear will not revert anyhow). So is there something that I need to add to make my player load in at the last saved location instead of resetting? :)

  7. Edited 4 years ago by DrDetroit

    Don't forget the setting in Alive that spawns player at last position. I think it's in Alive Data module...can't recall at the moment exactly which module. There is a checkbox.

    I'll check my persistence settings when I get home later today. Works flawlessly for me.

    BTW: if you find the checkbox in the module, check that, keep the three files loaded in your mission file, and get rid of the lines you put in the description box. I'm pretty sure that's my setup for persistence, and it works great. Again, if no joy, I'll check my settings later today.

  8. Hi there, I think that you're referring to the ALiVE player options - I've included my settings here --image-

    So I think that option has been enabled from the start. I appreciate you checking! And to confirm, you're suggesting to keep the new files, and just remove the text you provided from the description file only?

    Thanks again!

  9. Yup, that's the one, with the pulldown for 'Store Position'. Hmmm...not sure why it's not working for you.

    I can send you one of my ALive missions and you can take it apart to see the files I have and test the persistence. I noticed that I have some settings in my description.ext that triggers the sqf files.

    Anyhow let me know I'll shoot a campaign over. One that me and a few buddies have been 'testing' for the past 30-days or so has no issues with persistence, and I think about 4 in-game campaign days where we save progress where ever we happen to be on the map.

  10. Hi Dr, thanks again for your help, means a lot. I'd love to check out a mission - I can just replicate and test until it works!

    Then I can use those settings as a template for the future missions once it's worked out :)

  11. last year
    Deleted last year by CDEEKS
  12. I found the reason for this bug. ill write up a guide on steam page as many many days of tinkering i find the perfect way to force load everything as if the game never stopped.

 

or Sign Up to reply!