Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.35 KB | None | 0 0
  1. private ["_characterID","_temp","_currentWpn","_magazines","_force","_isNewPos","_humanity","_isNewGear","_currentModel","_modelChk","_playerPos","_playerGear","_playerBackp","_backpack","_killsB","_killsH","_medical","_isNewMed","_character","_timeSince","_charPos","_isInVehicle","_distanceFoot","_lastPos","_kills","_headShots","_timeGross","_timeLeft","_onLadder","_isTerminal","_currentAnim","_muzzles","_array","_key","_lastTime","_config","_currentState","_pos"];
  2. //[player,array]
  3. //diag_log ("UPDATE: " + str(_this) );
  4.  
  5. //waituntil {(typeName(_this) == "ARRAY");sleep 0.01;}; //seems to cause often infinite waits (but not for first n players)
  6.  
  7. //this only happens when we don't follow the correct parameter format...
  8. //(like supplying just the player object instead of the array in player_eat.sqf)
  9. //i've fixed this in player_eat so i can comment this part out
  10. /*if ( typeName(_this) == "OBJECT" ) then {
  11. _this = [_this,[],true];
  12. //diag_log ("DW_DEBUG: #manual fix _this: " + str(_this));
  13. };*/
  14.  
  15. //correct
  16. //"UPDATE: [B 1-1-B:1 (THE BEAST) REMOTE,[],true]"
  17. //error
  18. //"UPDATE: B 1-1-B:1 (THE BEAST) REMOTE"
  19.  
  20. _character = _this select 0;
  21. _magazines = _this select 1;
  22. _force = _this select 2;
  23. _force = true;
  24.  
  25. _characterID = _character getVariable ["characterID","0"];
  26. _charPos = getPosATL _character;
  27. _isInVehicle = vehicle _character != _character;
  28. _timeSince = 0;
  29. _humanity = 0;
  30.  
  31. //diag_log ("DW_DEBUG: (isnil _characterID): " + str(isnil "_characterID"));
  32. /*
  33. if !(isnil "_characterID") then {
  34. diag_log ("DW_DEBUG: _characterID: " + str(_characterID));
  35. };
  36. */
  37.  
  38. if (_character isKindOf "Animal") exitWith {
  39. diag_log ("ERROR: Cannot Sync Character " + (name _character) + " is an Animal class");
  40. };
  41.  
  42. if (isnil "_characterID") exitWith {
  43. diag_log ("ERROR: Cannot Sync Character " + (name _character) + " has nil characterID");
  44. };
  45.  
  46. if (_characterID == "0") exitWith {
  47. diag_log ("ERROR: Cannot Sync Character " + (name _character) + " as no characterID");
  48. };
  49.  
  50. private["_debug","_distance"];
  51. _debug = getMarkerpos "respawn_west";
  52. _distance = _debug distance _charPos;
  53. if (_distance < 2000) exitWith {
  54. diag_log format["ERROR: server_playerSync: Cannot Sync Player %1 [%2]. Position in debug! %3",name _character,_characterID,_charPos];
  55. };
  56.  
  57. //Check for server initiated updates
  58. _isNewMed = _character getVariable["medForceUpdate",false]; //Med Update is forced when a player receives some kind of med incident
  59. _isNewPos = _character getVariable["posForceUpdate",false]; //Med Update is forced when a player receives some kind of med incident
  60. _isNewGear = if (!isNil "_magazines") then { true } else { false };
  61.  
  62. //diag_log ("Starting Save... MED: " + str(_isNewMed) + " / POS: " + str(_isNewPos)); sleep 0.05;
  63.  
  64. //Check for player initiated updates
  65. if (_characterID != "0") then {
  66. _playerPos = [];
  67. _playerGear = [];
  68. _playerBackp = [];
  69. _medical = [];
  70. _distanceFoot = 0;
  71.  
  72. //diag_log ("Found Character...");
  73.  
  74. //Check if update is requested
  75. if (_isNewPos or _force) then {
  76. //diag_log ("position..." + str(_isNewPos) + " / " + str(_force)); sleep 0.05;
  77. if (((_charPos select 0) == 0) and ((_charPos select 1) == 0)) then {
  78. //Zero Position
  79. } else {
  80. //diag_log ("getting position..."); sleep 0.05;
  81. _playerPos = [round(direction _character),_charPos];
  82. _lastPos = _character getVariable["lastPos",_charPos];
  83. if (count _lastPos > 2 and count _charPos > 2) then {
  84. if (!_isInVehicle) then {
  85. _distanceFoot = round(_charPos distance _lastPos);
  86. if ( _distanceFoot > 2000 ) then
  87. {
  88. _distanceFoot = 0;
  89. };
  90. //diag_log ("debug _distanceFoot = " + str(_distanceFoot));
  91. };
  92. _character setVariable["lastPos",_charPos];
  93. };
  94. if (count _charPos < 3) then {
  95. _playerPos = [];
  96. };
  97. //diag_log ("position = " + str(_playerPos)); sleep 0.05;
  98. };
  99. _character setVariable ["posForceUpdate",false,true];
  100. };
  101. if (_isNewGear) then {
  102. //diag_log ("gear..."); sleep 0.05;
  103. _playerGear = [weapons _character, _magazines select 0, _magazines select 1];
  104. _backpack = unitBackpack _character;
  105. _playerBackp = [typeOf _backpack,getWeaponCargo _backpack,getMagazineCargo _backpack];
  106. };
  107. if (_isNewMed or _force) then {
  108. //diag_log ("medical..."); sleep 0.05;
  109. if (!(_character getVariable["USEC_isDead",false])) then {
  110. //diag_log ("medical check..."); sleep 0.05;
  111. _medical = _character call player_sumMedical;
  112. //diag_log ("medical result..." + str(_medical)); sleep 0.05;
  113. };
  114. _character setVariable ["medForceUpdate",false,true];
  115. };
  116.  
  117. //Process update
  118. if (_characterID != "0") then {
  119. //Record stats while we're here
  120. /*
  121. Check previous stats against what client had when they logged in
  122. this helps prevent JIP issues, where a new player wouldn't have received
  123. the old players updates. Only valid for stats where clients could have
  124. be recording results from their local objects (such as agent zombies)
  125. */
  126. _kills = ["zombieKills",_character] call server_getDiff;
  127. _killsB = ["banditKills",_character] call server_getDiff;
  128. _killsH = ["humanKills",_character] call server_getDiff;
  129. _headShots = ["headShots",_character] call server_getDiff;
  130. _humanity = ["humanity",_character] call server_getDiff2;
  131. //_humanity = _character getVariable ["humanity",0];
  132. _character addScore _kills;
  133. /*
  134. Assess how much time has passed, for recording total time on server
  135. */
  136. _lastTime = _character getVariable["lastTime",time];
  137. _timeGross = (time - _lastTime);
  138. _timeSince = floor(_timeGross / 60);
  139. _timeLeft = (_timeGross - (_timeSince * 60));
  140. /*
  141. Get character state details
  142. */
  143. _currentWpn = currentMuzzle _character;
  144. _currentAnim = animationState _character;
  145. _config = configFile >> "CfgMovesMaleSdr" >> "States" >> _currentAnim;
  146. _onLadder = (getNumber (_config >> "onLadder")) == 1;
  147. _isTerminal = (getNumber (_config >> "terminal")) == 1;
  148. //_wpnDisabled = (getNumber (_config >> "disableWeapons")) == 1;
  149. _currentModel = typeOf _character;
  150. _modelChk = _character getVariable ["model_CHK",""];
  151. if (_currentModel == _modelChk) then {
  152. _currentModel = "";
  153. } else {
  154. _currentModel = str(_currentModel);
  155. _character setVariable ["model_CHK",typeOf _character];
  156. };
  157.  
  158. if (_onLadder or _isInVehicle or _isTerminal) then {
  159. _currentAnim = "";
  160. //If position to be updated, make sure it is at ground level!
  161. if ((count _playerPos > 0) and !_isTerminal) then {
  162. _charPos set [2,0];
  163. _playerPos set[1,_charPos];
  164. };
  165. };
  166. if (_isInVehicle) then {
  167. _currentWpn = "";
  168. } else {
  169. if ( typeName(_currentWpn) == "STRING" ) then {
  170. _muzzles = getArray(configFile >> "cfgWeapons" >> _currentWpn >> "muzzles");
  171. if (count _muzzles > 1) then {
  172. _currentWpn = currentMuzzle _character;
  173. };
  174. } else {
  175. //diag_log ("DW_DEBUG: _currentWpn: " + str(_currentWpn));
  176. _currentWpn = "";
  177. };
  178. };
  179. _temp = round(_character getVariable ["temperature",100]);
  180. _currentState = [_currentWpn,_currentAnim,_temp];
  181. /*
  182. Everything is ready, now publish to HIVE
  183. */
  184. if (count _playerPos > 0) then {
  185. _array = [];
  186. {
  187. if (_x > -20000 and _x < 20000) then {
  188. _array set [count _array,_x];
  189. };
  190. } forEach (_playerPos select 1);
  191. _playerPos set [1,_array];
  192. };
  193. if (!isNull _character) then {
  194. if (alive _character) then {
  195. //Wait for HIVE to be free
  196. //Send request
  197. _key = format["CHILD:201:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:",_characterID,_playerPos,_playerGear,_playerBackp,_medical,false,false,_kills,_headShots,_distanceFoot,_timeSince,_currentState,_killsH,_killsB,_currentModel,_humanity];
  198. //diag_log ("HIVE: WRITE: "+ str(_key) + " / " + _characterID);
  199. _key call server_hiveWrite;
  200. };
  201. };
  202.  
  203. // If player is in a vehicle, keep its position updated
  204. if (vehicle _character != _character) then {
  205. [vehicle _character, "position"] call server_updateObject;
  206. };
  207.  
  208. // Force gear updates for nearby vehicles/tents
  209. _pos = _this select 0;
  210. {
  211. [_x, "gear"] call server_updateObject;
  212. } forEach nearestObjects [_pos, ["Car", "Helicopter", "Motorcycle", "Ship", "TentStorage", "StashSmall","StashMedium"], 10];
  213. //[_charPos] call server_updateNearbyObjects;
  214.  
  215. //Reset timer
  216. if (_timeSince > 0) then {
  217. _character setVariable ["lastTime",(time - _timeLeft)];
  218. };
  219. };
  220. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement