Advertisement
dapperstache

fn_loadSupplies.sqf

Feb 7th, 2025 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. //Title: NUP_fnc_loadSuppies
  2. //File: NUP\NUP_flagCapture\functions\fn_loadSuppies.sqf
  3. //Author: Dapperstache
  4. //Purpose: Stores a value in a param in the"Supply Truck", indicating whether or not it is loaded.
  5. //Usage: [ _veh, _trigger ] call NUP_fnc_loadSuppies;
  6.  
  7. params ["_veh", "_trigger"];
  8.  
  9. // Ensure the vehicle hasn't already loaded supplies
  10.  
  11. if ((_veh getVariable ["NUP_SuppliesLoaded", 0]) != 1) then {
  12.  
  13. params ["_veh", "_trigger"];
  14.  
  15. private _driver = driver _veh;
  16.  
  17. _damage = damage _veh;
  18. if (_damage > 0.01) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'>SUPPLY VEHICLE DAMAGED. VISIT VEHICLE SERVICE BAY.</t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  19.  
  20. // Configurable time for service cooldown (in seconds)
  21. private _serviceCooldownTime = 120; // 2 minutes (change this to adjust cooldown time)
  22.  
  23. // Get the last service time, defaulting to -1 if not set
  24. private _lastServiceTime = _veh getVariable ["NUP_lastServiceTime", -1]; // Use -1 to signify no prior service
  25.  
  26. // Get the current server time
  27. private _currentTime = serverTime;
  28.  
  29. if (speed _veh > 0) then {
  30.  
  31. [["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'>COME TO A COMPLETE STOP AND DISABLE ENGINE</t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];
  32. if (_driver != driver _veh) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  33. };
  34. if (_driver != driver _veh) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  35.  
  36. waitUntil {speed _veh == 0};
  37.  
  38. if (speed _veh == 0 && (isEngineOn _veh)) then {
  39.  
  40. [["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'>DISABLE ENGINE TO BEGIN LOADING SUPPLIES</t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];
  41. if (_driver != driver _veh) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  42. };
  43. if (_driver != driver _veh) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  44. waitUntil {!(isEngineOn _veh)};
  45. if (_driver != driver _veh) exitWith {[["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];};
  46. [["<t font='PuristaMedium' shadow='2' color='#00ff00' size='1.5'> </t><br/>", "PLAIN", -1, true, true]] remoteExec ["titleText", owner _driver];
  47.  
  48. // Show cinematic border and loading text
  49. [0, 1, true, false] remoteExec ["NUP_fnc_cinematicBorder", owner _driver];
  50. ["FD_Course_Active_F"] remoteExec ["playSound", owner _driver];
  51. _veh engineOn false;
  52. _veh addEventHandler ["Engine", { params ["_vehicle","_engineState"]; if (_engineState == true) then { _vehicle engineOn false}; }];
  53.  
  54. // Create the progress bar dynamically
  55. ["progressBarRsc", "PLAIN"] call BIS_fnc_rscLayer;
  56. private _display = findDisplay 46; // Fetch the newly created display (46 is the ID of "RscDisplayEmpty")
  57. // Create the text above the progress bar
  58.  
  59.  
  60. private _progressTextCtrl = _display ctrlCreate ["RscText", 123457];
  61. _progressTextCtrl ctrlSetPosition [0.3, 0.56, 0.4, 0.03]; // Position the text above the bar
  62. _progressTextCtrl ctrlSetText "LOADING SUPPLIES..."; // Set the text
  63. _progressTextCtrl ctrlSetTextColor [0, 1, 0, 1];
  64. _progressTextCtrl ctrlSetFont "PuristaMedium";
  65. _progressTextCtrl ctrlCommit 0;
  66.  
  67. private _progressBarCtrlBG = _display ctrlCreate ["RscProgress", 123455];
  68. private _progressBarCtrl = _display ctrlCreate ["RscProgress", 123456];
  69.  
  70. _progressBarCtrlBG ctrlSetPosition [0.3, 0.60, 0.4, 0.03]; // [x, y, width, height]
  71. _progressBarCtrl ctrlSetPosition [0.3, 0.60, 0.4, 0.03]; // [x, y, width, height]
  72.  
  73. _progressBarCtrlBG ctrlSetTextColor [0, 0, 0, 1];
  74. _progressBarCtrlBG ctrlSetBackgroundColor [0, 0, 0, 1];
  75. _progressBarCtrl ctrlSetBackgroundColor [0, 0, 0, 1];
  76.  
  77. _progressBarCtrlBG ctrlCommit 0;
  78. _progressBarCtrl ctrlCommit 0;
  79.  
  80. _progressBarCtrlBG progressSetPosition 100;
  81. _progressBarCtrl progressSetPosition 0;
  82.  
  83. private _totalTime = 5; // Total loading time in seconds
  84. private _updateInterval = 0.003; // Progress bar update interval in seconds
  85. private _progress = 0;
  86.  
  87. //attach Supply boxes to truck for visual reference
  88. // Create crates
  89. private _crate1 = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "NONE"];
  90. _crate1 allowDamage false;
  91. private _crate2 = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "NONE"];
  92. _crate2 allowDamage false;
  93. private _crate3 = createVehicle ["CargoNet_01_box_F", [0, 0, 0], [], 0, "NONE"];
  94. _crate3 allowDamage false;
  95.  
  96. // Simulate loading with progress bar
  97. for "_i" from 0 to (_totalTime / _updateInterval) do {
  98. _progress = _i * (_updateInterval / _totalTime);
  99. _progressBarCtrl progressSetPosition _progress;
  100. if (_progress >= .33 && _progress <= 0.34) then {_crate1 attachTo [_veh, [0, 0, 0.2], "", false];};
  101. if (_progress >= .66 && _progress <= 0.67) then {_crate2 attachTo [_veh, [0, -1.5, 0.2], "", false];};
  102. if (_progress >= .99 && _progress <= 1.00) then {_crate3 attachTo [_veh, [0, -3.0, 0.2], "", false];};
  103. // Front crate
  104. sleep _updateInterval;
  105. };
  106. _veh setVariable ["NUP_vehCrates", [_crate1, _crate2, _crate3]];
  107.  
  108. _progressBarCtrl progressSetPosition 0;
  109. _progressBarCtrlBG progressSetPosition 0;
  110.  
  111. // Mark the vehicle as loaded
  112. _veh setVariable ["NUP_SuppliesLoaded", 1, true];
  113.  
  114. //hint format ["Supplies Loaded Status: %1", _veh getVariable "NUP_SuppliesLoaded"];
  115. ["FD_Finish_F"] remoteExec ["playSound", owner _driver];
  116. _veh removeAllEventHandlers "Engine";
  117. _veh engineOn true;
  118. _barGate = nearestObject [_trigger, "Land_BarGate_01_open_F"];
  119. _barGate animateSource ["Door_1_source", 1];
  120. [_barGate] spawn {
  121. params ["_barGate"];
  122. sleep 20;
  123. _barGate animateSource ["Door_1_source", 0];
  124. };
  125. _progressTextCtrl ctrlSetText "SUPPLIES LOADED";
  126. // Remove cinematic border
  127. [1, 1, true, false] remoteExec ["NUP_fnc_cinematicBorder", owner _driver];
  128. _progressTextCtrl ctrlSetTextColor [0, 1, 0, 0];
  129. sleep 1.5;
  130. if (true) exitWith {};
  131. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement