Guest User

Untitled

a guest
Oct 16th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.49 KB | None | 0 0
  1. private ["_date","_year","_month","_day","_hour","_minute","_date1","_hiveResponse","_key","_objectCount","_dir","_point","_i","_action","_dam","_selection","_wantExplosiveParts","_entity","_worldspace","_damage","_booleans","_rawData","_ObjectID","_class","_CharacterID","_inventory","_hitpoints","_fuel","_id","_objectArray","_script","_result","_outcome"];
  2. []execVM "\z\addons\dayz_server\system\s_fps.sqf"; //server monitor FPS (writes each ~181s diag_fps+181s diag_fpsmin*)
  3. []execVM "\z\addons\dayz_server\system\instaaction.sqf";
  4. #include "\z\addons\dayz_server\compile\server_toggle_debug.hpp"
  5.  
  6.  
  7. dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  8. dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  9. _script = getText(missionConfigFile >> "onPauseScript");
  10.  
  11. if ((count playableUnits == 0) and !isDedicated) then {
  12. isSinglePlayer = true;
  13. };
  14.  
  15. waitUntil{initialized}; //means all the functions are now defined
  16. // ### BASE BUILDING 1.2 ### SERVER SIDE BUILD ARRAYS - START
  17. call build_baseBuilding_arrays;
  18. // ### BASE BUILDING 1.2 ### SERVER SIDE BUILD ARRAYS - END
  19.  
  20. diag_log "HIVE: Starting";
  21.  
  22. //Set the Time
  23. //Send request
  24. _key = "CHILD:307:";
  25. _result = _key call server_hiveReadWrite;
  26. _outcome = _result select 0;
  27. if(_outcome == "PASS") then {
  28. _date = _result select 1;
  29.  
  30. //date setup
  31. _year = _date select 0;
  32. _month = _date select 1;
  33. _day = _date select 2;
  34. _hour = _date select 3;
  35. _minute = _date select 4;
  36.  
  37. //Force full moon nights
  38. _date1 = [2013,8,3,_hour,_minute];
  39.  
  40. if(isDedicated) then {
  41. //["dayzSetDate",_date] call broadcastRpcCallAll;
  42. setDate _date1;
  43. dayzSetDate = _date1;
  44. dayz_storeTimeDate = _date1;
  45. publicVariable "dayzSetDate";
  46. };
  47. diag_log ("HIVE: Local Time set to " + str(_date1));
  48. };
  49.  
  50. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  51.  
  52. #include "\z\addons\dayz_server\compile\fa_hiveMaintenance.hpp"
  53.  
  54. if (isServer and isNil "sm_done") then {
  55. private ["_key","_data","_result","_status","_buildingArray","_bldCount","_val","_countr","_idKey","_type","_ownerID","_worldspace","_dir","_wsDone","_inventory","_hitPoints","_squadID","_combination","_damage","_object","_classname","_i","_requirements","_isDestructable","_objWpnTypes","_objWpnQty","_isOK","_block","_hiveResponse","_objectArray","_objectCount"];
  56.  
  57.  
  58. //Send the key
  59. _key = format["CHILD:999:select b.class_name, ib.worldspace from instance_building ib join building b on ib.building_id = b.id where ib.instance_id = ?:[%1]:", dayZ_instance];
  60. _data = "HiveEXT" callExtension _key;
  61.  
  62. diag_log("SERVER: Fetching buildings for instance " + str(dayZ_instance));
  63.  
  64. //Process result
  65. _result = call compile format ["%1", _data];
  66. _status = _result select 0;
  67.  
  68. _bldList = [];
  69. _bldCount = 0;
  70. if (_status == "CustomStreamStart") then {
  71. _val = _result select 1;
  72. for "_i" from 1 to _val do {
  73. _data = "HiveEXT" callExtension _key;
  74. _result = call compile format ["%1",_data];
  75.  
  76. _pos = call compile (_result select 1);
  77. _dir = _pos select 0;
  78. _pos = _pos select 1;
  79.  
  80. _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
  81. _building setDir _dir;
  82. _bldCount = _bldCount + 1;
  83. };
  84. diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
  85. };
  86.  
  87.  
  88. for "_i" from 1 to 5 do {
  89. diag_log "HIVE: trying to get objects";
  90. _key = format["CHILD:302:%1:", dayZ_instance];
  91. _hiveResponse = _key call server_hiveReadWrite;
  92. if ((((isnil "_hiveResponse") || {(typeName _hiveResponse != "ARRAY")}) || {((typeName (_hiveResponse select 1)) != "SCALAR")}) || {(_hiveResponse select 1 > 2000)}) then {
  93. if (!isNil "_hiveResponse") then {
  94. diag_log ("HIVE: connection problem... HiveExt response:"+str(_hiveResponse));
  95. } else {
  96. diag_log ("HIVE: connection problem... HiveExt NIL response:");
  97. };
  98. _hiveResponse = ["",0];
  99. } else {
  100. diag_log ("HIVE: found "+str(_hiveResponse select 1)+" objects" );
  101. _i = 99; // break
  102. };
  103. };
  104.  
  105. _objectArray = [];
  106. if ((_hiveResponse select 0) == "ObjectStreamStart") then {
  107. _objectCount = _hiveResponse select 1;
  108. diag_log ("HIVE: Commence Object Streaming...");
  109. for "_i" from 1 to _objectCount do {
  110. _hiveResponse = _key call server_hiveReadWrite;
  111. _objectArray set [_i - 1, _hiveResponse];
  112. //diag_log (format["HIVE dbg %1 %2", typeName _hiveResponse, _hiveResponse]);
  113. };
  114. diag_log ("HIVE: got " + str(count _objectArray) + " objects");
  115. #ifdef EMPTY_TENTS_CHECK
  116. // check empty tents, remove some of them
  117. [_objectArray, EMPTY_TENTS_GLOBAL_LIMIT, EMPTY_TENTS_USER_LIMIT] call fa_removeExtraTents;
  118. #endif
  119. // check vehicles count
  120. [_objectArray] call fa_checkVehicles;
  121. };
  122.  
  123. {
  124.  
  125. _action = _x select 0; // values : "OBJ"=object got from hive "CREATED"=vehicle just created ...
  126. _ObjectID = _x select 1;
  127. _class = if ((typeName (_x select 2)) == "STRING") then { _x select 2 } else { "Old_bike_TK_CIV_EP1" };
  128. _CharacterID = _x select 3;
  129. _worldspace = if ((typeName (_x select 4)) == "ARRAY") then { _x select 4 } else { [] };
  130. _inventory= if ((typeName (_x select 5)) == "ARRAY") then { _x select 5 } else { [] };
  131. _hitpoints= if ((typeName (_x select 6)) == "ARRAY") then { _x select 6 } else { [] };
  132. _fuel = if ((typeName (_x select 7)) == "SCALAR") then { _x select 7 } else { 0 };
  133. _damage = if ((typeName (_x select 8)) == "SCALAR") then { _x select 8 } else { 0.9 };
  134. _entity = nil;
  135.  
  136. _dir = floor(random(360));
  137. _point = getMarkerpos "respawn_west";
  138. if (count _worldspace >= 1 && {(typeName (_worldspace select 0)) == "SCALAR"}) then {
  139. _dir = _worldspace select 0;
  140. };
  141. if (count _worldspace == 2 && {(typeName (_worldspace select 1)) == "ARRAY"}) then {
  142. _i = _worldspace select 1;
  143. if (count _i == 3 &&
  144. {(typeName (_i select 0)) == "SCALAR"} &&
  145. {(typeName (_i select 1)) == "SCALAR"} &&
  146. {(typeName (_i select 2)) == "SCALAR"}) then {
  147. _point = _i;
  148. };
  149. };
  150.  
  151. // if legit vehicle
  152. if ((_class isKindOf "AllVehicles") && ((_CharacterID == "0") OR (_CharacterID == "1")) && (_damage < 1)) then {
  153. //_damage=0.86;//_action="CREATED";
  154. _point set [2, 0]; // here _point is in ATL format
  155. // check for no collision with world. Find a suitable place (depending of defined parameters)
  156. _worldspace = [_class, _dir, _point, _action] call fa_smartlocation;
  157. if (count _worldspace < 2) then { // safe position NOT found
  158. _action = "FAILED"; // don't worry, maybe we will find a nice spot next time :)
  159. }
  160. else { // found a spot for respawn
  161. if ((([_worldspace select 1, _point] call BIS_fnc_distance2D) > 1)
  162. AND (_action == "OBJ")) then { _action = "MOVED"; };
  163. _dir = _worldspace select 0;
  164. _point = _worldspace select 1;
  165. _entity = createVehicle [_class, _point, [], 0,
  166. if ((_class isKindOf "Air") OR {(_action != "OBJ")}) then {"NONE"} else {"CAN_COLLIDE"}
  167. ];
  168. _entity setVariable ["ObjectID", _ObjectID, true]; // this variable must be set very early
  169. _entity setVariable ["CharacterID", _CharacterID, true];
  170. _entity setVariable ["lastUpdate",time]; // prevent immediate hive write when vehicle parts are set up
  171. // setPos will be done again just after setDir, see below....
  172. _entity setDamage _damage;
  173. {
  174. _wantExplosiveParts = _x;
  175. {
  176. _selection = _x select 0;
  177. _dam = _x select 1;
  178. if (_selection in dayZ_explosiveParts) then {
  179. if (_wantExplosiveParts) then {
  180. if (_dam > 0.8) then { _dam = 0.8; };
  181. [_entity, _selection, _dam] call fnc_veh_handleDam;
  182. };
  183. }
  184. else {
  185. if (!_wantExplosiveParts) then {
  186. [_entity, _selection, _dam] call fnc_veh_handleDam;
  187. };
  188. };
  189. } forEach _hitpoints;
  190. } forEach [false, true]; // we set non explosive part first, then explosive parts
  191. _entity setvelocity [0,0,1];
  192. _entity setFuel _fuel;
  193. _entity call fnc_veh_ResetEH;
  194. };
  195. #ifdef OBJECT_DEBUG
  196. diag_log (format["VEHICLE %1 %2 at %3, original damage=%4, effective damage=%6, fuel=%5",
  197. _action, _entity call fa_veh2str, (getPosASL _entity) call fa_coor2str, _damage, _fuel, damage _entity]); // , hitpoints:%6, inventory=%7" , _hitpoints, _inventory
  198. #endif
  199. }
  200. else { // else for object or non legit vehicle
  201. if (!(_class in SafeObjects )) then {
  202. _damage = 1;
  203. };
  204. if (_damage < 1) then {
  205. // Rule #1: Tents will be always spawned if non empty.
  206. // Rule #2: Objects are not spawned if inside/close to building.
  207. // Rule #3: Rule #1 is higher priority
  208. _booleans=[];
  209. _worldspace = [_class, _point, _booleans] call fn_niceSpot;
  210. if (_booleans select 3) then { // is in building
  211. if ((_class != "TentStorage") OR {(_inventory call fa_tentEmpty)}) then {
  212. _action = "FAILED";
  213. _damage = 5;
  214. #ifdef OBJECT_DEBUG
  215. diag_log(format["Won't spawn object #%1(%4) in/close to a building, _point:%3, inventory: %5 booleans:%2",_ObjectID, _booleans, _point, _class, _inventory]);
  216. #endif
  217. };
  218. };
  219. };
  220. if (_damage < 1) then { // create object
  221. diag_log("Spawned: " + str(_ObjectID) + " " + _class);
  222.  
  223. // for tents: non colliding position
  224. _entity = createVehicle [_class, _point, [], 0,
  225. if (_class=="TentStorage") then {"NONE"} else {"CAN_COLLIDE"}
  226. ];
  227. _entity setVariable ["lastUpdate",time];
  228. // Don't set objects for deployables to ensure proper inventory updates
  229. if (_CharacterID == "0") then {
  230. _entity setVariable ["ObjectID", str(_ObjectID), true];
  231. } else {
  232. _entity setVariable ["ObjectUID", str(_ObjectID), true];
  233. };
  234. _entity setVariable ["CharacterID", _CharacterID, true];
  235.  
  236. if (_class == "TentStorage" || _class == "CamoNet_DZ") then {
  237. _entity addMPEventHandler ["MPKilled",{_this call vehicle_handleServerKilled;}];
  238. };
  239.  
  240. _entity setDamage _damage;
  241. //diag_log ("DW_DEBUG " + _class + " #" + str(_ObjectID) + " pos=" + (_point call fa_coor2str) + ", damage=" + str(_damage) );
  242. // ##### BASE BUILDING 1.2 Server Side ##### - START
  243. // This sets objects to appear properly once server restarts
  244. //_object setVariable ["ObjectUID", _worldspace call dayz_objectUID2, true]; // Optional (REMOVE // lines before _object) May fix DayZ.ST issues, or issues related to Panel codes not working thanks nullpo
  245. if ((_class == "Static") && !(_class == "TentStorage")) then {
  246. _entity setpos [(getposATL _entity select 0),(getposATL _entity select 1), 0];
  247. };
  248. //Set Variable
  249. if ((_class == "Infostand_2_EP1") && !(_class == "Infostand_1_EP1")) then {
  250. _entity setVariable ["ObjectUID", _ObjectID, true];
  251. };
  252.  
  253.  
  254. // Set whether or not buildable is destructable
  255. if (typeOf(_entity) in allbuildables_class) then {
  256. diag_log ("SERVER: in allbuildables_class:" + typeOf(_entity) + " !");
  257. for "_i" from 0 to ((count allbuildables) - 1) do
  258. {
  259. _classname = (allbuildables select _i) select _i - _i + 1;
  260. _result = [_classname,typeOf(_entity)] call BIS_fnc_areEqual;
  261. if (_result) then {
  262. _requirements = (allbuildables select _i) select _i - _i + 2;
  263.  
  264. _isDestructable = _requirements select 13;
  265. diag_log ("SERVER: " + typeOf(_entity) + " _isDestructable = " + str(_isDestructable));
  266. if (!_isDestructable) then {
  267. diag_log("Spawned: " + typeOf(_entity) + " Handle Damage False");
  268. _entity addEventHandler ["HandleDamage", {false}];
  269. };
  270. };
  271. };
  272. //gateKeypad = _entity addaction ["Defuse", "\z\addons\dayz_server\compile\enterCode.sqf"];
  273. };
  274. // This sets objects to appear properly once server restarts
  275. // ##### BASE BUILDING 1.2 Server Side ##### - END
  276. }
  277. else { // delete object -- this has been comented out: object are never really deleted from hive
  278. /* _key = format["CHILD:306:%1:%2:%3:", _ObjectID, [], 1];
  279. _rawData = "HiveEXT" callExtension _key;
  280. _key = format["CHILD:304:%1:",_ObjectID]; // delete by ID (not UID which is handler 310)
  281. _rawData = "HiveEXT" callExtension _key;*/
  282. #ifdef OBJECT_DEBUG
  283. diag_log (format["IGNORED %1 oid#%2 cid:%3 ",
  284. _class, _ObjectID, _CharacterID ]);
  285. #endif
  286. };
  287. };
  288. //diag_log(format["VEH MAINTENANCE DEBUG %1 %2", __FILE__, __LINE__]);
  289.  
  290. // common code (vehicle or not)
  291. if (_damage < 1 AND !(isNil ("_entity"))) then {
  292. _entity setdir _dir;
  293. _entity setPos _point;
  294.  
  295. if (_entity isKindOf "TrapItems") then {
  296. _entity setVariable ["armed", _inventory select 0, false];
  297. } else {
  298. [_entity, _inventory] call fa_populateCargo;
  299. };
  300.  
  301. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _entity];
  302.  
  303. // UPDATE MODIFIED OBJECTS TO THE HIVE
  304. if (_action == "CREATED") then {
  305. // insert className damage characterId worldSpace inventory hitPoints fuel uniqueId
  306. _key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:", dayZ_instance,
  307. _class, _damage , 1,
  308. [_dir, _point],
  309. [getWeaponCargo _entity, getMagazineCargo _entity ,getBackpackCargo _entity],
  310. _hitpoints, _fuel, _ObjectID
  311. ];
  312. //diag_log (_key);
  313. _rawData = "HiveEXT" callExtension _key;
  314. };
  315. if (_action == "SPAWNED" || _action == "DAMAGED") then {
  316. // update hitpoint,damage -- already done by needupdate
  317. /*_key = format["CHILD:306:%1:%2:%3:", _ObjectID, _hitpoints, _damage];
  318. _rawData = "HiveEXT" callExtension _key;*/
  319. };
  320. if (_action == "SPAWNED") then {
  321. // update inventory
  322. _key = format["CHILD:309:%1:%2:", _ObjectID,
  323. [getWeaponCargo _entity, getMagazineCargo _entity, getBackpackCargo _entity]];
  324. _rawData = "HiveEXT" callExtension _key;
  325. };
  326. if (_action == "MOVED" || _action == "SPAWNED") then {
  327. // update position,fuel in Hive
  328. // already done by server_updateObject?
  329. /*_key = format["CHILD:305:%1:%2:%3:", _ObjectID, [_dir, _point], _fuel];
  330. _rawData = "HiveEXT" callExtension _key;*/
  331. //Updated object position if moved
  332. [_entity, "position"] call server_updateObject;
  333. };
  334. }; // not damaged
  335. sleep 0.01; // yield to connecting players.
  336. } forEach _objectArray;
  337.  
  338. createCenter civilian;
  339. if (isDedicated) then {
  340. endLoadingScreen;
  341. };
  342.  
  343. if (isDedicated) then {
  344. _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  345. };
  346.  
  347. allowConnection = true;
  348.  
  349. // [_guaranteedLoot, _randomizedLoot, spawnOnStart, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  350. [3, 4, 3, (40 * 60), (15 * 60), 0.75, 'center', 4000, true, false] spawn server_spawnCrashSite;
  351.  
  352. // antiwallhack
  353. call compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\fa_antiwallhack.sqf";
  354.  
  355. //Spawn camps
  356. // quantity, marker, radius, min distance between 2 camps
  357. Server_InfectedCamps = [3, "center", 4500, 2000] call fn_bases;
  358. dayzInfectedCamps = Server_InfectedCamps;
  359. publicVariable "dayzInfectedCamps";
  360.  
  361. sm_done = true;
  362. publicVariable "sm_done";
  363.  
  364. [300] call server_plantSpawner;
  365.  
  366. //if (isDedicated) then {
  367. //Wild Zeds Ownership isnt working as expected yet
  368. // execFSM "\z\addons\dayz_server\system\zombie_wildagent.fsm";
  369. //};
  370. // Trap loop
  371. [] call {
  372. private ["_array","_array2","_array3","_script","_armed"];
  373. _array = str dayz_traps;
  374. _array2 = str dayz_traps_active;
  375. _array3 = str dayz_traps_trigger;
  376.  
  377. while { true } do {
  378. if ((str dayz_traps != _array) || (str dayz_traps_active != _array2) || (str dayz_traps_trigger != _array3)) then {
  379. _array = str dayz_traps;
  380. _array2 = str dayz_traps_active;
  381. _array3 = str dayz_traps_trigger;
  382.  
  383. diag_log "DEBUG: traps";
  384. diag_log format["dayz_traps (%2) -> %1", dayz_traps, count dayz_traps];
  385. diag_log format["dayz_traps_active (%2) -> %1", dayz_traps_active, count dayz_traps_active];
  386. diag_log format["dayz_traps_trigger (%2) -> %1", dayz_traps_trigger, count dayz_traps_trigger];
  387. diag_log "DEBUG: end traps";
  388. };
  389.  
  390. {
  391. if (isNull _x) then {
  392. dayz_traps = dayz_traps - [_x];
  393. };
  394.  
  395. _script = call compile getText (configFile >> "CfgVehicles" >> typeOf _x >> "script");
  396. _armed = _x getVariable ["armed", false];
  397.  
  398. if (_armed) then {
  399. if !(_x in dayz_traps_active) then {
  400. ["arm", _x] call _script;
  401. };
  402. } else {
  403. if (_x in dayz_traps_active) then {
  404. ["disarm", _x] call _script;
  405. };
  406. };
  407.  
  408. //sleep 0.01;
  409. } forEach dayz_traps;
  410. };
  411. };
  412. };
Advertisement
Add Comment
Please, Sign In to add comment