Jump to content
gc8

Player inventory recover

Recommended Posts

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

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

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

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.

  • Like 3

Share this post


Link to post
Share on other sites

@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
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

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 by Lucullus
Example attached
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
34 minutes ago, gc8 said:

to save the inventory

 

Maybe with a killed eventhandler , or even hit , instead of loops.

  • Like 1

Share this post


Link to post
Share on other sites

Or the handleDamage EH...

 

edit:

As I guess George he is already tinkering. 😉

  • Like 1

Share this post


Link to post
Share on other sites
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
	};
}];

 

  • Like 2
  • Thanks 2

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

×