Author: Pierre MGI
Author Website:

Short description: How to respawn with exactly the same loadout and same ammo count on each mag.
Date: 2016-07-16 17:24
Submitted by: Pierre MGI


Comments: (0)
Rating:



 

Respawning with same loadout and ammos

by
Pierre MGI


Description
This script allows a player or an AI unit to respawn with the same equipment and the same ammo count in each mag,
current mags included. For MP missions.

Code

if (!isServer) exitWith {};
{_x addMPEventHandler ["MPkilled", {
  _unit = _this select 0;

  if (!isPlayer _unit) exitWith {removeSwitchableUnit _unit}; // optional

  [_unit, [missionNamespace, format ["cur_inv_%1", _unit getVariable "invKill"]]] call BIS_fnc_saveInventory;
  _unit setVariable ["MGI_ammo1",_unit ammo (primaryWeapon _unit)];
  _unit setVariable ["MGI_ammo2",_unit ammo (handgunWeapon _unit)];
  _unit setVariable ["MGI_ammo3",_unit ammo (secondaryWeapon _unit)];
  _unit setVariable ["MGI_mags",magazinesAmmoFull _unit];
  _unit setVariable ["MGI_weapon",currentWeapon _unit];

}]} forEach playableUnits + switchableUnits;


{_x addMPEventHandler ["MPRespawn", {
  _unit = _this select 0;
  _corpse = _this select 1;
  if (!isPlayer _unit) exitWith {deleteVehicle _unit}; // optional

  [_unit, [missionNamespace, format ["cur_inv_%1", _unit getVariable "invKill"]]] call BIS_fnc_loadInventory;
  {_unit removeMagazine _x} forEach magazines _unit;
  _unit setAmmo [primaryWeapon _unit, 0];
  _unit setAmmo [handGunWeapon _unit, 0];
  _unit setAmmo [secondaryWeapon _unit, 0];
  { if (((_unit getVariable "MGI_mags") select _foreachindex select 3) <= 0) then {
    _unit addMagazine [_x select 0,_x select 1]}} forEach (_unit getVariable "MGI_mags");
  _unit setAmmo [primaryWeapon _unit,_unit getVariable "MGI_ammo1"];
  _unit setAmmo [handGunWeapon _unit,_unit getVariable  "MGI_ammo2"];
  _unit setAmmo [secondaryWeapon _unit,_unit getVariable "MGI_ammo3"];
  _unit selectWeapon (_unit getVariable "MGI_weapon");

  removeAllWeapons _corpse;
  removeBackpackGlobal _corpse;
  removeVest _corpse;
  removeAllAssignedItems _corpse;
  removeAllItems _corpse;
  removeGoggles _corpse;
  removeHeadgear _corpse;
  {deleteVehicle _x} forEach nearestObjects [(getPosATL _corpse),["WeaponHolderSimulated","groundWeaponHolder"],5];

}]} forEach playableUnits + switchableUnits;

Usage
in init.sqf or any script running at start. In a trigger (no condition).



Tags: Ammo,   Loadout,   Magazines,   Respawn