Guest User

Untitled

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