Advertisement
Guest User

Untitled

a guest
Dec 24th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.74 KB | None | 0 0
  1. /*
  2. Script Name: crash_spawner.sqf
  3. Original Author: Grafzahl / Finest
  4. Modified by BushWookie & Forgotten for Epoch
  5. Modified by f3cuk for Epoch 1051
  6. Script Version: 1.3
  7. */
  8.  
  9. private["_timeAdjust","_timeToSpawn","_spawnRoll","_crash","_hasAdjustment","_newHeight","_adjustedPos","_useStatic","_crashDamage","_lootRadius","_preWaypoints","_preWaypointPos","_endTime","_startTime","_safetyPoint","_heliStart","_deadBody","_exploRange","_heliModel","_lootPos","_list","_craters","_dummy","_wp2","_wp3","_landingzone","_aigroup","_wp","_helipilot","_crash","_crashwreck","_smokerand","_staticcoords","_pos","_dir","_position","_num","_config","_itemType","_itemChance","_weights","_index","_iArray","_crashModel","_lootTable","_guaranteedLoot","_randomizedLoot","_frequency","_variance","_spawnChance","_spawnMarker","_spawnRadius","_spawnFire","_permanentFire","_crashName","_event_marker", "_markerRadius","_hint","_itemTypes"];
  10.  
  11. _spawnChance = 100; // Percent chance of spawning a crash number between 0 - 100
  12. _guaranteedLoot = 8; // Guaranteed Loot Spawns
  13. _randomizedLoot = 8; // Random number of loot piles as well as the guaranteed ones
  14. _spawnFire = true; // Spawn Smoke/Fire at the helicrash
  15. _fadeFire = false; // Fade the Smoke/Fire overtime
  16. _preWaypoints = 2; // Amount of way points the heli flies to before crashing
  17. _crashDamage = 0.3; // Amount of damage the heli can take before crashing (between 0.1 and 1) Lower the number and the heli can take less damage before crashing 1 damage is fully destroyed and 0.1 something like a DMR could one shot the heli
  18. _exploRange = 50; // How far away from the predefined crash point should the heli start crashing
  19. _minLootRadius = 4; // Minimum distance for loot to spawn from the crash site in meters
  20. _maxLootRadius = 10; // Maximum distance for loot to spawn from the crash site in meters
  21. _lootTable = "HeliCrash"; // Name of the loot table the heli gets loot from (DO NOT edit unless you know what your doing)
  22. _markerRadius = 500; // Radius for the marker
  23. _spawnMarker = "center";
  24. _heliModel = ["UH1Y_DZE"] call BIS_fnc_selectRandom;
  25. _crashModel = "UH1Wreck_DZ";
  26. _plane = false;
  27. _porh = "helicopter";
  28.  
  29. _spawnRadius = HeliCrashArea;
  30. _heliStart = [[400.000,-630,20084.0],[240.000,-630,244.000],[20208.0,-630,20212.0],[20240.0,-630,180.000]] call BIS_fnc_selectRandom;
  31. _safetyPoint = [0,16000,0];
  32. _crashName = getText (configFile >> "CfgVehicles" >> _heliModel >> "displayName");
  33. _spawnRoll = round(random 100);
  34.  
  35. diag_log(format["CRASHSPAWNER: %1%2 chance to start a crashing %3 with loot table '%4'", _spawnChance, '%', _crashName, _lootTable]);
  36.  
  37. if (_spawnRoll <= _spawnChance) then
  38. {
  39.  
  40. if(_plane) then {
  41. _porh = "plane";
  42. };
  43.  
  44. [nil,nil,rTitleText,format["A %1 is in distress! Watch for it and go to the crash site to secure the loot!",_porh], "PLAIN",10] call RE;
  45.  
  46. _position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,2000,0] call BIS_fnc_findSafePos;
  47.  
  48. diag_log(format["CRASHSPAWNER: %1 started flying from %2 to %3 NOW!(TIME:%4||LT:%5)", _crashName, str(_heliStart), str(_position), round(time), _lootTable]);
  49.  
  50. _startTime = time;
  51. _crashwreck = createVehicle [_heliModel,_heliStart, [], 0, "FLY"];
  52. _crashwreck setCombatMode "BLUE";
  53. _crashwreck engineOn true;
  54.  
  55. if (_plane) then
  56. {
  57. _crashwreck flyInHeight 300;
  58. _crashwreck forceSpeed 250;
  59. _crashwreck setspeedmode "LIMITED";
  60. }
  61. else
  62. {
  63. _crashwreck flyInHeight 150;
  64. _crashwreck forceSpeed 150;
  65. _crashwreck setspeedmode "NORMAL";
  66. };
  67.  
  68. _landingzone = createVehicle ["HeliHEmpty", [_position select 0, _position select 1,0], [], 0, "CAN_COLLIDE"];
  69. _aigroup = creategroup civilian;
  70. _helipilot = _aigroup createUnit ["SurvivorW2_DZ",getPos _crashwreck,[],0,"FORM"];
  71. _helipilot setCombatMode "BLUE";
  72. _helipilot moveindriver _crashwreck;
  73. _helipilot assignAsDriver _crashwreck;
  74.  
  75. sleep 0.5;
  76.  
  77. if(_preWaypoints > 0) then
  78. {
  79. for "_x" from 1 to _preWaypoints do
  80. {
  81. _preWaypointPos = [getMarkerPos _spawnMarker, 0, _spawnRadius, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
  82. _wp = _aigroup addWaypoint [_preWaypointPos, 0];
  83. _wp setWaypointType "MOVE";
  84. _wp setWaypointBehaviour "CARELESS";
  85. };
  86. };
  87.  
  88. _wp2 = _aigroup addWaypoint [position _landingzone, 0];
  89. _wp2 setWaypointType "MOVE";
  90. _wp2 setWaypointBehaviour "CARELESS";
  91. _wp2 setWaypointStatements ["true", "_crashwreck setdamage 1;"];
  92. _wp3 = _aigroup addWaypoint [_safetyPoint, 0];
  93. _wp3 setWaypointType "CYCLE";
  94. _wp3 setWaypointBehaviour "CARELESS";
  95.  
  96. waituntil {(_crashwreck distance _position) <= 1000 || !alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  97.  
  98. if (_plane) then
  99. {
  100. _crashwreck flyInHeight 100;
  101. _crashwreck forceSpeed 150;
  102. _crashwreck setspeedmode "LIMITED";
  103. _exploRange = 360;
  104. }
  105. else
  106. {
  107. _crashwreck flyInHeight 100;
  108. _crashwreck forceSpeed 100;
  109. _crashwreck setspeedmode "NORMAL";
  110. };
  111.  
  112. waituntil {(_crashwreck distance _position) <= _exploRange || !alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  113.  
  114. if (_plane) then
  115. {
  116. _crashwreck setdamage 1;
  117. _vel = velocity _crashwreck;
  118. _dir = direction _crashwreck;
  119. _speed = 100;
  120. _crashwreck setVelocity [(_vel select 0)-(sin _dir*_speed),(_vel select 1)-(cos _dir*_speed),(_vel select 2) - 30];
  121. }
  122. else
  123. {
  124. _crashwreck setHit ["mala vrtule", 1];
  125. _ran15 = random 15;
  126. _crashwreck setVelocity [_ran15,_ran15,-25];
  127. _crashwreck setdamage .9;
  128.  
  129. waitUntil{sleep 1; getpos _crashwreck select 2 <= 30};
  130.  
  131. _helipilot setdamage 1;
  132. _crashwreck setVelocity [_ran15,_ran15,-20];
  133.  
  134. waitUntil{sleep 1; getpos _crashwreck select 2 <= 10};
  135.  
  136. _crashwreck setdamage 1;
  137. };
  138.  
  139. waitUntil{sleep 1; getpos _crashwreck select 2 <= 5};
  140.  
  141. diag_log(format["CRASHSPAWNER: %1 just exploded at %2!", _crashName, getpos _crashwreck]);
  142.  
  143. _pos = [getpos _crashwreck select 0, getpos _crashwreck select 1,0];
  144. _dir = getdir _crashwreck;
  145. heliCrash = _pos;
  146. publicVariable "heliCrash";
  147. deletevehicle _crashwreck;
  148. deletevehicle _helipilot;
  149. deletevehicle _landingzone;
  150.  
  151. _crash = createVehicle [_crashModel, _pos, [], 0, "CAN_COLLIDE"];
  152.  
  153. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_crash];
  154.  
  155. if (_spawnFire) then
  156. {
  157. PVDZE_obj_Fire = [_crash,2,time,false,_fadeFire];
  158. publicVariable "PVDZE_obj_Fire";
  159. _crash setVariable ["fadeFire",_fadeFire,true];
  160. };
  161.  
  162. _num = round(random _randomizedLoot) + _guaranteedLoot;
  163.  
  164. if (DZE_MissionLootTable) then {
  165. _itemTypes = [] + getArray(missionConfigFile >> "CfgBuildingLoot" >> _lootTable >> "lootType");
  166. } else {
  167. _itemTypes = [] + getArray(configFile >> "CfgBuildingLoot" >> _lootTable >> "lootType");
  168. };
  169. _CBLBase = dayz_CBLBase find(toLower(_lootTable));
  170. _weights = dayz_CBLChances select _CBLBase;
  171. _cntWeights = count _weights;
  172.  
  173. for "_x" from 1 to _num do
  174. {
  175. _maxLootRadius = (random _maxLootRadius) + _minLootRadius;
  176. _lootPos = [_pos, _maxLootRadius, random 360] call BIS_fnc_relPos;
  177. _index1 = floor(random _cntWeights);
  178. _index2 = _weights select _index1;
  179. _itemType = _itemTypes select _index2;
  180.  
  181. [_itemType select 0, _itemType select 1, _lootPos, 5] call spawn_loot;
  182.  
  183. diag_log(format["CRASHSPAWNER: Loot spawn at '%1' with loot table '%2'", _lootPos, _lootTable]);
  184.  
  185. _nearby = _pos nearObjects ["ReammoBox", sizeOf(_crashModel)];
  186. {
  187. _x setVariable ["permaLoot",true];
  188. } forEach _nearBy;
  189. };
  190.  
  191. _endTime = time - _startTime;
  192.  
  193. [nil,nil,rTitleText,format["O %1 caiu, va procurar o loot!",_porh], "PLAIN",10] call RE;
  194.  
  195. _event_marker = createMarker [ format ["loot_event_marker_%1", _startTime], _position];
  196. _event_marker setMarkerShape "ELLIPSE";
  197. _event_marker setMarkerColor "ColorYellow";
  198. _event_marker setMarkerAlpha 0.5;
  199. _event_marker setMarkerSize [(_markerRadius + 50), (_markerRadius + 50)];
  200.  
  201. _loot_pos = [_position,0,(_markerRadius - 100),10,0,2000,0] call BIS_fnc_findSafePos;
  202.  
  203. diag_log(format["CRASHSPAWNER: Crash completed! Wreck at: %2 - Runtime: %1 Seconds || Distance from calculated POC: %3 meters", round(_endTime), str(getPos _crash), round(_position distance _crash)]);
  204. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement