Advertisement
MulleDK19

ARMA 3 - Enable Weapon Holstering

Oct 9th, 2014
6,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. // MulleDK19 © 2014
  2. // Allows holstering of weapons on player units. Works in multiplayer.
  3. // Usage: UNIT execVM "EnableWeaponHolstering.sqf";
  4. // Eg. player execVM "EnableWeaponHolstering.sqf";
  5.  
  6. if (!isPlayer _this) exitWith
  7. {
  8.     // Action makes no sense on AI units.
  9. };
  10.  
  11. _holsterAction = _this getVariable "HolsterAction";
  12. if (!isNil "_holsterAction") then
  13. {
  14.     // Remove existing action.
  15.     _this removeAction _holsterAction;
  16. };
  17.  
  18. waitUntil { currentWeapon _this != "" };
  19.  
  20. _holsterAction = _this addAction ["Holster weapon",
  21. {
  22.     _unit = _this select 1;
  23.     _unit action ["SwitchWeapon", _unit, _unit, 100];
  24.     _holsterAction = _unit getVariable "HolsterAction";
  25.     _unit setVariable ["HolsterAction", nil];
  26.     _unit removeAction _holsterAction;
  27.    
  28.     if (primaryWeapon _unit == "" && secondaryWeapon _unit == "") exitWith
  29.     {
  30.         sleep 1;
  31.         _unit execVM "EnableWeaponHolstering.sqf";
  32.     };
  33.    
  34.     _unit spawn
  35.     {
  36.         // Primary weapon action doesn't show when weapons are holstered. Make a custom one to select the primary weapon.
  37.         _selectPrimaryWeaponAction = nil;
  38.         if (primaryWeapon _this != "") then
  39.         {
  40.             _selectPrimaryWeaponActionName = "Weapon ";
  41.             _weaponName = getText (configFile >> "CfgWeapons" >> (primaryWeapon _this) >> "displayName");
  42.             _selectPrimaryWeaponActionName = _selectPrimaryWeaponActionName + _weaponName;
  43.             _selectPrimaryWeaponAction = _this addAction [_selectPrimaryWeaponActionName, { _unit = _this select 0; _unit selectWeapon primaryWeapon _unit }];
  44.         };
  45.        
  46.         // Wait until a weapon is unholstered.
  47.         while { currentWeapon _this == "" } do
  48.         {
  49.             sleep 0.1;
  50.         };
  51.        
  52.         // Delete the action.
  53.         _this removeAction _selectPrimaryWeaponAction;
  54.         sleep 1;
  55.         _this execVM "EnableWeaponHolstering.sqf";
  56.     };
  57. }];
  58.  
  59. _this setVariable ["HolsterAction", _holsterAction];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement