Advertisement
Guest User

heli crash site 1.7.6.1

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