MrSydney 1 Posted April 9, 2022 Good day, I am having trouble with getUnitLoadout and setUnitLoadout functions. I want to make it so that when players respawn, they have the same loadout like they did before they died/respawned. But in some cases it removes the primary and secondary weapons. I am using the code below: //In onPlayerKilled.sqf I have: player setVariable ["Saved_Loadout",getUnitLoadout player]; //In onPlayerRespawn.sqf I have: player setUnitLoadout (player getVariable ["Saved_Loadout",[]]); It works when players respawn through the menu. But the problem is when they are shot and go into the incapacitated animation (I have revive enabled). I assume that when you go into the incapacitated state you lose your weapons, and then it saves your loadout when you "Hold space" to respawn. So technically you did not have a weapon when the script saved your loadout. I was thinking that the "getUnitLoadout" function should be triggered just before you go into the incapacitated state, but I am not sure how to do that. Maybe check if the player's health is below 10%? Any help would be appreciated. -MrSydney Share this post Link to post Share on other sites
pierremgi 4853 Posted April 9, 2022 When player is killed, the corpse looses the primary weapon and the launcher if any. You are using an sqf running when the player is killed, without the useful parameters (see BIKI link). With killed event only: onPlayerKilled.sqf, (so suspension is allowed), here: params ["_oldPlyr"]; // you can change the variable name and use the 1st one only if you don't need the others. private _loadout = getUnitLoadout _oldPlyr; waitUntil {alive player}; player setUnitLoadout _loadout; // here you can use player because this command is available and refers to new unit Other method: As far as, respawn is concerned, you could forget the old event sqf (onPlayerKilled.sqf and onPlayerRespawn.sqf), for event handlers (code in init field of the playable units for this example): this addEventHandler ["killed",{ params ["_Plyr"]; _plyr setVariable ["oldLoadout",getUnitLoadout _Plyr,TRUE]; }]; this addEventHandler ["respawn",{ params ["_newPlyr","_oldOne"]; _newPlyr setUnitLoadout (_oldOne getVariable ["oldLoadout",getUnitLoadout _newPlyr]); }]; Note : instead of this, you can apply the EH on player everywhere player is defined, initPlayerLocal.sqf for example. 1 Share this post Link to post Share on other sites
MrSydney 1 Posted April 9, 2022 Thank you, The first one did the same. Does "_oldPlyr" refer to the unit while it was still alive or while it was incapacitated and waiting to be revived? Second one with event handlers solved the issue. But now I am confused when the eventHandler is triggered. "Killed" in this context looks like it applies to when the player/unit has been put into the incapacitated state. The wiki just "when the unit is killed". But "onPlayerKilled" says the same, but seems to happen after the incapacitated state, when the unit becomes an object/corpse (bleeds out/dies/respawns). Can you help me understand maybe? Share this post Link to post Share on other sites
pierremgi 4853 Posted April 9, 2022 The first method works for me, but you need to get the loadout as soon as the player is killed, i.e. without extra code before (and check twice your local variable names in params and following lines). EH killed fires... when the player is killed, so unconscious state is not triggering this kind of EH. While player can be healed, nothing triggers, no matter the sqf or the EH you scripted. life state is : incapacitated. Once the bleedout time is over (if any!), player dies, EH "killed" or any similar EHs (MPKilled, entityKilled) or even onplayerKilled.sqf, is firing (depending on their specific syntax of course) As you can see, you can refer to the unit who dies and, if you work with this parameter (present in all EHs or sqf "killed" versions), you can set a variable on it (like I did), with all data you need. That's reliable. Then , the respawn time count down starts and the life state is DEAD-RESPAWN if I'm right. Player can't be healed anymore and must wait for respawn. Once over, the player respawns and the EH "respawn" (or equivalent EHs or sqf) fires (not before). As you can see, the 2 first parameters in respawn events (all versions) are 1: new unit, 2: old unit... Scripting for old unit (getUnitLoadout as example) is not reliable (for all data), but you can grab the variable set above on the old unit, i.e. the corpse (not deleted so far). This parameter remains useful for positioning or deleting the corpse after all. New unit is, of course, the new played unit, totally reliable. Life state is now HEALTHY. Share this post Link to post Share on other sites
MrSydney 1 Posted April 9, 2022 59 minutes ago, pierremgi said: but you need to get the loadout as soon as the player is killed, i.e. without extra code before Ok I understand. 1 hour ago, pierremgi said: Once the bleedout time is over (if any!), player dies, EH "killed" or any similar EHs (MPKilled, entityKilled) or even onplayerKilled.sqf, is firing I thought they fired at two different times for some reason. Thank you very much for the help. Share this post Link to post Share on other sites