Advertisement
Thatguy5532

Untitled

Jun 1st, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.16 KB | None | 0 0
  1. /*
  2. _player should be the player unit building the structure.
  3. _objectType should be the class name of the object to be built.
  4. _cost should be an array of [Supply, Ammo, Fuel] integers.
  5. _fob should be the FOB variable name.
  6. */
  7. params["_player", "_objectType", "_cost", "_fob"];
  8.  
  9. /* Check if the needed supplies exists at the current fob */
  10. private _resources = TRA_playerResources getOrDefault [_fob, [1000,1000,1000]];
  11.  
  12. if !([_resources, _cost] call TRA_fnc_resourceCheck) exitWith {
  13.     ["TaskFailed", ["", "Not enough resources to build object!"]] call BIS_fnc_showNotification;
  14.     false
  15. };
  16.  
  17. /* Create Provided Object */
  18. private _object = createVehicle[_objectType, [1, 1, 1000], [], 0, "NONE"];
  19.  
  20. /* Attach object to player */
  21. private _playerDist = 10;
  22. _object attachTo[_player, [0, _playerDist, 0]];
  23.  
  24. /* Make the object a mission variable in order to grab it later. */
  25. missionNamespace setVariable ['TRA_buildObject', _object];
  26.  
  27. /* Make mission variables to be used later */
  28. missionNamespace setVariable ['TRA_buildHeight', 0];
  29. missionNamespace setVariable ['TRA_buildRotation', 0];
  30. missionNamespace setVariable ['TRA_buildSuccess', false];
  31. missionNamespace setVariable ['TRA_buildCancel', false];
  32.  
  33. /* Create display in order to reserve keys for object manipulation. */
  34. private _id = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call TRA_rotateObject"];
  35. private _id2 = (findDisplay 46) displayAddEventHandler ["MouseButtonDown","_this call TRA_cancelRotation"];
  36.  
  37. /* ID needed to escape the FOB orienting */
  38. missionNamespace setVariable ['TRA_buildDisplayID', _id];
  39. missionNamespace setVariable ['TRA_cancelDisplayID', _id2];
  40.  
  41. TRA_buildCtrlPic = "res\Controls.paa";
  42.  
  43. with uiNamespace do {
  44.     TRA_buildControls = findDisplay 46 ctrlCreate ["RscPicture", -1];
  45.     TRA_buildControls ctrlSetPosition [0.1, 0.4, 0.7, 0.5];
  46.     TRA_buildControls ctrlCommit 0;
  47. };
  48.  
  49. (uiNamespace getVariable "TRA_buildControls") ctrlSetText (TRA_buildCtrlPic);
  50.  
  51.  
  52. TRA_rotateObject = {
  53.     params["_display", "_key", "_shift", "_ctrl", "_alt"];
  54.     if (isNil 'TRA_buildObject') exitWith {
  55.         systemChat "Build object was not set as a missionNamespace variable";
  56.         false;
  57.     };
  58.     if (missionNamespace getVariable ['TRA_buildCancel', false]) then {
  59.         _key = 1000;
  60.     };
  61.    
  62.     if !(_key in [203, 205, 200, 208, 57, 1000]) exitWith {
  63.         false
  64.     };
  65.  
  66.     private _rotation = TRA_buildRotation;
  67.     private _height = TRA_buildHeight;
  68.     private _rotate = false;
  69.     private _elevate = false;
  70.  
  71.     private _rotateIncrement = 1;
  72.     private _elevateIncrement = 0.2;
  73.  
  74.     switch (_key) do {
  75.         case 203: {
  76.             _rotation = _rotation + _rotateIncrement;
  77.             _rotate = true;
  78.         };
  79.         case 205: {
  80.             _rotation = _rotation - _rotateIncrement;
  81.             _rotate = true;
  82.         };
  83.         case 200: {
  84.             _height = _height + _elevateIncrement;
  85.             _elevate = true;
  86.         };
  87.         case 208: {
  88.             _height = _height - _elevateIncrement;
  89.             _elevate = true;
  90.         };
  91.         case 57: {
  92.             (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_buildDisplayID];
  93.             detach TRA_buildObject;
  94.             missionNamespace setVariable ['TRA_buildHeight', 0];
  95.             missionNamespace setVariable ['TRA_buildRotation', 0];
  96.             missionNamespace setVariable ['TRA_buildObject', objNull];
  97.             (uiNamespace getVariable "TRA_buildControls") ctrlSetText ("");
  98.             missionNamespace setVariable ['TRA_buildSuccess', true];
  99.             ["TaskSucceeded", ["", "Object Built!"]] call BIS_fnc_showNotification;
  100.         };
  101.         case 1000: {
  102.             (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_buildDisplayID];
  103.             detach TRA_buildObject;
  104.             deleteVehicle TRA_buildObject;
  105.             missionNamespace setVariable ['TRA_buildHeight', 0];
  106.             missionNamespace setVariable ['TRA_buildRotation', 0];
  107.             missionNamespace setVariable ['TRA_buildObject', objNull];
  108.             (uiNamespace getVariable "TRA_buildControls") ctrlSetText ("");
  109.             missionNamespace setVariable ['TRA_buildSuccess', false];
  110.             ["TaskFailed", ["", "Object build canceled!"]] call BIS_fnc_showNotification;
  111.         };
  112.     };
  113.  
  114.     if (_rotate) then {
  115.         TRA_buildObject setDir _rotation;
  116.     };
  117.     if (_elevate) then {
  118.         _player = attachedTo TRA_buildObject;
  119.         TRA_buildObject attachTo [_player, [0, 10, _height]];
  120.         TRA_buildObject setDir TRA_buildRotation;
  121.     };
  122.     TRA_buildRotation = _rotation;
  123.     TRA_buildHeight = _height;
  124.  
  125.     true
  126. };
  127.  
  128. TRA_cancelRotation = {
  129.     params["_display", "_key", "_shift", "_ctrl", "_alt"];
  130.     if (_key isNotEqualTo 1) exitWith {
  131.         false
  132.     };
  133.     // systemChat (str _this);
  134.     missionNamespace setVariable ['TRA_buildCancel', true];
  135.     (findDisplay 46) displayRemoveEventHandler ["KeyDown", TRA_cancelDisplayID];
  136.     false
  137. };
  138.  
  139. /* While build KeyDown event handler exists, do: */
  140. while {(findDisplay 46) getEventHandlerInfo ["KeyDown", TRA_buildDisplayID] select 0} do {
  141.     sleep 1;
  142. };
  143.  
  144. /* Return whether build was a success or failure after KeyDown eh is removed */
  145. missionNamespace getVariable ['TRA_buildSuccess', false];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement