Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.22 KB | None | 0 0
  1. /*
  2. Script Name: animated_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.2
  7. */
  8.  
  9. private["_show_name","_show_marker", "_finder","_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","_mdot","_position","_num","_config","_itemType","_itemChance","_weights","_index","_iArray","_crashModel","_lootTable","_guaranteedLoot","_randomizedLoot","_frequency","_variance","_spawnChance","_spawnMarker","_spawnRadius","_spawnFire","_permanentFire","_crashName","_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 = 1; // 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 = 200; // 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 = 200; // Radius for the marker
  23. _show_marker = true; // Show a marker on the map
  24. _show_name = true; // Add the crashname to the marker
  25.  
  26. /* do not change below values if you do not know what you are doing */
  27. _plane = false;
  28. _spawnMarker = "center";
  29. _heliModel = ["UH1Y_DZE"/* ,"UH1H_DZE","MV22","Mi17_DZ","UH60M_EP1","UH1H_TK_EP1","UH60M_EP1","UH1H_TK_EP1","UH60M_MEV_EP1","A10","Ka52Black","Mi24_D","AH1Z","AV8B","Su25_TK_EP1"*/] call BIS_fnc_selectRandom;
  30. _crashModel = "UH1Wreck_DZ";
  31. _spawnRadius = HeliCrashArea;
  32. _heliStart = [[1000.0,2.0],[3500.0,2.0],[5000.0,2.0],[7500.0,2.0],[9712.0,663.067],[12304.0,1175.07],[14736.0,2500.0],[16240.0,5000.0],[16240.0,7500.0],[16240.0,10000.0]] call BIS_fnc_selectRandom;
  33. _porh = "helicopter";
  34. _safetyPoint = [0,16000,0];
  35. _crashName = getText (configFile >> "CfgVehicles" >> _heliModel >> "displayName");
  36. _spawnRoll = round(random 100);
  37.  
  38. _finder = "";
  39.  
  40. if(_heliModel == "UH1Y_DZE") then {
  41. _lootTable = "MilitarySpecial";
  42. _crashModel = "UH1Wreck_DZ";
  43. _plane = true;
  44. _guaranteedLoot = 10;
  45. };
  46. /*
  47. if(_heliModel == "Su25_TK_EP1") then {
  48. _lootTable = "MilitarySpecial";
  49. _crashModel = "SU25Wreck";
  50. _plane = true;
  51. _guaranteedLoot = 4;
  52. };
  53.  
  54. if(_heliModel == "AV8B") then {
  55. _lootTable = "MilitarySpecial";
  56. _crashModel = "AV8BWreck";
  57. _plane = true;
  58. _guaranteedLoot = 5;
  59. };
  60.  
  61. if(_heliModel == "AH1Z") then {
  62. _lootTable = "MilitarySpecial";
  63. _crashModel = "AH1ZWreck";
  64. _guaranteedLoot = 4;
  65. };
  66.  
  67. if(_heliModel == "Mi24_D") then {
  68. _lootTable = "MilitarySpecial";
  69. _crashModel = "Mi24Wreck";
  70. _guaranteedLoot = 5;
  71. };
  72.  
  73. if(_heliModel == "Ka52Black") then {
  74. _lootTable = "MilitarySpecial";
  75. _crashModel = "Ka52Wreck";
  76. _guaranteedLoot = 3;
  77. };
  78.  
  79. if(_heliModel == "Mi17_DZ") then {
  80. _crashModel = "Mi8Wreck";
  81. };
  82.  
  83. if(_heliModel == "UH60M_EP1") then {
  84. _crashModel = "UH60Wreck_DZ";
  85. };
  86.  
  87. if(_heliModel == "A10") then {
  88. _lootTable = "MilitarySpecial";
  89. _crashModel = "A10Wreck";
  90. _plane = true;
  91. _guaranteedLoot = 2;
  92. };
  93.  
  94. if(_heliModel == "MV22") then {
  95. _lootTable = "Hospital";
  96. _crashModel = "MV22Wreck";
  97. _plane = true;
  98. _guaranteedLoot = 24;
  99. };
  100.  
  101. if(_heliModel == "UH60M_MEV_EP1") then {
  102. _lootTable = "Hospital";
  103. _crashModel = "UH60Wreck_DZ";
  104. _guaranteedLoot = 16;
  105. };
  106. */
  107.  
  108. diag_log(format["CRASHSPAWNER: %1%2 chance to start a crashing %3 with loot table '%4'", _spawnChance, '%', _crashName, _lootTable]);
  109.  
  110. if (_spawnRoll <= _spawnChance) then
  111. {
  112.  
  113. if(_plane) then {
  114. _porh = "plane";
  115. };
  116.  
  117. //[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;
  118.  
  119. _position = [getMarkerPos _spawnMarker,0,_spawnRadius,10,0,2000,0] call BIS_fnc_findSafePos;
  120.  
  121. diag_log(format["CRASHSPAWNER: %1 started flying from %2 to %3 NOW!(TIME:%4||LT:%5)", _crashName, str(_heliStart), str(_position), round(time), _lootTable]);
  122.  
  123. _startTime = time;
  124. _crashwreck = createVehicle [_heliModel,_heliStart, [], 0, "FLY"];
  125. _crashwreck setCombatMode "BLUE";
  126. _crashwreck engineOn true;
  127. _crashwreck flyInHeight 150;
  128.  
  129. if (_plane) then
  130. {
  131. _crashDamage = .5;
  132. _crashwreck setDamage .4;
  133. _crashwreck forceSpeed 250;
  134. _crashwreck setspeedmode "LIMITED";
  135. }
  136. else
  137. {
  138. _crashwreck forceSpeed 150;
  139. _crashwreck setspeedmode "NORMAL";
  140. };
  141.  
  142. _landingzone = createVehicle ["HeliHEmpty", [_position select 0, _position select 1,0], [], 0, "CAN_COLLIDE"];
  143. _aigroup = creategroup civilian;
  144. _helipilot = _aigroup createUnit ["SurvivorW2_DZ",getPos _crashwreck,[],0,"FORM"];
  145. _helipilot setCombatMode "BLUE";
  146. _helipilot moveindriver _crashwreck;
  147. _helipilot assignAsDriver _crashwreck;
  148.  
  149. sleep 0.5;
  150.  
  151. if(_preWaypoints > 0) then
  152. {
  153. for "_x" from 1 to _preWaypoints do
  154. {
  155. _preWaypointPos = [getMarkerPos _spawnMarker, 0, _spawnRadius, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
  156. _wp = _aigroup addWaypoint [_preWaypointPos, 0];
  157. _wp setWaypointType "MOVE";
  158. _wp setWaypointBehaviour "CARELESS";
  159. };
  160. };
  161.  
  162. _wp2 = _aigroup addWaypoint [position _landingzone, 0];
  163. _wp2 setWaypointType "MOVE";
  164. _wp2 setWaypointBehaviour "CARELESS";
  165. _wp2 setWaypointStatements ["true", "_crashwreck setdamage 1;"];
  166. _wp3 = _aigroup addWaypoint [_safetyPoint, 0];
  167. _wp3 setWaypointType "CYCLE";
  168. _wp3 setWaypointBehaviour "CARELESS";
  169.  
  170. waituntil {(_crashwreck distance _position) <= 1000 || !alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  171.  
  172. if (_plane) then
  173. {
  174. _crashwreck flyInHeight 100;
  175. _crashwreck forceSpeed 150;
  176. _crashwreck setspeedmode "NORMAL";
  177. _exploRange = 360;
  178. }
  179. else
  180. {
  181. _crashwreck flyInHeight 100;
  182. _crashwreck forceSpeed 100;
  183. _crashwreck setspeedmode "NORMAL";
  184. };
  185.  
  186. waituntil {(_crashwreck distance _position) <= _exploRange || !alive _crashwreck || (getPosATL _crashwreck select 2) < 5 || (damage _crashwreck) >= _crashDamage};
  187.  
  188. deletevehicle _helipilot;
  189.  
  190. if (_plane) then
  191. {
  192. _crashwreck setdamage 1;
  193. _vel = velocity _crashwreck;
  194. _dir = direction _crashwreck;
  195. _speed = 100;
  196. _crashwreck setVelocity [(_vel select 0)-(sin _dir*_speed),(_vel select 1)-(cos _dir*_speed),(_vel select 2) - 30];
  197. }
  198. else
  199. {
  200. _crashwreck setHit ["mala vrtule", 1];
  201. _ran15 = random 15;
  202. _crashwreck setVelocity [_ran15,_ran15,-25];
  203. _crashwreck setdamage .9;
  204.  
  205. waitUntil{sleep 1; getpos _crashwreck select 2 <= 30};
  206.  
  207. _helipilot setdamage 1;
  208. _crashwreck setVelocity [_ran15,_ran15,-20];
  209.  
  210. waitUntil{sleep 1; getpos _crashwreck select 2 <= 10};
  211.  
  212. _crashwreck setdamage 1;
  213. };
  214.  
  215. waitUntil{sleep 1; getpos _crashwreck select 2 <= 5};
  216.  
  217. diag_log(format["CRASHSPAWNER: %1 just exploded at %2!", _crashName, getpos _crashwreck]);
  218.  
  219. _pos = [getpos _crashwreck select 0, getpos _crashwreck select 1,0];
  220. _dir = getdir _crashwreck;
  221.  
  222. deletevehicle _crashwreck;
  223. deletevehicle _landingzone;
  224.  
  225. _isWater = surfaceIsWater [getpos _crashwreck select 0, getpos _crashwreck select 1];
  226.  
  227. if(_isWater) then {
  228.  
  229. [nil,nil,rTitleText,format["O HeliCrash caiu na agua!",_porh], "PLAIN",10] call RE;
  230.  
  231. }
  232. else
  233. {
  234.  
  235. _crash = createVehicle [_crashModel, _pos, [], 0, "CAN_COLLIDE"];
  236. _crash setDir _dir;
  237.  
  238. PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_crash];
  239.  
  240. if (_spawnFire) then
  241. {
  242. PVDZE_obj_Fire = [_crash, 4, time, false, _fadeFire];
  243. publicVariable "PVDZE_obj_Fire";
  244. };
  245.  
  246. _num = round(random _randomizedLoot) + _guaranteedLoot;
  247.  
  248. if (DZE_MissionLootTable) then {
  249. _itemTypes = [] + getArray(missionConfigFile >> "CfgBuildingLoot" >> _lootTable >> "lootType");
  250. } else {
  251. _itemTypes = [] + getArray(configFile >> "CfgBuildingLoot" >> _lootTable >> "lootType");
  252. };
  253. _CBLBase = dayz_CBLBase find(toLower(_lootTable));
  254. _weights = dayz_CBLChances select _CBLBase;
  255. _cntWeights = count _weights;
  256.  
  257. for "_x" from 1 to _num do
  258. {
  259. _maxLootRadius = (random _maxLootRadius) + _minLootRadius;
  260. _lootPos = [_pos, _maxLootRadius, random 360] call BIS_fnc_relPos;
  261. _index1 = floor(random _cntWeights);
  262. _index2 = _weights select _index1;
  263. _itemType = _itemTypes select _index2;
  264.  
  265. [_itemType select 0, _itemType select 1, _lootPos, 5] call spawn_loot;
  266.  
  267. diag_log(format["CRASHSPAWNER: Loot spawn at '%1' with loot table '%2'", _lootPos, _lootTable]);
  268.  
  269. _nearby = _pos nearObjects ["ReammoBox", sizeOf(_crashModel)];
  270. {
  271. _x setVariable ["permaLoot",true];
  272. } forEach _nearBy;
  273. };
  274.  
  275. _endTime = time - _startTime;
  276.  
  277. //[nil,nil,rTitleText,format["O Helicrash caiu va procurar por loot!!",_porh], "PLAIN",10] call RE;
  278.  
  279. diag_log(format["CRASHSPAWNER: Crash completed! Wreck at: %2 - Runtime: %1 Seconds || Distance from calculated POC: %3 meters", round(_endTime), str(_pos), round(_position distance _crash)]);
  280.  
  281. if(_show_marker) then {
  282.  
  283. _marker_position = [_pos,0,_markerRadius,0,1,2000,0] call BIS_fnc_findSafePos;
  284. _marker = createMarker [ format ["loot_event_marker_%1", _startTime], _marker_position];
  285. _marker setMarkerShape "ELLIPSE";
  286. _marker setMarkerColor "ColorBlue";
  287. _marker setMarkerAlpha 0.5;
  288. _marker setMarkerSize [(_markerRadius + 50), (_markerRadius + 50)];
  289. _marker setMarkerText _crashName;
  290.  
  291. if(_show_name) then {
  292.  
  293. _mdot = createMarker [format ["dot_%1", _startTime], _marker_position];
  294. _mdot setMarkerColor "ColorBlack";
  295. _mdot setMarkerType "mil_dot";
  296. _mdot setMarkerText _crashName;
  297.  
  298. };
  299.  
  300. };
  301.  
  302. waitUntil
  303. {
  304. sleep 5;
  305. _playerPresent = false;
  306. {
  307. if((isPlayer _x) && (_x distance _pos <= 25)) then {
  308. _playerPresent = true;
  309. _finder = name _x;
  310. };
  311.  
  312. } foreach playableUnits;
  313.  
  314. (_playerPresent)
  315. };
  316.  
  317. [nil,nil,rTitleText,format["O HeliCrash foi capturado por %1!", _finder], "PLAIN",10] call RE;
  318.  
  319. if(_show_marker) then {
  320.  
  321. deleteMarker _marker;
  322.  
  323. if(_show_name) then {
  324. deleteMarker _mdot;
  325. };
  326.  
  327. };
  328.  
  329. diag_log(format["CRASHSPAWNER: Crash found by %1, removing the marker" , _finder]);
  330.  
  331. };
  332.  
  333. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement