Advertisement
Guest User

Untitled

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