Advertisement
Guest User

Untitled

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