gc8 970 Posted March 2, 2019 Hi I'm trying to save player inventory on death and give it back on respawn but for some reason my code doesn't work all the time. Sometimes player respawn with just a pistol and I don't know why. Here's my code: In onPlayerKilled.sqf: [player,[missionNamespace,(name player)]] call bis_fnc_saveInventory; in onPlayerRespawn.sqf: [player,[missionNamespace,(name player)]] call bis_fnc_loadInventory; But sometimes it works and sometimes not. Any ideas why? thx! Share this post Link to post Share on other sites
gc8 970 Posted March 2, 2019 Found out the reason. in onPlayerKilled.sqf the primary weapon is sometimes gone. Tested with "primaryweapon player" it returns empty string sometimes. don't know why though, has the weapon fallen to ground? Share this post Link to post Share on other sites
beno_83au 1362 Posted March 2, 2019 I believe that on being killed a groundWeaponHolder (?) is created and the weapon "falls" into it, so to speak. Share this post Link to post Share on other sites
gc8 970 Posted March 2, 2019 6 minutes ago, beno_83au said: I believe that on being killed a groundWeaponHolder (?) is created and the weapon "falls" into it, so to speak Yeah, neeed to get the inv somehow before that. Looking for best solution... Share this post Link to post Share on other sites
Larrow 2803 Posted March 2, 2019 Use a Take and InventoryClosed EH with a possible SEH for arsenalClosed( if your using an arsenal )? Those are the main times a units inventory is going to change. 3 Share this post Link to post Share on other sites
gc8 970 Posted March 2, 2019 @Larrow Good idea. Or maybe I use loop every 5 seconds to save the inventory because if player empties some clips those are considered lost. Haven't yet decided what's the best way Share this post Link to post Share on other sites
Lucullus 71 Posted March 2, 2019 Since I use getUnitLoadout and setUnitloadout, this error no longer occurs. Share this post Link to post Share on other sites
gc8 970 Posted March 2, 2019 4 minutes ago, Lucullus said: Since I use getUnitLoadout and setUnitloadout, this error no longer occurs. It's not the command that is failing (at least AFAIK) but the timing of the save command Share this post Link to post Share on other sites
Lucullus 71 Posted March 2, 2019 (edited) Maybe, but you can try the difference. From my ArmaArcade mission onPlayerKilled.sqf: params ["_oldUnit","_killer"]; _load = getUnitLoadout _oldUnit; // a few more lines... waitUntil { sleep 0.1; !isNull player }; player setUnitLoadout [_load,false]; Edited March 2, 2019 by Lucullus Example attached 1 1 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4206 Posted March 2, 2019 34 minutes ago, gc8 said: to save the inventory Maybe with a killed eventhandler , or even hit , instead of loops. 1 Share this post Link to post Share on other sites
Lucullus 71 Posted March 2, 2019 Or the handleDamage EH... edit: As I guess George he is already tinkering. 😉 1 Share this post Link to post Share on other sites
Larrow 2803 Posted March 2, 2019 58 minutes ago, gc8 said: if player empties some clips those are considered lost How about something like.... findDisplay 46 displayAddEventHandler [ "KeyDown", { params[ "_display", "_keyCode", "_shft", "_ctr", "_alt" ]; if ( inputAction "reloadMagazine" > 0 && { currentMagazineDetail player splitString "(/)" select 1 == "0" } ) then { //Save inventory }; }]; 2 2 Share this post Link to post Share on other sites