Advertisement
Guest User

server_playerSetup.sqf

a guest
May 29th, 2015
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. private ["_characterID","_playerObj","_playerID","_dummy","_worldspace","_state","_doLoop","_key","_primary","_medical","_stats","_humanity","_lastinstance","_friendlies","_randomSpot","_position","_debug","_distance","_hit","_fractures","_score","_findSpot","_pos","_isIsland","_w","_clientID","_spawnMC","_namespace"];
  2.  
  3. //diag_log ("SETUP: attempted with " + str(_this));
  4.  
  5. _characterID = _this select 0;
  6. _playerObj = _this select 1;
  7. _playerID = getPlayerUID _playerObj;
  8.  
  9. if (isNull _playerObj) exitWith {
  10. diag_log ("SETUP INIT FAILED: Exiting, player object null: " + str(_playerObj));
  11. };
  12.  
  13. //Add MPHit event handler
  14. // diag_log("Adding MPHit EH for " + str(_playerObj));
  15. _playerObj addMPEventHandler ["MPHit", {_this spawn fnc_plyrHit;}];
  16.  
  17. if (_playerID == "") then {
  18. _playerID = getPlayerUID _playerObj;
  19. };
  20.  
  21. if (_playerID == "") exitWith {
  22. diag_log ("SETUP INIT FAILED: Exiting, no player ID: " + str(_playerObj));
  23. };
  24.  
  25. private["_dummy"];
  26. _dummy = getPlayerUID _playerObj;
  27. if ( _playerID != _dummy ) then {
  28. diag_log format["DEBUG: _playerID miscompare with UID! _playerID:%1",_playerID];
  29. _playerID = _dummy;
  30. };
  31.  
  32. //Variables
  33. _worldspace = [];
  34.  
  35. _state = [];
  36.  
  37. //Do Connection Attempt
  38. _doLoop = 0;
  39. while {_doLoop < 5} do {
  40. _key = format["CHILD:102:%1:",_characterID];
  41. _primary = _key call server_hiveReadWrite;
  42. if (count _primary > 0) then {
  43. if ((_primary select 0) != "ERROR") then {
  44. _doLoop = 9;
  45. };
  46. };
  47. _doLoop = _doLoop + 1;
  48. };
  49.  
  50. if (isNull _playerObj || !isPlayer _playerObj) exitWith {
  51. diag_log ("SETUP RESULT: Exiting, player object null: " + str(_playerObj));
  52. };
  53.  
  54. //Wait for HIVE to be free
  55. //diag_log ("SETUP: RESULT: Successful with " + str(_primary));
  56.  
  57. _medical = _primary select 1;
  58. _stats = _primary select 2;
  59. _state = _primary select 3;
  60. _worldspace = _primary select 4;
  61. _humanity = _primary select 5;
  62. _lastinstance = _primary select 6;
  63.  
  64. //Set position
  65. _randomSpot = false;
  66.  
  67. if (count _worldspace > 0) then {
  68.  
  69. _position = _worldspace select 1;
  70. if (count _position < 3) then {
  71. //prevent debug world!
  72. _randomSpot = true;
  73. };
  74. _debug = getMarkerpos "respawn_west";
  75. _distance = _debug distance _position;
  76. if (_distance < 2000) then {
  77. _randomSpot = true;
  78. };
  79.  
  80. _distance = [0,0,0] distance _position;
  81. if (_distance < 500) then {
  82. _randomSpot = true;
  83. };
  84.  
  85. // Came from another server force random spawn
  86. if (_lastinstance != dayZ_instance) then {
  87. _randomSpot = true;
  88. };
  89.  
  90. //_playerObj setPosATL _position;
  91. } else {
  92. _randomSpot = true;
  93. };
  94.  
  95. //diag_log ("LOGIN: Location: " + str(_worldspace) + " doRnd?: " + str(_randomSpot));
  96.  
  97. //set medical values
  98. if (count _medical > 0) then {
  99. _playerObj setVariable["USEC_isDead",(_medical select 0),true];
  100. _playerObj setVariable["NORRN_unconscious", (_medical select 1), true];
  101. _playerObj setVariable["USEC_infected",(_medical select 2),true];
  102. _playerObj setVariable["USEC_injured",(_medical select 3),true];
  103. _playerObj setVariable["USEC_inPain",(_medical select 4),true];
  104. _playerObj setVariable["USEC_isCardiac",(_medical select 5),true];
  105. _playerObj setVariable["USEC_lowBlood",(_medical select 6),true];
  106. _playerObj setVariable["USEC_BloodQty",(_medical select 7),true];
  107. _playerObj setVariable["unconsciousTime",(_medical select 10),true];
  108.  
  109. //Add Wounds
  110. {
  111. _playerObj setVariable[_x,true,true];
  112. //["usecBleed",[_playerObj,_x,_hit]] call broadcastRpcCallAll;
  113. usecBleed = [_playerObj,_x,_hit];
  114. publicVariable "usecBleed";
  115. } count (_medical select 8);
  116.  
  117. //Add fractures
  118. _fractures = (_medical select 9);
  119. _playerObj setVariable ["hit_legs",(_fractures select 0),true];
  120. _playerObj setVariable ["hit_hands",(_fractures select 1),true];
  121.  
  122. if (count _medical > 11) then {
  123. //Additional medical stats
  124. _playerObj setVariable ["messing",(_medical select 11),true];
  125. };
  126.  
  127. } else {
  128. //Reset Fractures
  129. _playerObj setVariable ["hit_legs",0,true];
  130. _playerObj setVariable ["hit_hands",0,true];
  131. _playerObj setVariable ["USEC_injured",false,true];
  132. _playerObj setVariable ["USEC_inPain",false,true];
  133. _playerObj setVariable ["messing",[0,0],true];
  134. };
  135.  
  136. if (count _stats > 0) then {
  137. //register stats
  138. _playerObj setVariable["zombieKills",(_stats select 0),true];
  139. _playerObj setVariable["headShots",(_stats select 1),true];
  140. _playerObj setVariable["humanKills",(_stats select 2),true];
  141. _playerObj setVariable["banditKills",(_stats select 3),true];
  142. _playerObj addScore (_stats select 1);
  143.  
  144. //Save Score
  145. _score = score _playerObj;
  146. _playerObj addScore ((_stats select 0) - _score);
  147.  
  148. //record for Server JIP checks
  149. _playerObj setVariable["zombieKills_CHK",(_stats select 0)];
  150. _playerObj setVariable["headShots_CHK",(_stats select 1)];
  151. _playerObj setVariable["humanKills_CHK",(_stats select 2)];
  152. _playerObj setVariable["banditKills_CHK",(_stats select 3)];
  153. if (count _stats > 4) then {
  154. if (!(_stats select 3)) then {
  155. _playerObj setVariable["selectSex",true,true];
  156. };
  157. } else {
  158. _playerObj setVariable["selectSex",true,true];
  159. };
  160. } else {
  161. //Save initial loadout
  162. //register stats
  163. _playerObj setVariable["zombieKills",0,true];
  164. _playerObj setVariable["humanKills",0,true];
  165. _playerObj setVariable["banditKills",0,true];
  166. _playerObj setVariable["headShots",0,true];
  167.  
  168. //record for Server JIP checks
  169. _playerObj setVariable["zombieKills_CHK",0];
  170. _playerObj setVariable["humanKills_CHK",0,true];
  171. _playerObj setVariable["banditKills_CHK",0,true];
  172. _playerObj setVariable["headShots_CHK",0];
  173. };
  174.  
  175. if (_randomSpot) then {
  176. private["_counter","_position","_isNear","_isZero","_mkr"];
  177. if (!isDedicated) then {
  178. endLoadingScreen;
  179. };
  180.  
  181. //Spawn modify via mission init.sqf
  182. if(isnil "spawnArea") then {
  183. spawnArea = 1500;
  184. };
  185. if(isnil "spawnShoremode") then {
  186. spawnShoremode = 1;
  187. };
  188.  
  189. //
  190. _spawnMC = actualSpawnMarkerCount;
  191.  
  192. //spawn into random
  193. _findSpot = true;
  194. _mkr = "";
  195. while {_findSpot} do {
  196. _counter = 0;
  197. while {_counter < 20 && _findSpot} do {
  198. // switched to floor
  199. _mkr = "spawn" + str(floor(random _spawnMC));
  200. _position = ([(getMarkerPos _mkr),0,spawnArea,10,0,2000,spawnShoremode] call BIS_fnc_findSafePos);
  201. _isNear = count (_position nearEntities ["Man",100]) == 0;
  202. _isZero = ((_position select 0) == 0) && ((_position select 1) == 0);
  203. //Island Check //TeeChange
  204. _pos = _position;
  205. _isIsland = false; //Can be set to true during the Check
  206. for [{_w=0},{_w<=150},{_w=_w+2}] do {
  207. _pos = [(_pos select 0),((_pos select 1) + _w),(_pos select 2)];
  208. if(surfaceisWater _pos) exitWith {
  209. _isIsland = true;
  210. };
  211. };
  212.  
  213. if ((_isNear && !_isZero) || _isIsland) then {_findSpot = false};
  214. _counter = _counter + 1;
  215. };
  216. };
  217. _isZero = ((_position select 0) == 0) && ((_position select 1) == 0);
  218. _position = [_position select 0,_position select 1,0];
  219. if (!_isZero) then {
  220. //_playerObj setPosATL _position;
  221. _worldspace = [0,_position];
  222. };
  223. };
  224.  
  225. //Record player for management
  226. dayz_players set [count dayz_players,_playerObj];
  227.  
  228. //record player pos locally for server checking
  229. _playerObj setVariable["CharacterID",_characterID,true];
  230. _playerObj setVariable["humanity",_humanity,true];
  231. _playerObj setVariable["humanity_CHK",_humanity];
  232. //_playerObj setVariable["worldspace",_worldspace,true];
  233. //_playerObj setVariable["state",_state,true];
  234. _playerObj setVariable["lastPos",getPosATL _playerObj];
  235.  
  236. dayzPlayerLogin2 = [_worldspace,_state,_randomSpot];
  237.  
  238. // PVDZE_obj_Debris = DZE_LocalRoadBlocks;
  239. _clientID = owner _playerObj;
  240. if (!isNull _playerObj) then {
  241. _clientID publicVariableClient "dayzPlayerLogin2";
  242.  
  243. if (isNil "PVDZE_plr_SetDate") then {
  244. call server_timeSync;
  245. };
  246. _clientID publicVariableClient "PVDZE_plr_SetDate";
  247. };
  248. //record time started
  249. _playerObj setVariable ["lastTime",time];
  250. //_playerObj setVariable ["model_CHK",typeOf _playerObj];
  251.  
  252. //diag_log ("LOGIN PUBLISHING: " + str(_playerObj) + " Type: " + (typeOf _playerObj));
  253.  
  254. PVDZE_plr_Login = nil;
  255. PVDZE_plr_Login2 = nil;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement