Advertisement
dapperstache

fn_repairVehicle

Nov 28th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. // Define the repair function
  2. params ["_veh", "_thistrigger"];
  3.  
  4. [_veh, _thistrigger] spawn {
  5. _veh = _this select 0;
  6. _thistrigger = _this select 1;
  7.  
  8. // Get the last repair time from the player's vehicle
  9. _lastRepairTime = player getVariable ["lastRepairTime", 0];
  10.  
  11. // Get the timeout value from the player
  12. _timeOut = player getVariable ["repairTimeout", 0];
  13.  
  14. _elapsedTime=0;
  15.  
  16. // If the timeout value is 0 (unset), set it to 0 initially to allow repairs
  17. if (_timeOut == 0) then {
  18.  
  19. _timeOut = 0;
  20.  
  21. };
  22.  
  23. // Initialize remaining time to 0 initially
  24. _remainingTime = 0;
  25.  
  26. // Check if the player has already repaired and calculate the remaining time accordingly
  27. if (_lastRepairTime > 0) then {
  28.  
  29. // Calculate the time elapsed since the last repair
  30. _elapsedTime = time - _lastRepairTime;
  31.  
  32. // Calculate the remaining time until the next repair is available
  33. _remainingTime = _timeOut - _elapsedTime;
  34.  
  35. // Check if remaining time is less than or equal to 0
  36. if (_remainingTime <= 0) then {
  37. // Reset remaining time to 0
  38. _remainingTime = 0;
  39. };
  40. };
  41.  
  42. /// Check if the remaining time is less than or equal to 0, indicating that the player can repair
  43. if (_remainingTime > 0 && (vehicle _veh inArea _thisTrigger)) then {
  44.  
  45. // Display a silent hint with the remaining time until the player can repair again
  46. while {_remainingTime > 0} do {
  47.  
  48. // Recalculate remaining time until the next repair is available
  49. _elapsedTime = time - _lastRepairTime;
  50. _remainingTime = _timeOut - _elapsedTime;
  51.  
  52. // Display the updated silent hint
  53. _hint = format["Vehicle Service Lockout: %1", [(_remainingTime / 60) + 0.01, "HH:MM"] call BIS_fnc_timetostring];
  54. hintSilent _hint;
  55.  
  56. // Wait for 1 second before checking again
  57. sleep 1;
  58.  
  59. // Check if the player has left the trigger area
  60. if !(vehicle _veh inArea _thisTrigger) exitWith { hintSilent ""; };
  61.  
  62. };
  63. };
  64.  
  65. // Get vehicle damage, fuel level, and ammo
  66. _vehicleDamage = damage _veh;
  67. _vehicleFuel = fuel _veh;
  68.  
  69. // Check if the vehicle needs repair
  70. if (_vehicleDamage >= 0.90 && _vehicleFuel >= 0.90) exitWith {};
  71.  
  72. // Monitor conditions and initiate repair process
  73. while {true} do {
  74.  
  75. // Recalculate remaining time until the next repair is available
  76. if (_lastRepairTime > 0) then {
  77.  
  78. // Calculate the time elapsed since the last repair
  79. _elapsedTime = time - _lastRepairTime;
  80.  
  81. // Calculate the remaining time until the next repair is available
  82. _remainingTime = _timeOut - _elapsedTime;
  83.  
  84. // Check if remaining time is less than or equal to 0
  85. if (_remainingTime <= 0) then {
  86.  
  87. // Reset remaining time to 0
  88. _remainingTime = 0;
  89.  
  90. }
  91.  
  92. };
  93.  
  94. if (driver _veh == player && !(isEngineOn _veh) && vehicle player == _veh && _veh inArea _thisTrigger) then {
  95.  
  96. // Check if repair service is available
  97. if (_remainingTime <= 0) then {
  98.  
  99. // Call the cinematic border function to activate it
  100. [0, 1, true, false] call NUP_fnc_cinematicBorder;
  101.  
  102. // Disable user input during repair
  103. //disableUserInput true;
  104.  
  105.  
  106. // Display repair messages
  107. titleText ["<t color='#00ff00' size='2'>Initializing vehicle services, please wait...</t><br/>", "PLAIN", -1, true, true];
  108. sleep 3.5;
  109. titleText ["<t color='#00ff00' size='2'>Assessing vehicle for damages...</t><br/>", "PLAIN", -1, true, true];
  110. sleep 1.5;
  111. titleText ["<t color='#00ff00' size='2'>Assessing any vehicle armaments...</t><br/>", "PLAIN", -1, true, true];
  112. sleep 1.5;
  113. titleText ["<t color='#00ff00' size='2'>Assessing vehicle fuel level...</t><br/>", "PLAIN", -1, true, true];
  114. sleep 1.5;
  115. titleText ["<t color='#00ff00' size='2'>Repairing vehicle... 25% Complete.</t><br/>", "PLAIN", -1, true, true];
  116. sleep 3;
  117. titleText ["<t color='#00ff00' size='2'>Repairing vehicle... 50% Complete.</t><br/>", "PLAIN", -1, true, true];
  118. sleep 3;
  119. titleText ["<t color='#00ff00' size='2'>Repairing vehicle... 75% Complete.</t><br/>", "PLAIN", -1, true, true];
  120. sleep 3;
  121. titleText ["<t color='#00ff00' size='2'>Repairing vehicle... 99% Complete.</t><br/>", "PLAIN", -1, true, true];
  122. sleep 3;
  123. _veh setDamage 0;
  124. _veh setVehicleAmmo 1;
  125. _veh setFuel 1;
  126. ["A3\Sounds_F\sfx\blip1.wss", 0.3] remoteExec ["playSoundUI", player];
  127. titleText ["<t color='#00ff00' size='2'>Vehicle service complete.</t><br/>", "PLAIN", -1, true, true];
  128.  
  129.  
  130. } else {
  131.  
  132. // Display lockout message
  133. hintSilent format["Vehicle Service Lockout: %1", [(_remainingTime / 60) + 0.01, "HH:MM"] call BIS_fnc_timetostring];
  134.  
  135. };
  136.  
  137. // Re-enable user input after repair
  138. //disableUserInput false;
  139.  
  140. // Call the cinematic border function to deactivate it
  141. [1, 1, true, false] call NUP_fnc_cinematicBorder;
  142.  
  143. // Store the current time as the last repair time
  144. player setVariable ["lastRepairTime", time, true];
  145.  
  146. // Set the repair timeout to 2 minutes after the first repair
  147. if (_timeOut == 0) then {
  148.  
  149. player setVariable ["repairTimeout", 25, true]; // Set timeout to 2 minutes (2 * 60 seconds)
  150.  
  151. };
  152.  
  153. // Clear any messages
  154. hintSilent "";
  155.  
  156. break; // Exit the loop once service is complete
  157.  
  158. } else {
  159.  
  160. if (driver _veh == player && (isEngineOn _veh) && vehicle player == _veh && (_veh inArea _thisTrigger) && (_remainingTime <= 0)) then
  161. {
  162. // Display lockout message if repair service is not available
  163. titleText ["<t color='#FFA500' size='2'>Disable engine to initiate vehicle services.</t><br/>", "PLAIN", -1, true, true];
  164. };
  165. };
  166.  
  167. sleep 1; // Check conditions every second
  168. };
  169. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement