Advertisement
BobTheHunted

fn_UnitTakeControl

Sep 16th, 2017
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 1.83 KB | None | 0 0
  1. // Switch player to friendly unit - By BobTheHunted
  2. // Heavily based on BIS_fnc_modulRemoteControl for Zeus unit control
  3. // nul = [player,unit] call BTH_fnc_UnitTakeControl;
  4. // player: Object - Original player unit.
  5. // unit:-- Object - Unit to switch to.
  6. // Example: nul = [player,bob] call BTH_fnc_UnitTakeControl;
  7.  
  8. params [
  9.     ['_caller',objNull,[objNull]],
  10.     ['_unit',objNull,[objNull]]
  11. ];
  12.  
  13. if (isNull _unit) exitWith {hint "No suitable unit found"};
  14. if (isPlayer _unit) exitWith {hint "You cannot control a player unit!"};
  15. if (!alive _unit) exitWith {hint "You cannot control a dead unit!"};
  16. if (side _caller != side _unit) exitWith {hint "You cannot control a unit that isn't on your side!"};
  17.  
  18. [_caller,_unit] spawn {
  19.     params [
  20.         ['_caller',objNull,[objNull]],
  21.         ['_unit',objNull,[objNull]]
  22.     ];
  23.     _vehicle = vehicle _unit;
  24.     _vehicleRole = str assignedVehicleRole _unit;
  25.  
  26.     //--- Switch
  27.     _caller remoteControl (driver _unit);
  28.     if (cameraOn != _vehicle) then {
  29.         _vehicle switchCamera cameraView;
  30.     };
  31.  
  32.     _unit addAction [
  33.         "<t color='#53BE5F'>Exit Unit Control</t>",
  34.         {
  35.             private _unit = (_this select 0);
  36.             private _caller = (_this select 3);
  37.  
  38.             removeAllActions _unit;
  39.  
  40.             private _vehicle = vehicle _unit;
  41.             private _vehicleRole = str assignedVehicleRole _unit;
  42.             private _rating = rating _caller;
  43.  
  44.             _caller addRating (-rating _caller + _rating);
  45.             objNull remoteControl _unit;
  46.  
  47.             sleep 0.01;
  48.             _caller switchCamera cameraView;
  49.         },
  50.         _caller, -1, false, true, "", "true", 1.5
  51.     ];
  52.  
  53.     _vehicle = vehicle _unit;
  54.     _vehicleRole = str assignedVehicleRole _unit;
  55.     _rating = rating _caller;
  56.  
  57.     _caller addRating (-rating _caller + _rating);
  58.  
  59.     waitUntil {!alive _unit || !alive _caller};
  60.  
  61.     removeAllActions _unit;
  62.  
  63.     objNull remoteControl _unit;
  64.  
  65.     sleep 0.01;
  66.     _caller switchCamera cameraView;
  67. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement