vossoft

server_playerSetup.sqf

Dec 4th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 or !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.     // add your players here like this
  93.     _playerSpawnLocations = [
  94.         // ["PLAYER-UID", [x,y,z]]
  95.         ["54746454", [50,160,0]],
  96.         ["45478744", [25,83,0]],
  97.         ["56758454", [90,120,0]]
  98.     ];
  99.     // get spawn location from the list
  100.     _position = nil;
  101.     {
  102.         if (_x select 0 == _playerID) exitWith {
  103.             // player is the list, set position
  104.             _position = _x select 1;
  105.         };
  106.     } forEach _playerSpawnLocations;
  107.     if (isNil "_position") then {
  108.         // player not in the spawn list, use random location to spawn
  109.         _randomSpot = true;
  110.     } else {
  111.         // player found, set the position
  112.         _worldspace = [0,_position]; // this will be send back to the player
  113.     };
  114. };
  115.  
  116. //diag_log ("LOGIN: Location: " + str(_worldspace) + " doRnd?: " + str(_randomSpot));
  117.  
  118. //set medical values
  119. if (count _medical > 0) then {
  120.     _playerObj setVariable["USEC_isDead",(_medical select 0),true];
  121.     _playerObj setVariable["NORRN_unconscious", (_medical select 1), true];
  122.     _playerObj setVariable["USEC_infected",(_medical select 2),true];
  123.     _playerObj setVariable["USEC_injured",(_medical select 3),true];
  124.     _playerObj setVariable["USEC_inPain",(_medical select 4),true];
  125.     _playerObj setVariable["USEC_isCardiac",(_medical select 5),true];
  126.     _playerObj setVariable["USEC_lowBlood",(_medical select 6),true];
  127.     _playerObj setVariable["USEC_BloodQty",(_medical select 7),true];
  128.     _playerObj setVariable["unconsciousTime",(_medical select 10),true];
  129.        
  130.     //Add Wounds
  131.     {
  132.         _playerObj setVariable[_x,true,true];
  133.         //["usecBleed",[_playerObj,_x,_hit]] call broadcastRpcCallAll;
  134.         usecBleed = [_playerObj,_x,_hit];
  135.         publicVariable "usecBleed";
  136.     } forEach (_medical select 8);
  137.    
  138.     //Add fractures
  139.     _fractures = (_medical select 9);
  140.     _playerObj setVariable ["hit_legs",(_fractures select 0),true];
  141.     _playerObj setVariable ["hit_hands",(_fractures select 1),true];
  142.    
  143.     if (count _medical > 11) then {
  144.         //Additional medical stats
  145.         _playerObj setVariable ["messing",(_medical select 11),true];
  146.     };
  147.    
  148. } else {
  149.     //Reset Fractures
  150.     _playerObj setVariable ["hit_legs",0,true];
  151.     _playerObj setVariable ["hit_hands",0,true];
  152.     _playerObj setVariable ["USEC_injured",false,true];
  153.     _playerObj setVariable ["USEC_inPain",false,true];
  154.     _playerObj setVariable ["messing",[0,0],true];
  155. };
  156.    
  157. if (count _stats > 0) then {   
  158.     //register stats
  159.     _playerObj setVariable["zombieKills",(_stats select 0),true];
  160.     _playerObj setVariable["headShots",(_stats select 1),true];
  161.     _playerObj setVariable["humanKills",(_stats select 2),true];
  162.     _playerObj setVariable["banditKills",(_stats select 3),true];
  163.     _playerObj addScore (_stats select 1);
  164.    
  165.     //Save Score
  166.     _score = score _playerObj;
  167.     _playerObj addScore ((_stats select 0) - _score);
  168.    
  169.     //record for Server JIP checks
  170.     _playerObj setVariable["zombieKills_CHK",(_stats select 0)];
  171.     _playerObj setVariable["headShots_CHK",(_stats select 1)];
  172.     _playerObj setVariable["humanKills_CHK",(_stats select 2)];
  173.     _playerObj setVariable["banditKills_CHK",(_stats select 3)];
  174.     if (count _stats > 4) then {
  175.         if (!(_stats select 3)) then {
  176.             _playerObj setVariable["selectSex",true,true];
  177.         };
  178.     } else {
  179.         _playerObj setVariable["selectSex",true,true];
  180.     };
  181. } else {
  182.     //Save initial loadout
  183.     //register stats
  184.     _playerObj setVariable["zombieKills",0,true];
  185.     _playerObj setVariable["humanKills",0,true];
  186.     _playerObj setVariable["banditKills",0,true];
  187.     _playerObj setVariable["headShots",0,true];
  188.    
  189.     //record for Server JIP checks
  190.     _playerObj setVariable["zombieKills_CHK",0];
  191.     _playerObj setVariable["humanKills_CHK",0,true];
  192.     _playerObj setVariable["banditKills_CHK",0,true];
  193.     _playerObj setVariable["headShots_CHK",0];
  194. };
  195.  
  196. if (_randomSpot) then {
  197.     private["_counter","_position","_isNear","_isZero","_mkr"];
  198.     if (!isDedicated) then {
  199.         endLoadingScreen;
  200.     };
  201.    
  202.     //Spawn modify via mission init.sqf
  203.     if(isnil "spawnArea") then {
  204.         spawnArea = 1500;
  205.     };
  206.     if(isnil "spawnShoremode") then {
  207.         spawnShoremode = 1;
  208.     };
  209.    
  210.     //
  211.     _spawnMC = actualSpawnMarkerCount;
  212.  
  213.     //spawn into random
  214.     _findSpot = true;
  215.     _mkr = "";
  216.     while {_findSpot} do {
  217.         _counter = 0;
  218.         while {_counter < 20 and _findSpot} do {
  219.             // switched to floor
  220.             _mkr = "spawn" + str(floor(random _spawnMC));
  221.             _position = ([(getMarkerPos _mkr),0,spawnArea,10,0,2000,spawnShoremode] call BIS_fnc_findSafePos);
  222.             _isNear = count (_position nearEntities ["Man",100]) == 0;
  223.             _isZero = ((_position select 0) == 0) and ((_position select 1) == 0);
  224.             //Island Check      //TeeChange
  225.             _pos        = _position;
  226.             _isIsland   = false;        //Can be set to true during the Check
  227.             for [{_w=0},{_w<=150},{_w=_w+2}] do {
  228.                 _pos = [(_pos select 0),((_pos select 1) + _w),(_pos select 2)];
  229.                 if(surfaceisWater _pos) exitWith {
  230.                     _isIsland = true;
  231.                 };
  232.             };
  233.            
  234.             if ((_isNear and !_isZero) || _isIsland) then {_findSpot = false};
  235.             _counter = _counter + 1;
  236.         };
  237.     };
  238.     _isZero = ((_position select 0) == 0) and ((_position select 1) == 0);
  239.     _position = [_position select 0,_position select 1,0];
  240.     if (!_isZero) then {
  241.         //_playerObj setPosATL _position;
  242.         _worldspace = [0,_position];
  243.     };
  244. };
  245.  
  246. //Record player for management
  247. dayz_players set [count dayz_players,_playerObj];
  248.  
  249. //record player pos locally for server checking
  250. _playerObj setVariable["CharacterID",_characterID,true];
  251. _playerObj setVariable["humanity",_humanity,true];
  252. _playerObj setVariable["humanity_CHK",_humanity];
  253. //_playerObj setVariable["worldspace",_worldspace,true];
  254. //_playerObj setVariable["state",_state,true];
  255. _playerObj setVariable["lastPos",getPosATL _playerObj];
  256.  
  257. dayzPlayerLogin2 = [_worldspace,_state];
  258. _clientID = owner _playerObj;
  259. _clientID publicVariableClient "dayzPlayerLogin2";
  260.  
  261. //record time started
  262. _playerObj setVariable ["lastTime",time];
  263. //_playerObj setVariable ["model_CHK",typeOf _playerObj];
  264.  
  265. //diag_log ("LOGIN PUBLISHING: " + str(_playerObj) + " Type: " + (typeOf _playerObj));
  266.  
  267. PVDZE_plr_Login = null;
  268. PVDZE_plr_Login2 = null;
Advertisement
Add Comment
Please, Sign In to add comment