Advertisement
Guest User

Untitled

a guest
Nov 11th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.19 KB | None | 0 0
  1.  
  2. //TO SET THIS UP FOLLOW MY INSTRUCTIONS ON OPEN DAYZ
  3. private["_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"];
  4.  
  5. _guaranteedLoot = 7;
  6. _randomizedLoot = 5;
  7. _frequency = 700;
  8. _variance = 0;
  9. _spawnChance = 0.99;
  10. _spawnMarker = 'center';
  11. _spawnRadius = 4000;
  12. _spawnFire = true;
  13. _fadeFire = false;
  14. _useStatic = false;
  15. _preWaypoints = 1;
  16. _crashDamage = 1;
  17.  
  18. diag_log(format["C130CRASHSPAWNER: Starting spawn logic for animated helicrashs - written by Grafzahl [SC:%1||PW:%2||CD:%3]", str(_useStatic), str(_preWaypoints), _crashDamage]);
  19.  
  20. while {true} do {
  21. private["_timeAdjust","_timeToSpawn","_spawnRoll","_crash","_hasAdjustment","_newHeight","_adjustedPos"];
  22. // Allows the variance to act as +/- from the spawn frequency timer
  23. _timeAdjust = round(random(_variance * 2) - _variance);
  24. _timeToSpawn = time + _frequency + _timeAdjust;
  25.  
  26. //Random Heli-Type
  27. _heliModel = ["C130J"] call BIS_fnc_selectRandom;
  28.  
  29. //Random-Startpositions, Adjust this for other Maps then Chernarus
  30. _heliStart = [[6993.7007,173.05298,300],[1623.715,218.18848,300]] call BIS_fnc_selectRandom;
  31.  
  32. //A Backup Waypoint, if not Chernarus, set some Coordinates far up in the north (behind all possible Crashsites)
  33. _safetyPoint = [7492.6675, 15263.042];
  34.  
  35. //Settings for the Standard UH1H_DZ
  36. _crashModel = "C130JWreck";
  37. _exploRange = 195;
  38. _lootRadius = 0.55;
  39.  
  40. //Adjust Wreck and Range of Explosion if its a Mi17_DZ
  41. if(_heliModel == "Mi17_DZ") then {
  42. _crashModel = "Mi8Wreck";
  43. _exploRange = 285;
  44. _lootRadius = 0.3;
  45. };
  46.  
  47. //Crash loot - just uncomment the one you wish to use by default with 50cals is enabled.
  48. //Table including 50 cals
  49. _lootTable = ["HeliCrash"] call BIS_fnc_selectRandom;
  50.  
  51. //Table without 50 cals
  52. //_lootTable = ["Military","HeliCrash_No50s","MilitarySpecial"] call BIS_fnc_selectRandom;
  53.  
  54. _crashName = getText (configFile >> "CfgVehicles" >> _heliModel >> "displayName");
  55.  
  56. diag_log(format["C130CRASHSPAWNER: %1%2 chance to start a crashing %3 with loot table '%4' at %5", round(_spawnChance * 100), '%', _crashName, _lootTable, _timeToSpawn]);
  57.  
  58. // Apprehensive about using one giant long sleep here given server time variances over the life of the server daemon
  59. while {time < _timeToSpawn} do {
  60. sleep 5;
  61. };
  62.  
  63. _spawnRoll = random 1;
  64.  
  65. // Percentage roll
  66. if (_spawnRoll <= _spawnChance) then {
  67.  
  68. /*
  69. ==================================================================================================
  70. _staticcoords give you the possibility to organize your crashsites!
  71.  
  72. IT IS RECOMENDED THAT YOU USE STATIC - CO-ORDS, AND KEEP THEM A GOOD DISTANCE FROM WATER, OTHERWISE YOUR C130 COULD
  73. END UP UNDER THE WATER
  74.  
  75. SET AS MANY AS YOU WANT, THESE WONT BE ACCURATE, BUT CLOSE
  76. ==================================================================================================
  77. */
  78.  
  79. _staticcoords = [
  80. [4516.49,3296.73,3.68049],
  81. [4921.93,5148.96,31.5836],
  82. [6457.06,5190.83,114.982],
  83. [6909.84,3491.64,71.644],
  84. [5263.36,6200.04,106.836],
  85. [5191.33,4356.68,131.633]
  86. ];
  87.  
  88. if(_useStatic) then {
  89. _position = _staticcoords call BIS_fnc_selectRandom;
  90. } else {
  91. _position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,2000,0] call BIS_fnc_findSafePos;
  92. };
  93. //DEFAULT: GET COORDS FROM BIS_fnc_findSafePos, COMMENT OUT IF YOU USE _STATICCOORDS
  94.  
  95. diag_log(format["C130StartCRASHSPAWNER: %1 started flying from %2 to %3 NOW!(TIME:%4||LT:%5)", _crashName, str(_heliStart), str(_position), round(time), _lootTable]);
  96.  
  97. //Spawn the AI-Heli flying in the air
  98. _startTime = time;
  99. _crashwreck = createVehicle [_heliModel,_heliStart, [], 0, "FLY"];
  100.  
  101. //Make sure its not destroyed by the Hacker-Killing-Cleanup (Thanks to Sarge for the hint)
  102. _crashwreck setVariable["Sarge",1];
  103.  
  104. _crashwreck engineOn true;
  105. _crashwreck flyInHeight 120;
  106. _crashwreck forceSpeed 140;
  107. _crashwreck setspeedmode "LIMITED";
  108.  
  109. //Create an Invisibile Landingpad at the Crashside-Coordinates
  110. _landingzone = createVehicle ["HeliHEmpty", [_position select 0, _position select 1,0], [], 0, "CAN_COLLIDE"];
  111. _landingzone setVariable["Sarge",1];
  112.  
  113. //Only a Woman could crash a Heli this way...
  114. _aigroup = creategroup civilian;
  115. _helipilot = _aigroup createUnit ["SurvivorW2_DZ",getPos _crashwreck,[],0,"FORM"];
  116. _helipilot moveindriver _crashwreck;
  117. _helipilot assignAsDriver _crashwreck;
  118.  
  119. sleep 0.5;
  120.  
  121. if(_preWaypoints > 0) then {
  122. for "_x" from 1 to _preWaypoints do {
  123. if(_useStatic) then {
  124. _preWaypointPos = _staticcoords call BIS_fnc_selectRandom;
  125. } else {
  126. _preWaypointPos = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,2000,0] call BIS_fnc_findSafePos;
  127. };
  128. diag_log(format["C130CRASHSPAWNER: Adding Pre-POC-Waypoint #%1 on %2", _x,str(_preWaypointPos)]);
  129. _wp = _aigroup addWaypoint [_preWaypointPos, 0];
  130. _wp setWaypointType "MOVE";
  131. _wp setWaypointBehaviour "CARELESS";
  132. };
  133. };
  134.  
  135. _wp2 = _aigroup addWaypoint [position _landingzone, 0];
  136. _wp2 setWaypointType "MOVE";
  137. _wp2 setWaypointBehaviour "CARELESS";
  138.  
  139. //Even when the Heli flys to high, it will burn when reaching its Waypoint
  140. _wp2 setWaypointStatements ["true", "_crashwreck setdamage 1;"];
  141.  
  142. //Adding a last Waypoint up in the North, so the Heli doesnt Hover at WP1 (OR2)
  143. //and would also come back to WP1 if somehow it doesnt explode.
  144. _wp3 = _aigroup addWaypoint [_safetyPoint, 0];
  145. _wp3 setWaypointType "CYCLE";
  146. _wp3 setWaypointBehaviour "CARELESS";
  147.  
  148. //Get some more Speed when close to the Crashpoint and go on even if Heli died or hit the ground
  149. waituntil {(_crashwreck distance _position) <= 1000 || not alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  150. _crashwreck flyInHeight 95;
  151. _crashwreck forceSpeed 80;
  152. _crashwreck setspeedmode "NORMAL";
  153.  
  154. //BOOOOOOM!
  155. waituntil {(_crashwreck distance _position) <= _exploRange || not alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  156. //Taking out the Tailrotor would be more realistic, but makes the POC not controllable
  157. //_crashwreck setHit ["mala vrtule", 1];
  158. _crashwreck setdamage 1;
  159. _crashwreck setfuel 0;
  160. diag_log(format["C130EndCRASHSPAWNER: %1 just exploded at %2!, ", _crashName, str(getPosATL _crashwreck)]);
  161.  
  162. //She cant survive this :(
  163. _helipilot setdamage 1;
  164.  
  165. //Giving the crashed Heli some time to find its "Parkingposition"
  166. sleep 13;
  167.  
  168. //Get position of the helis wreck, but make sure its on the ground;
  169. _pos = [getpos _crashwreck select 0, getpos _crashwreck select 1,0];
  170. _landedPos = [getpos _crashwreck select 0, getpos _crashwreck select 1];
  171.  
  172. //saving the direction of the wreck(not used right now)
  173. _dir = getdir _crashwreck;
  174.  
  175. //Send Public Variable so every client can delete the craters around the new Wreck (musst be added in init.sqf)
  176. heliCrash = _pos;
  177. publicVariable "heliCrash";
  178.  
  179. //Clean Up the Crashsite
  180. deletevehicle _crashwreck;
  181. deletevehicle _helipilot;
  182. deletevehicle _landingzone;
  183.  
  184. //Animation is done, lets create the actual Crashside
  185. _crash = createVehicle [_crashModel, _pos, [], 0, "CAN_COLLIDE"];
  186. _crash setVariable["Sarge",1];
  187.  
  188. //If you want all Grass around the crashsite to be cutted: Uncomment the next Line (Noobmode)
  189. //_crashcleaner = createVehicle ["ClutterCutter_EP1", _pos, [], 0, "CAN_COLLIDE"];
  190.  
  191. //Setting the Direction would add realism, but it sucks because of the bugged model when not on plane ground.
  192. //If you want it anyways, just uncomment the next line
  193. //_crash setDir _dir;
  194.  
  195. // I don't think this is needed (you can't get "in" a crash), but it was in the original DayZ Crash logic
  196. dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_crash];
  197.  
  198. _crash setVariable ["ObjectID",1,true];
  199.  
  200. //Make it burn (or not)
  201. if (_spawnFire) then {
  202. //["dayzFire",[_crash,2,time,false,_fadeFire]] call broadcastRpcCallAll;
  203. dayzFire = [_crash,2,time,false,_fadeFire];
  204. publicVariable "dayzFire";
  205. _crash setvariable ["fadeFire",_fadeFire,true];
  206. };
  207.  
  208. _num = round(random _randomizedLoot) + _guaranteedLoot;
  209.  
  210. _config = configFile >> "CfgBuildingLoot" >> _lootTable;
  211. _itemTypes = [] + getArray (_config >> "itemType");
  212. _cntItems = count _itemTypes;
  213. diag_log(format["C130CRASHSPAWNER: numLoot: '%1', _index: '%2', _weights: '%3', _cntItemTypes: '%4', config: '%5'", str(_num), str(_index), str(_weights), str(_cntItems), str(_config)]);
  214.  
  215. for "_x" from 1 to _num do {
  216. //create loot
  217. _index = floor(random _cntItems);
  218. _itemType = _itemTypes select _index;
  219. [_itemType select 0, _itemType select 1, _landedPos, 5] call spawn_loot;
  220.  
  221. diag_log(format["CRASHSPAWNER: Loot Table: '%1', ItemTypes: '%2', Index: '%3', ItemType: '%4', Item: '%5'", _lootTable, str(_itemTypes), str(_index), str(_itemType), str(_itemType select 0)]);
  222.  
  223. // ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 and other such items.
  224. _nearby = _landedPos nearObjects ["ReammoBox", sizeOf(_crashModel)];
  225. {
  226. _x setVariable ["permaLoot",true];
  227. } forEach _nearBy;
  228. };
  229.  
  230. //Adding 5 dead soldiers around the wreck, poor guys
  231. for "_x" from 1 to 5 do {
  232. _lootPos = [_pos, ((random 4)+3), random 360] call BIS_fnc_relPos;
  233. _deadBody = createVehicle[["Body1","Body2"] call BIS_fnc_selectRandom,_lootPos,[], 0, "CAN_COLLIDE"];
  234. _deadBody setDir (random 360);
  235. };
  236.  
  237. _endTime = time - _startTime;
  238. diag_log(format["C130CRASHSPAWNER: Crash completed! Wreck at: %2 - Runtime: %1 Seconds || Distance from calculated POC: %3 meters", round(_endTime), str(getPos _crash), round(_position distance _crash)]);
  239.  
  240.  
  241. };
  242. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement