Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 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. private ["_dome","_rsb","_timeStamp","_extDBNotLoaded"];
  13. DB_Async_Active = false;
  14. DB_Async_ExtraLock = false;
  15. life_server_isReady = false;
  16. _extDBNotLoaded = "";
  17. serv_sv_use = [];
  18. publicVariable "life_server_isReady";
  19. life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
  20. fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
  21.  
  22. /*
  23. Prepare the headless client.
  24. */
  25. life_HC_isActive = false;
  26. publicVariable "life_HC_isActive";
  27. HC_Life = false;
  28. publicVariable "HC_Life";
  29.  
  30. if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
  31. [] execVM "\life_server\initHC.sqf";
  32. };
  33.  
  34. /*
  35. Prepare extDB before starting the initialization process
  36. for the server.
  37. */
  38.  
  39. if (isNil {uiNamespace getVariable "life_sql_id"}) then {
  40. life_sql_id = round(random(9999));
  41. CONSTVAR(life_sql_id);
  42. uiNamespace setVariable ["life_sql_id",life_sql_id];
  43. try {
  44. _result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
  45. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  46. _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  47. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  48. } catch {
  49. diag_log _exception;
  50. _extDBNotLoaded = [true, _exception];
  51. };
  52. if (_extDBNotLoaded isEqualType []) exitWith {};
  53. EXTDB "9:LOCK";
  54. diag_log "extDB3: Connected to Database";
  55. } else {
  56. life_sql_id = uiNamespace getVariable "life_sql_id";
  57. CONSTVAR(life_sql_id);
  58. diag_log "extDB3: Still Connected to Database";
  59. };
  60.  
  61.  
  62. if (_extDBNotLoaded isEqualType []) exitWith {
  63. life_server_extDB_notLoaded = true;
  64. publicVariable "life_server_extDB_notLoaded";
  65. };
  66. life_server_extDB_notLoaded = false;
  67. publicVariable "life_server_extDB_notLoaded";
  68.  
  69. /* Run stored procedures for SQL side cleanup */
  70. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  71. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  72. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  73. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  74.  
  75. _timeStamp = diag_tickTime;
  76. diag_log "----------------------------------------------------------------------------------------------------";
  77. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  78. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  79. diag_log "----------------------------------------------------------------------------------------------------";
  80.  
  81. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  82. [] spawn {
  83. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  84. [_query,1] call DB_fnc_asyncCall;
  85. };
  86. };
  87.  
  88. /* Map-based server side initialization. */
  89. master_group attachTo[bank_obj,[0,0,0]];
  90. {
  91. if (!isPlayer _x) then {
  92. _npc = _x;
  93. {
  94. if (_x != "") then {
  95. _npc removeWeapon _x;
  96. };
  97. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  98. };
  99. } forEach allUnits;
  100.  
  101. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  102.  
  103. life_adminLevel = 0;
  104. life_medicLevel = 0;
  105. life_copLevel = 0;
  106. CONST(JxMxE_PublishVehicle,"false");
  107.  
  108. /* Setup radio channels for west/independent/civilian */
  109. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  110. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  111. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  112.  
  113. /* Set the amount of gold in the federal reserve at mission start */
  114. fed_bank setVariable ["safe",count playableUnits,true];
  115. [] spawn TON_fnc_federalUpdate;
  116.  
  117. /* Event handler for disconnecting players */
  118. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  119. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  120.  
  121. /* Set OwnerID players for Headless Client */
  122. TON_fnc_requestClientID =
  123. {
  124. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  125. };
  126. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  127.  
  128. /* Event handler for logs */
  129. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  130. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  131.  
  132. /* Miscellaneous mission-required stuff */
  133. life_wanted_list = [];
  134.  
  135. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  136.  
  137. [] spawn {
  138. for "_i" from 0 to 1 step 0 do {
  139. uiSleep (30 * 60);
  140. {
  141. _x setVariable ["sellers",[],true];
  142. } forEach [Dealer_1,Dealer_2];
  143. };
  144. };
  145.  
  146. [] spawn TON_fnc_initHouses;
  147. cleanup = [] spawn TON_fnc_cleanup;
  148.  
  149. TON_fnc_playtime_values = [];
  150. TON_fnc_playtime_values_request = [];
  151.  
  152. //Just incase the Headless Client connects before anyone else
  153. publicVariable "TON_fnc_playtime_values";
  154. publicVariable "TON_fnc_playtime_values_request";
  155.  
  156.  
  157. /* Setup the federal reserve building(s) */
  158. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  159. private _altisArray = [16019.5,16952.9,0];
  160. private _tanoaArray = [11074.2,11501.5,0.00137329];
  161. private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort;
  162.  
  163. _dome = nearestObject [_pos,"Land_Dome_Big_F"];
  164. _rsb = nearestObject [_pos,_vaultHouse];
  165.  
  166. 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];};
  167. _dome setVariable ["locked",true,true];
  168. _rsb setVariable ["locked",true,true];
  169. _rsb setVariable ["bis_disabled_Door_1",1,true];
  170. _dome allowDamage false;
  171. _rsb allowDamage false;
  172.  
  173. /* Tell clients that the server is ready and is accepting queries */
  174. life_server_isReady = true;
  175. publicVariable "life_server_isReady";
  176.  
  177. /* Initialize hunting zone(s) */
  178. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  179.  
  180. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  181. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  182. life_attachment_point setPosASL [0,0,0];
  183. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  184.  
  185. // Sharing the point of attachment with all players.
  186. publicVariable "life_attachment_point";
  187.  
  188. //setting up bank
  189. life_bank_beingRobbed = 0;
  190. publicVariable "life_bank_beingRobbed";
  191. _pos = getMarkerPos "bank";
  192. _bank = nearestObject [_pos,"Land_CommonwealthBank"];
  193. _bank animate ["Vault_Door",0];
  194. _obj = nearestObjects[bank,["Land_Money_F"],30];
  195. {_x hideObjectGlobal false;}foreach _obj;
  196.  
  197. life_bank_caches = [];
  198. _bank_cache = 8;
  199. _counter = 1;
  200. while {_counter <= _bank_cache} do {
  201. life_bank_caches pushBack 0;
  202. _counter = _counter + 1;
  203. };
  204. life_lastRobbed = 0;
  205. life_bank_caches_orig = life_bank_caches;
  206. publicVariable "life_lastRobbed";
  207. publicVariable "life_bank_caches";
  208. publicVariable "life_bank_caches_orig";
  209.  
  210.  
  211.  
  212. diag_log "----------------------------------------------------------------------------------------------------";
  213. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  214. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement