Guest User

Untitled

a guest
May 9th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.80 KB | None | 0 0
  1. #include "script_macros.hpp"
  2. /*
  3. File: init.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Edit: Nanou for HeadlessClient optimization.
  7. Please read support for more informations.
  8.  
  9. Description:
  10. Initialize the server and required systems.
  11. */
  12. tf_radio_channel_name = "Task Force Radio";
  13. tf_radio_channel_password = "9513";
  14.  
  15. publicVariable "tf_radio_channel_name";
  16. publicVariable "tf_radio_channel_password";
  17.  
  18. private ["_dome","_rsb","_timeStamp","_extDBNotLoaded"];
  19. DB_Async_Active = false;
  20. DB_Async_ExtraLock = false;
  21. life_server_isReady = false;
  22. _extDBNotLoaded = "";
  23. serv_sv_use = [];
  24. publicVariable "life_server_isReady";
  25. life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
  26. fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
  27.  
  28. /*
  29. Prepare the headless client.
  30. */
  31. life_HC_isActive = false;
  32. publicVariable "life_HC_isActive";
  33. HC_Life = false;
  34. publicVariable "HC_Life";
  35.  
  36. if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
  37. [] execVM "\life_server\initHC.sqf";
  38. };
  39.  
  40. /*
  41. Prepare extDB before starting the initialization process
  42. for the server.
  43. */
  44.  
  45. if (isNil {uiNamespace getVariable "life_sql_id"}) then {
  46. life_sql_id = round(random(9999));
  47. CONSTVAR(life_sql_id);
  48. uiNamespace setVariable ["life_sql_id",life_sql_id];
  49. try {
  50. _result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
  51. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  52. _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  53. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  54. } catch {
  55. diag_log _exception;
  56. _extDBNotLoaded = [true, _exception];
  57. };
  58. if (_extDBNotLoaded isEqualType []) exitWith {};
  59. EXTDB "9:LOCK";
  60. diag_log "extDB3: Connected to Database";
  61. } else {
  62. life_sql_id = uiNamespace getVariable "life_sql_id";
  63. CONSTVAR(life_sql_id);
  64. diag_log "extDB3: Still Connected to Database";
  65. };
  66.  
  67.  
  68. if (_extDBNotLoaded isEqualType []) exitWith {
  69. life_server_extDB_notLoaded = true;
  70. publicVariable "life_server_extDB_notLoaded";
  71. };
  72. life_server_extDB_notLoaded = false;
  73. publicVariable "life_server_extDB_notLoaded";
  74.  
  75. /* Run stored procedures for SQL side cleanup */
  76. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  77. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  78. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  79. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  80.  
  81. _timeStamp = diag_tickTime;
  82. diag_log "----------------------------------------------------------------------------------------------------";
  83. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  84. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  85. diag_log "----------------------------------------------------------------------------------------------------";
  86.  
  87. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  88. [] spawn {
  89. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  90. [_query,1] call DB_fnc_asyncCall;
  91. };
  92. };
  93.  
  94. /* Map-based server side initialization. */
  95. master_group attachTo[bank_obj,[0,0,0]];
  96.  
  97. {
  98. _hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
  99. _hs setDir (markerDir _x);
  100. _hs setPosATL (getMarkerPos _x);
  101. _var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
  102. _var attachTo [_hs, [4.69775,32.6045,-0.1125]];
  103. detach _var;
  104. _var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
  105. _var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
  106. detach _var;
  107. if (worldName isEqualTo "Tanoa") then {
  108. if (_forEachIndex isEqualTo 0) then {
  109. atm_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  110. vendor_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  111. "medic_spawn_3" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  112. "med_car_2" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  113. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  114. } else {
  115. atm_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  116. vendor_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  117. "medic_spawn_1" setMarkerPos (_var modelToWorld [-1.85181,-6.07715,-8.24944]);
  118. "med_car_1" setMarkerPos (_var modelToWorld [5.9624,11.8799,-8.28493]);
  119. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  120. };
  121. };
  122. } forEach ["hospital_2","hospital_3"];
  123.  
  124. {
  125. if (!isPlayer _x) then {
  126. _npc = _x;
  127. {
  128. if (_x != "") then {
  129. _npc removeWeapon _x;
  130. };
  131. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  132. };
  133. } forEach allUnits;
  134.  
  135. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  136.  
  137. life_adminLevel = 0;
  138. life_medicLevel = 0;
  139. life_copLevel = 0;
  140. CONST(JxMxE_PublishVehicle,"false");
  141.  
  142. /* Setup radio channels for west/independent/civilian */
  143. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  144. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  145. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  146.  
  147. /* Set the amount of gold in the federal reserve at mission start */
  148. fed_bank setVariable ["safe",count playableUnits,true];
  149. [] spawn TON_fnc_federalUpdate;
  150.  
  151. /* Event handler for disconnecting players */
  152. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  153. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  154.  
  155. /* Set OwnerID players for Headless Client */
  156. TON_fnc_requestClientID =
  157. {
  158. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  159. };
  160. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  161.  
  162. /* Event handler for logs */
  163. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  164. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  165.  
  166. /* Miscellaneous mission-required stuff */
  167. life_wanted_list = [];
  168.  
  169. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  170.  
  171. [] spawn {
  172. for "_i" from 0 to 1 step 0 do {
  173. uiSleep (30 * 60);
  174. {
  175. _x setVariable ["sellers",[],true];
  176. } forEach [Dealer_1,Dealer_2,Dealer_3];
  177. };
  178. };
  179.  
  180. [] spawn TON_fnc_initHouses;
  181. cleanup = [] spawn TON_fnc_cleanup;
  182.  
  183. TON_fnc_playtime_values = [];
  184. TON_fnc_playtime_values_request = [];
  185.  
  186. //Just incase the Headless Client connects before anyone else
  187. publicVariable "TON_fnc_playtime_values";
  188. publicVariable "TON_fnc_playtime_values_request";
  189.  
  190.  
  191. /* Setup the federal reserve building(s) */
  192. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  193. private _altisArray = [16019.5,16952.9,0];
  194. private _tanoaArray = [11074.2,11501.5,0.00137329];
  195. private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort;
  196.  
  197. _dome = nearestObject [_pos,"Land_Dome_Big_F"];
  198. _rsb = nearestObject [_pos,_vaultHouse];
  199.  
  200. for "_i" from 1 to 3 do {_dome setVariable [format ["bis_disabled_Door_%1",_i],1,true]; _dome animateSource [format ["Door_%1_source", _i], 0];};
  201. _dome setVariable ["locked",true,true];
  202. _rsb setVariable ["locked",true,true];
  203. _rsb setVariable ["bis_disabled_Door_1",1,true];
  204. _dome allowDamage false;
  205. _rsb allowDamage false;
  206.  
  207. /* Tell clients that the server is ready and is accepting queries */
  208. life_server_isReady = true;
  209. publicVariable "life_server_isReady";
  210.  
  211. /* Initialize hunting zone(s) */
  212. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  213.  
  214. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  215. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  216. life_attachment_point setPosASL [0,0,0];
  217. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  218.  
  219. // Sharing the point of attachment with all players.
  220. publicVariable "life_attachment_point";
  221.  
  222. diag_log "----------------------------------------------------------------------------------------------------";
  223. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  224. diag_log "----------------------------------------------------------------------------------------------------";
Add Comment
Please, Sign In to add comment