Advertisement
dapperstache

onPlayerRespawn.sqf

Jan 3rd, 2025
2,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.45 KB | None | 0 0
  1.     params ["_newUnit", "_oldUnit", "_respawn", "_respawnDelay"];
  2.  
  3.     _newUnit setPos [0, 0, 0];
  4.     [] call NUP_fnc_playerMarkers;
  5.     _newUnit allowDamage false;
  6.     _newUnit enableSimulation false;
  7.     [0, 1, true, false] call NUP_fnc_cinematicBorder;
  8.  
  9.     // Create camera to focus on the dead body
  10.     _camera = "camera" camCreate (getPosATL _oldUnit);
  11.     _camera cameraEffect ["INTERNAL", "BACK"];
  12.     _camera camPrepareTarget _oldUnit;
  13.     _camera camCommitPrepared 0;
  14.     _camera camPrepareRelPos [0, 0, 3];
  15.     _camera camPrepareFOV 0.5;
  16.     _camera camCommitPrepared 0;
  17.  
  18.     // Open the RespawnDialog
  19.     createDialog "RespawnDialog";
  20.  
  21.     // Disable scoring UI
  22.     private _scoreHUD = uiNamespace getVariable "ScoreHUD";
  23.     if (!isNull _scoreHUD) then {
  24.         _scoreHUD closeDisplay 1;
  25.     };
  26.  
  27.     // Pass variables to the dialog
  28.     private _display = findDisplay 9500; // RespawnDialog display
  29.    
  30.     // Fetch the map control and set its position to the player's position
  31.     private _map = _display displayCtrl 9501; // Map control (_CT_MAP)
  32.     if (!isNull _map) then {
  33.         _map ctrlMapAnimAdd [0, 0.025, getPosATL _oldUnit]; // Set the map to player's position
  34.         ctrlMapAnimCommit _map;
  35.     };
  36.  
  37.  
  38.     // Fetch the dialog controls
  39.     _respawnButton = _display displayCtrl 1050; // Respawn button (_CT_BUTTON)
  40.     _respawnButton setVariable ["NUP_camInstance", _camera];
  41.     _respawnButton setVariable ["NUP_newUnitInstance", _newUnit];
  42.     _respawnButton setVariable ["NUP_oldUnitInstance", _oldUnit];
  43.  
  44.     // Attach functionality to the Respawn Button
  45.     private _NUP_respawnEH = _respawnButton ctrlAddEventHandler ["ButtonClick", {
  46.         params ["_ctrl"];
  47.  
  48.         // Retrieve variables from the dialog
  49.         _display = findDisplay 9501;
  50.         _camera = _ctrl getVariable "NUP_camInstance";
  51.         _newUnit = _ctrl getVariable "NUP_newUnitInstance";
  52.         _oldUnit = _ctrl getVariable "NUP_oldUnitInstance";
  53.         diag_log format ["_oldUnit %1, _newUnit %2, _camera %3", _oldUnit, _newUnit, _camera];
  54.         //hintc format ["_oldUnit %1, _newUnit %2, _camera %3", _oldUnit, _newUnit, _camera];
  55.  
  56.         // Retrieve the new unit's side
  57.         private _playerSide = side _newUnit;
  58.         private _respawnMarker = switch (_playerSide) do {
  59.             case west: { "start_WEST" };
  60.             case east: { "start_EAST" };
  61.             case independent: { "start_INDEP" };
  62.             default { "start_CIVILIAN" };
  63.         };
  64.  
  65.         private _markerPos = getMarkerPos _respawnMarker;
  66.  
  67.         // Building search logic
  68.         _buildingClasses = [
  69.             "Land_Cargo_HQ_V1_F", "Land_Cargo_HQ_V3_F", "Land_Medevac_HQ_V1_F",
  70.             "Land_Cargo_House_V1_F", "Land_Cargo_Tower_V1_F", "Land_i_Shed_Ind_F"
  71.         ];
  72.         _nearestBuildings = nearestObjects [_markerPos, _buildingClasses, 100];
  73.         _allBuildingPositions = [];
  74.         {
  75.         _buildingPositions = [_x] call BIS_fnc_buildingPositions;
  76.             _allBuildingPositions = _allBuildingPositions + _buildingPositions;
  77.         } forEach _nearestBuildings;
  78.  
  79.         // Determine respawn position
  80.         _respawnPos = if (count _allBuildingPositions > 0) then {
  81.             selectRandom _allBuildingPositions
  82.         } else {
  83.             _markerPos
  84.         };
  85.  
  86.         // Move player to respawn position
  87.         _newUnit allowDamage true;
  88.         _newUnit enableSimulation true;
  89.         _newUnit setPosATL _respawnPos;
  90.  
  91.  
  92.         _camera cameraEffect ["TERMINATE", "BACK"];
  93.         camDestroy _camera;
  94.  
  95.         // Delete the old unit after 60 seconds
  96.         [_oldUnit] spawn {
  97.             sleep 60;
  98.             deleteVehicle _oldUnit;
  99.         };
  100.  
  101.         // Remove the EH and close the dialog
  102.         _respawnButton ctrlRemoveEventHandler ["ButtonClick", _NUP_respawnEH];
  103.         closeDialog 0;
  104.  
  105.     }];
  106.  
  107.     // Add revive action to the dead body
  108.     _oldUnit addAction [
  109.         "Revive Player",    // title
  110.         {
  111.             params ["_target", "_caller", "_actionId", "_arguments"]; // script                
  112.             _arguments params ["_camera", "_oldUnit", "_newUnit"];
  113.             [_target, _caller, _camera, _oldUnit, _newUnit] call NUP_fnc_revivePlayer;
  114.  
  115.         },
  116.         _arguments,     // arguments
  117.         1.5,        // priority
  118.         true,       // showWindow
  119.         true,       // hideOnUse
  120.         "",         // shortcut
  121.         "side _this == side _target",       // condition
  122.         2,          // radius
  123.         false,      // unconscious
  124.         "",         // selection
  125.         ""          // memoryPoint
  126.     ];
  127.  
  128.     // Set the safezone delay back to false so respawning players at HQ are protected immediately.
  129.     _newUnit setVariable ["NUP_safezoneDelay", false];
  130.     _newUnit setVariable ["NUP_disableCommandChat", true];
  131.     _newUnit setVariable ["vehicle", 0];
  132.     [] call NUP_fnc_playerMarkers;
  133.    
  134.     // Apply the saved loadout if it exists
  135.     private _savedLoadout = _newUnit getVariable ["NUP_savedLoadout", nil];
  136.  
  137.     if (!isNil "_savedLoadout") then {
  138.         _newUnit setUnitLoadout _savedLoadout;
  139.     };
  140.  
  141.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement