Advertisement
fr1nkbot

server_spawnCrashSite.sqf

Jun 16th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. private ["_position","_num","_config","_itemType","_weights","_index","_crashModel","_lootTable","_guaranteedLoot","_randomizedLoot","_frequency","_variance","_spawnChance","_spawnMarker","_spawnRadius","_spawnFire","_crashName","_nearby","_itemTypes","_cntWeights","_fadeFire"];
  2.  
  3. //_crashModel = _this select 0;
  4. //_lootTable = _this select 1;
  5. _guaranteedLoot = _this select 0;
  6. _randomizedLoot = _this select 1;
  7. _frequency = _this select 2;
  8. _variance = _this select 3;
  9. _spawnChance = _this select 4;
  10. _spawnMarker = _this select 5;
  11. _spawnRadius = _this select 6;
  12. _spawnFire = _this select 7;
  13. _fadeFire = _this select 8;
  14.  
  15.  
  16. diag_log("CRASHSPAWNER: Starting spawn logic for Crash Spawner");
  17.  
  18. while {true} do {
  19. private["_timeAdjust","_timeToSpawn","_spawnRoll","_crash","_hasAdjustment","_newHeight","_adjustedPos"];
  20. // Allows the variance to act as +/- from the spawn frequency timer
  21. _timeAdjust = round(random(_variance * 2) - _variance);
  22. _timeToSpawn = time + _frequency + _timeAdjust;
  23.  
  24. //Adding some Random systems
  25. _crashModel = ["UH60Wreck_DZ","UH1Wreck_DZ","Mass_grave_DZ"] call BIS_fnc_selectRandom;
  26.  
  27.  
  28. if(_crashModel == "Mass_grave_DZ") then {
  29. _lootTable = "MassGrave";
  30. } else {
  31. //Crash loot just uncomment the one you wish to use by default with 50cals is enabled.
  32. //Table including 50 cals
  33. _lootTable = ["Military","HeliCrash","MilitarySpecial"] call BIS_fnc_selectRandom;
  34. //Table without 50 cals
  35. //_lootTable = ["Military","HeliCrash_No50s","MilitarySpecial"] call BIS_fnc_selectRandom;
  36. };
  37.  
  38. _crashName = getText (configFile >> "CfgVehicles" >> _crashModel >> "displayName");
  39.  
  40. diag_log(format["CRASHSPAWNER: %1%2 chance to spawn '%3' with loot table '%4' at %5", round(_spawnChance * 100), '%', _crashName, _lootTable, _timeToSpawn]);
  41.  
  42. // Apprehensive about using one giant long sleep here given server time variances over the life of the server daemon
  43. while {time < _timeToSpawn} do {
  44. sleep 5;
  45. };
  46.  
  47. _spawnRoll = random 1;
  48.  
  49. // Percentage roll
  50. if (_spawnRoll <= _spawnChance) then {
  51.  
  52. _position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,2000,0] call BIS_fnc_findSafePos;
  53.  
  54. diag_log(format["CRASHSPAWNER: Spawning '%1' with loot table '%2' NOW! (%3) at: %4", _crashName, _lootTable, time, str(_position)]);
  55.  
  56. _crash = createVehicle [_crashModel,_position, [], 0, "CAN_COLLIDE"];
  57. // Randomize the direction the wreck is facing
  58. _crash setDir round(random 360);
  59.  
  60. // Using "custom" wrecks (using the destruction model of a vehicle vs. a prepared wreck model) will result
  61. // in the model spawning halfway in the ground. To combat this, an OPTIONAL configuration can be tied to
  62. // the CfgVehicles class you've created for the custom wreck to define how high above the ground it should
  63. // spawn. This is optional.
  64. _config = configFile >> "CfgVehicles" >> _crashModel >> "heightAdjustment";
  65. _hasAdjustment = isNumber(_config);
  66. _newHeight = 0;
  67. if (_hasAdjustment) then {
  68. _newHeight = getNumber(_config);
  69. //diag_log(format["DIAG: ADJUSTMENT FOUND FOR %1, IT IS: %2", _crashName, _newHeight]);
  70. };
  71.  
  72. // Must setPos after a setDir otherwise the wreck won't level itself with the terrain
  73. _adjustedPos = [(_position select 0), (_position select 1), _newHeight];
  74. //diag_log(format["DIAG: Designated Position: %1", str(_adjustedPos)]);
  75. _crash setPos _adjustedPos;
  76.  
  77. // I don't think this is needed (you can't get "in" a crash), but it was in the original DayZ Crash logic
  78. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_crash];
  79.  
  80. _crash setVariable ["ObjectID",1,true];
  81.  
  82. // Disable simulation server side
  83. _crash enableSimulation false;
  84.  
  85. _num = round(random _randomizedLoot) + _guaranteedLoot;
  86.  
  87. if(_crashModel == "Mass_grave_DZ") then {
  88. _spawnFire = false;
  89. _num = _num * 2;
  90. };
  91.  
  92. if (_spawnFire) then {
  93. //["dayzFire",[_crash,2,time,false,_fadeFire]] call broadcastRpcCallAll;
  94. dayzFire = [_crash,2,time,false,_fadeFire];
  95. publicVariable "dayzFire";
  96. _crash setvariable ["fadeFire",_fadeFire,true];
  97. };
  98.  
  99.  
  100.  
  101. _config = configFile >> "CfgBuildingLoot" >> _lootTable;
  102. _itemTypes = [] + getArray (_config >> "itemType");
  103. _index = dayz_CBLBase find toLower(_lootTable);
  104. _weights = dayz_CBLChances select _index;
  105. _cntWeights = count _weights;
  106.  
  107. for "_x" from 1 to _num do {
  108. //create loot
  109. _index = floor(random _cntWeights);
  110. _index = _weights select _index;
  111. _itemType = _itemTypes select _index;
  112. [_itemType select 0, _itemType select 1, _position, 5] call spawn_loot;
  113.  
  114. diag_log(format["CRASHSPAWNER: Loot spawn at '%1' with loot table '%2'", _crashName, _lootTable]);
  115.  
  116. // ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 and other such items.
  117. _nearby = _position nearObjects ["ReammoBox", sizeOf(_crashModel)];
  118. {
  119. _x setVariable ["permaLoot",true];
  120. } forEach _nearBy;
  121. };
  122.  
  123. };
  124. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement