Jump to content
Sign in to follow this  
dachs

Simple respawn with old gear, optimization help?

Recommended Posts

I'm slowly learning this scripting stuff, and I'm beginning to wonder about best practises.

 

As it is I'm trying to make it so Player will respawn with the gear he had when killed.

I got it working by using onPlayerRespawn.sqf and onPlayerKilled.sqf, which works very well, right until the mission gets busy with 40-50 AI that is!

Then, often times the gear does not get saved properly, and Player will respawn with only basic loadout i.e. a pistol.

 

Instead I now use the code below, in initPlayerLocal.sqf, to save Players inventory every 10 seconds.

What I'm wondering is, is there a more efficient way of running that loop?

 

Spawn, eventhandler, precompile maybe? I've been reading about it in a number of threads, but can't quite grasp the differences..?

      while {alive player} do
		{
			[player, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;
			sleep 10;
		};

And the stuff gets loaded again using this in onPlayerRespawn.sqf

[player, [missionNamespace, "inventory_var"]] call BIS_fnc_loadInventory;

Share this post


Link to post
Share on other sites

I did a video that quickly shows you how to easily implement a system that saves/loads the player's loadout upon death/respawn:

​Hope it helps!

  • Like 1

Share this post


Link to post
Share on other sites

onPlayerRespawn.sqf have this feature implemented automatically:  [<newUnit>, <oldUnit>, <respawn>, <respawnDelay>]

 

So you would only need to use that.

_newPlayer = _this select 0; //respawned player, setUnitLoadout
_oldPlayer = _this select 1; //killed player, getUnitLoadout

You can use

https://community.bistudio.com/wiki/getUnitLoadout

to save the loadout to a variable

and

https://community.bistudio.com/wiki/setUnitLoadout

to apply it to the new unit

  • Like 1

Share this post


Link to post
Share on other sites

@Fiddi

So, something like this, placed in onPlayerRespawn.sqf?

_NG_newPlayer = _this select 0;
_NG_oldPlayer = _this select 1;

_NG_loadOut = getUnitLoadout _NG_oldPlayer;  //Gets the loadout from killed Player unit.
_NG_newPlayer setUnitLoadout _NG_loadOut;    //Sets old loadout on new Player unit.

It works, but only sort of..

Not everything is saved, primary weapon and launcher seems to disappear everytime?

Maybe there is something fishy going on with the  get and setUnitLoadout commands.  The wiki does mention it's WIP?

 

 

@phronk

I've been doing it more or less as you show in the video, only I've been using BIS_fnc_saveInventory and BIS_fnc_loadInventory instead.

It's working very well, right until the mission framerate gets a bit low, when there is a lot of AI activity.

 

Maybe I just have to many AI in the mission? Around 50 enemy infantry and a couple of cars. I don't know, is that to much?

Share this post


Link to post
Share on other sites

I'm slowly learning this scripting stuff, and I'm beginning to wonder about best practises.

 

I don't wanna be mean, but please use the forum search next time, or for all I care google. This question has been asked at least  3 times in the last 2 month.

 

https://www.google.de/?gws_rd=ssl#q=arma+3+respawn+with+gear

 

 

The solutions above should work just fine.

Share this post


Link to post
Share on other sites

I don't wanna be mean, but please use the forum search next time, or for all I care google. This question has been asked at least  3 times in the last 2 month.

 

https://www.google.de/?gws_rd=ssl#q=arma+3+respawn+with+gear

 

 

The solutions above should work just fine.

 

Well.. You could choose to not comment, if you deem the question not worthy of your time..?

 

And the above solutions work fine indeed, right up until the mission gets busy, then it starts loosing gear on respawns!

It seems like the old gear just doesen't get saved properly.

 

Anyway, I probably worded it poorly, but my real question was infact this:

Is there a more efficient way of running that loop?

 

And the loop in question

while {alive player} do
		{
			[player, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;
			sleep 10;
		};

Ended up making it a function, and calling it with spawn from both initlocalPlayer.sqf and onPlayerRespawn.sqf.

Share this post


Link to post
Share on other sites

 

Well.. You could choose to not comment, if you deem the question not worthy of your time..?

 

Oh i have a solution for you but this is not wort of my time you need to search it indeed.

Share this post


Link to post
Share on other sites

Good for you! You both win the internet today I guess, sigh...

Share this post


Link to post
Share on other sites

initplayerlocal.sqf

// Save loadout
player addEventHandler ["Killed", {
        [player, [missionNamespace, getPlayerUID player]] call BIS_fnc_saveInventory;
    }
];


// Load saved loadout on respawn
player addEventHandler ["Respawn", {
        [player, [missionNamespace, getPlayerUID player]] call BIS_fnc_loadInventory;

    }
];


  • Like 1

Share this post


Link to post
Share on other sites

"Jebus" spawn script made by DreadPirate has worked really well for me and Dread's support has been invaluable. Check out the example mission which illustrates quite well the different spawn modes available to AI.

 

edit: sorry disregard, a closer read of your post indicates you're not looking for AI respawn capabilities.

  • Like 1

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  

×