Advertisement
RamireDu06

Untitled

Oct 2nd, 2020
2,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.94 KB | None | 0 0
  1. _logic = _this param [0,objnull,[objnull]];
  2. _activated = _this param [2,true,[true]];
  3.  
  4. if (_activated) then {
  5.  
  6.     //--- Draw respan positions for players
  7.     true call bis_fnc_drawRespawnPositions;
  8.     if !(isserver) exitwith {};
  9.  
  10.     //--- Server init
  11.     _typeID = 0;
  12.     _sideID = 0;
  13.  
  14.     _name = _logic getvariable ["Name",""];
  15.     if (isnumber (configfile >> "cfgvehicles" >> typeof _logic >> "respawnSide")) then {
  16.         //--- Module with pre-define params
  17.         _sideID = getnumber (configfile >> "cfgvehicles" >> typeof _logic >> "respawnSide");
  18.         _typeID = getnumber (configfile >> "cfgvehicles" >> typeof _logic >> "respawnType");
  19.     } else {
  20.         //--- Module with adjustable params
  21.         _typeID = (_logic getvariable ["Type","0"]) call BIS_fnc_parseNumberSafe;
  22.         _sideID = (_logic getvariable ["Side","-1"]) call BIS_fnc_parseNumberSafe;
  23.     };
  24.     _showNotification = (_logic getvariable ["ShowNotification","1"]) call BIS_fnc_parseNumberSafe;
  25.  
  26.     //--- Detect the leading side
  27.     if (_sideID < 0) then {
  28.         if (ismultiplayer) then {
  29.             _maxScore = -1;
  30.             {
  31.                 _score = scoreside _x;
  32.                 if (_score > _maxScore) then {
  33.                     _maxScore = _score;
  34.                     _sideID = _x call bis_fnc_sideID;
  35.                 } else {
  36.                     if (_score == _maxScore) then {
  37.                         _sideID = -1;
  38.                     };
  39.                 };
  40.             } foreach [opfor,blufor,independent,civilian];
  41.         } else {
  42.             _sideID = (player call bis_fnc_objectSide) call bis_fnc_sideID;
  43.         };
  44.     };
  45.  
  46.     if (_sideID in [0,1,2,3]) then {
  47.         private ["_side","_pos","_markerPrefix","_markerType","_respawnPositions","_respawnObjects","_type","_respawn"];
  48.         _side = _sideID call bis_fnc_sideType;
  49.         _pos = position _logic;
  50.         _markerType = ["respawn_inf","respawn_unknown","respawn_motor","respawn_armor","respawn_air","respawn_plane","respawn_naval"] select _typeID;
  51.         _respawnPositions = [];
  52.         _respawnObjects = [];
  53.  
  54.         if (_typeID > 0) then {
  55.             private ["_markerSide"];
  56.             _markerSide = ["east","west","guerrila","civilian"] select _sideID;
  57.             _respawn = "respawn_vehicle_" + _markerSide + str _pos;
  58.             createmarker [_respawn,_pos];
  59.             _respawn setmarkerdir ((round direction _logic) * 360);
  60.             _respawn setmarkersize [1,1];
  61.             _respawn setmarkercolor ([_side,true] call bis_fnc_sidecolor);
  62.             _respawn setmarkertype _markerType;
  63.             _logic setvariable ["marker",_respawn];
  64.             //_respawn setmarkertext (_name call bis_fnc_localize);
  65.             _respawnPositions pushback _respawn;
  66.             _respawnObjects pushback objnull;
  67.         } else {
  68.             //--- Respawn in vehicle
  69.             {
  70.                 if (_x iskindof "AllVehicles") then {
  71.                     _respawn = [_side,_x,_name] call bis_fnc_addRespawnPosition;
  72.                     _respawnPositions pushback _respawn;
  73.                     _respawnObjects pushback _x;
  74.                 };
  75.             } foreach (synchronizedobjects _logic);
  76.  
  77.             //--- Respawn on position (when no vehicles are synced)
  78.             if (count _respawnPositions == 0) then {
  79.                 _respawn = [_side,_logic,_name] call bis_fnc_addRespawnPosition;
  80.                 _respawnPositions pushback _respawn;
  81.                 _respawnObjects pushback objnull;
  82.             };
  83.         };
  84.         _logic setvariable ["respawn",_respawnPositions];
  85.  
  86.         //--- Show notifications
  87.         _type = gettext (configfile >> "cfgmarkers" >> _markerType >> "name");
  88.         {
  89.             if (_name == "") then {
  90.                 private ["_namePos"];
  91.                 _name = "";
  92.                 _namePos = [0,0,0];
  93.                 _veh = _respawnObjects select _foreachindex;
  94.                 if (!isnull _veh) then {
  95.                     _name = gettext (configfile >> "cfgvehicles" >> (typeof _veh) >> "displayname");
  96.                     _namePos = position _veh;
  97.                 } else {
  98.                     _name = format [localize "str_a3_bis_fnc_respawnmenuposition_grid",mapgridposition _pos];
  99.                     _namePos = _pos;
  100.                 };
  101.                 _name = _name + " - " + (_namePos call bis_fnc_locationdescription);
  102.             } else {
  103.                 _name = _name call bis_fnc_localize;
  104.             };
  105.  
  106.             if (_showNotification > 0) then
  107.             {
  108.                 [["RespawnAdded",[_type,_name,_markerType call bis_fnc_textureMarker]],"BIS_fnc_showNotification",_side] call bis_fnc_mp;
  109.             };
  110.         } foreach _respawnPositions;
  111.  
  112.         //--- Update markers and actual module positions
  113.         _list = missionnamespace getvariable ["BIS_fnc_moduleRespawnPosition_list",[]];
  114.         _list pushback _logic;
  115.         missionnamespace setvariable ["BIS_fnc_moduleRespawnPosition_list",_list];
  116.         if (isnil "BIS_fnc_moduleRespawnPosition_loop") then {
  117.             BIS_fnc_moduleRespawnPosition_loop = [] spawn {
  118.                 scriptname "bis_fnc_moduleRespawnPosition: Loop";
  119.                 _listMarkers = [];
  120.                 waituntil {
  121.                     _list = missionnamespace getvariable ["BIS_fnc_moduleRespawnPosition_list",[]];
  122.                     _refresh = false;
  123.                     {
  124.                         if !(isnull _x) then {
  125.                             //--- Update position
  126.                             _pos = _x getvariable ["BIS_fnc_position_forced",[0,0,0]];
  127.                             if (position _x distance _pos > 0) then {
  128.                                 _pos = position _x;
  129.                                 _x setvariable ["BIS_fnc_position_forced",_pos,true]; //--- Force rewire for BIS_fnc_position
  130.  
  131.                                 _marker = _x getvariable ["marker",""];
  132.                                 if (_marker != "") then {
  133.                                     _marker setmarkerpos _pos;
  134.                                     if !(_marker in _listMarkers) then {_listMarkers pushback _marker;};
  135.                                 };
  136.                             };
  137.                         } else {
  138.                             _refresh = true;
  139.                         };
  140.                         sleep 0.1;
  141.                     } foreach _list;
  142.                     if (_refresh) then {
  143.                         //--- Remove deleted modules from the list
  144.                         _list = _list - [objnull];
  145.                         missionnamespace setvariable ["BIS_fnc_moduleRespawnPosition_list",_list];
  146.  
  147.                         //--- Remove markers of deleted modules
  148.                         _listMarkersDelete = +_listMarkers;
  149.                         {
  150.                             _listMarkersDelete = _listMarkersDelete - [_x getvariable ["marker",""]];
  151.                         } foreach _list;
  152.                         {deletemarker _x;} foreach _listMarkersDelete;
  153.                     };
  154.                     count _list == 0
  155.                 };
  156.                 BIS_fnc_moduleRespawnPosition_loop = nil;
  157.             };
  158.         };
  159.     } else {
  160.         ["Respawn %1 not added, all sides have the same score.",_logic] call bis_fnc_logFormat;
  161.     };
  162. } else {
  163.  
  164.     //--- Remove
  165.     _respawnPositions = _logic getvariable ["respawn",[]];
  166.     {
  167.         if (typename _x == typename []) then {
  168.             _x call bis_fnc_removeRespawnPosition;
  169.         } else {
  170.             deletemarker _x;
  171.         };
  172.     } foreach _respawnPositions;
  173.     _logic setvariable ["respawn",nil];
  174. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement