Advertisement
NyxGrimlock

player setup

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