Jump to content
CaptainDawson

Respawn with loadout script?

Recommended Posts

Anyone know where to find the script for making players respawn with their loadouts? Yes, I know there are tutorials and forum posts for this, but so far all the ones I've found are either incomplete, or the links to the code are dead.

 

Any help with finding the script and how to use it would be much appreciated! 

Share this post


Link to post
Share on other sites

This is what i use, hope it helps:

 

 _pid = getPlayerUID _player;
 
 [ _player, [ profilenamespace, _pid], [], false ] call BIS_fnc_saveInventory;

 

 

And to load the inv call this on respawn:

 

 

 _pid = getPlayerUID _player;
 [_player, [profilenamespace, _pid]] call BIS_fnc_loadInventory;

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 6/13/2019 at 4:54 AM, CaptainDawson said:

Anyone know where to find the script for making players respawn with their loadouts?

 

Hi Cap

 

Can I check what you were hoping to do, or what difficulties you were having that required this script? I only ask because I'm wondering if this is key to what I might need as well. It depends upon what your issue is.

 

Anfo

Share this post


Link to post
Share on other sites
20 hours ago, gc8 said:

This is what i use, hope it helps:

 


 _pid = getPlayerUID _player;
 
 [ _player, [ profilenamespace, _pid], [], false ] call BIS_fnc_saveInventory;

 

 

And to load the inv call this on respawn:

 

 


 _pid = getPlayerUID _player;
 [_player, [profilenamespace, _pid]] call BIS_fnc_loadInventory;

 

 

 

Hi gc8

I'm afraid I have to be that dumb guy who needs to ask where this code goes?
Maybe onplayerkilled.sqf fo the first, and onplayerrespawn.sqf for the second maybe?

 

Anfo

Share this post


Link to post
Share on other sites
6 minutes ago, anfo said:

Maybe onplayerkilled.sqf fo the first, and onplayerrespawn.sqf for the second maybe?

this

Share this post


Link to post
Share on other sites
1 minute ago, sarogahtyp said:

this

 

Thanks Sarogahtyp!

If a player loses connection to the server, does the server see that as a death (killed)?
Also, say the player starts with 5 magazines, then dies/disconnects with 2 magazines, does he respawn with the original 5, or the 2 when he died?

 

Cheers

Share this post


Link to post
Share on other sites
54 minutes ago, anfo said:

If a player loses connection to the server, does the server see that as a death (killed)?

 

I don't think so but you can use the "HandleDisconnect" EH.


 

addMissionEventHandler ["HandleDisconnect", 
{
 params ["_player", "_id", "_uid", "_name"];
 
 // Your player save code here
 
 false
}];

 

55 minutes ago, anfo said:

Also, say the player starts with 5 magazines, then dies/disconnects with 2 magazines, does he respawn with the original 5, or the 2 when he died?

 

If you load the loadout with BIS_fnc_loadInventory then he should have all mags

Share this post


Link to post
Share on other sites

This is the setup that was the first to work for me. Save loadout on death, and on respawn, delete the new loadout and then load the previously saved loadout.

 

From ArmaPhronk

https://www.youtube.com/watch?v=BiBXZFZEF70

 

Create .sqf/.ext files in the mission folder. You do this by making in the folder: New->Text Document, open the document, Save As->All File Types. type ".sqf" or ".ext" as the extension of the file name, and save. Now delete the .txt and open the new .sqf or .ext in Notepad++ to insert the code.

 

onPlayerKilled.sqf

Quote

player setVariable["Saved_Loadout",getUnitLoadout player];

 

onPlayerRespawn.sqf

Quote

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

 

description.ext

Quote

respawn=3;
respawnDelay=2;
respawnOnStart=-1;

 

init.sqf

Quote

0 spawn {
    waitUntil {player == player};
    player addEventHandler ["Respawn", {
        (_this select 0) setUnitLoadout getUnitLoadout (_this select 1);
        deleteVehicle (_this select 1);
    }];
};

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi again

 

The reason I'm interested in this thread, is that we have largely a simple crew of mission makers, none (including yours truly) who know much about coding. The system we use to respawn is clunky, but it involves ACE Spectator upon death. However if the player is authorised to re-enter the game, they have to abort and rejoin from the lobby. Respawning simply doesn't work at this point.

I was therefore hoping to use a combination of this code and hope it works with ACE spectator. This is the current respawn code we use to achieve this:

respawn = 3;
respawnDialog = 0;
respawnDelay = 9999999;
respawnTemplates[] = {"ace_spectator"};

Does anybody have any insightful comments to offer please?

 

Anfo

Share this post


Link to post
Share on other sites
7 hours ago, anfo said:

ACE Spectator upon death. However if the player is authorised to re-enter the game, they have to abort and rejoin from the lobby

A lot of milsim units use a "respawn bunker". Basically it's just a bunch of walls from which dead players cannot exit, you place computers there so that they can access (and exit) a spectator mode. But if you need to allow them back in you can just teleport them.

Also for the save /restore loadout issue.
Create 2 files at the root of your mission.
One is onPlayerKilled.sqf and the other is on playerRespawn.sqf withe the following code.

 

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

//onPlayerRespawn.sqf
player setUnitLoadout(player getVariable["Saved_Loadout",[]]);

 

Share this post


Link to post
Share on other sites
13 minutes ago, Mr H. said:

you place computers there so that they can access (and exit) a spectator mode

 

Interesting concept, @Mr H., thank you. ACE Spectator is usable from a computer object as you say?

Share this post


Link to post
Share on other sites

Yes:
https://ace3mod.com/wiki/framework/spectator-framework.html
 

Quote

The public function ace_spectator_fnc_setSpectator which can be used at any time to open/close the spectator interface

 

 * Arguments:
 * 0: Spectator state of local client <BOOL> (default: true)
 * 1: Force interface <BOOL> (default: true)
 * 2: Hide player (if alive) <BOOL> (default: true)
 *
 * Return Value:
 * None
 *
 * Example:
 * [true] call ace_spectator_fnc_setSpectator

 

Share this post


Link to post
Share on other sites

If you're using ACRE2 or TFAR you will also have to call:
 

// ACRE / TFAR 
//[true] call acre_api_fnc_setSpectator;
//[player, true] call TFAR_fnc_forceSpectator;

 

Share this post


Link to post
Share on other sites
2 minutes ago, Mr H. said:

If you're using ACRE2 or TFAR you will also have to call:
 


// ACRE / TFAR 
//[true] call acre_api_fnc_setSpectator;
//[player, true] call TFAR_fnc_forceSpectator;

 

 

I'm also perusing your interesting wiki 😉

  • 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

×