daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Author: Glowbal
  3.  * Detonates ammunition from a vehicle until no ammo left
  4.  *
  5.  * Arguments:
  6.  * 0: vehicle <OBJECT>
  7.  * 1: Ammo Array <ARRAY>
  8.  *      0: Magazine Classname <STRING>
  9.  *      1: Ammo Count <NUMBER>
  10.  * 2: Total Ammo Count <NUMBER>
  11.  *
  12.  * Return Value:
  13.  * None
  14.  *
  15.  * Example:
  16.  * [_vehicle, magazinesAmmo _vehicle] call ace_cookoff_fnc_detonateAmmunition
  17.  *
  18.  * Public: No
  19.  */
  20. #include "script_component.hpp"
  21. #define MAX_TIME_BETWEEN_AMMO_DET 25
  22.  
  23. params ["_vehicle", "_magazines", "_totalAmmo"];
  24.  
  25. if (isNull _vehicle) exitWith {}; // vehicle got deleted
  26. if (_magazines isEqualTo []) exitWith {}; // nothing to detonate anymore
  27. if (underwater _vehicle) exitWith {};
  28.  
  29. private _magazineIndex = floor random(count _magazines);
  30. private _magazine = _magazines select _magazineIndex;
  31. _magazine params ["_magazineClassname", "_amountOfMagazines"];
  32.  
  33. if (_amountOfMagazines > 0) exitWith {
  34.     private _removed = _amountOfMagazines min floor(1 + random(6 / GVAR(ammoCookoffDuration)));
  35.  
  36.     _amountOfMagazines = _amountOfMagazines - _removed;
  37.     if (_amountOfMagazines <= 0) then {
  38.         _magazines deleteAt _magazineIndex;
  39.     } else {
  40.         _magazine set [1, _amountOfMagazines]; // clear out the magazine
  41.     };
  42.     private _timeBetweenAmmoDetonation = (((random 10) / (sqrt _totalAmmo)) min MAX_TIME_BETWEEN_AMMO_DET) max 0.1;
  43.     TRACE_2("",_totalAmmo,_timeBetweenAmmoDetonation);
  44.     _totalAmmo = _totalAmmo - _removed;
  45.  
  46.     private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "ammo");
  47.     private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;
  48.  
  49.     private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
  50.     private _simType = getText (_ammoCfg >> "simulation");
  51.  
  52.     private _effect2pos = _vehicle selectionPosition "destructionEffect2";
  53.  
  54.     private _spawnProjectile = {
  55.         params ["_vehicle", "_ammo", "_speed", "_flyAway"];
  56.  
  57.         private _spawnPos = _vehicle modelToWorld [-0.2 + (random 0.4), -0.2 + (random 0.4), random 3];
  58.         if (_spawnPos select 2 < 0) then {
  59.             _spawnPos set [2, 0];
  60.         };
  61.  
  62.         private _projectile = createVehicle [_ammo, _spawnPos, [], 0, "CAN_COLLIDE"];
  63.         if (_flyAway) then {
  64.             //private _vectorAmmo = [(-1 + (random 2)), (-1 + (random 2)), -0.2 + (random 1)];
  65.             //private _velVec = _vectorAmmo vectorMultiply _speed;
  66.             //_projectile setVectorDir _velVec;
  67.             //_projectile setVelocity _velVec;
  68.             _projectile setDamage 1;  //no Glowbal, just no
  69.         } else {
  70.             _projectile setDamage 1;
  71.         };
  72.  
  73.         _projectile;
  74.     };
  75.  
  76.     private _speed = random (_speedOfAmmo / 10) max 1;
  77.  
  78.     if (toLower _simType == "shotbullet") then {
  79.         private _sound = selectRandom [QUOTE(PATHTO_R(sounds\light_crack_close.wss)), QUOTE(PATHTO_R(sounds\light_crack_close_filtered.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close_filtered.wss))];
  80.         playSound3D [_sound, objNull, false, (getPosASL _vehicle), 2, 1, 1250];
  81.  
  82.         if (random 1 < 0.6) then {
  83.             [_vehicle, _ammo, _speed, true] call _spawnProjectile;
  84.         };
  85.     };
  86.     if (toLower _simType == "shotshell") then {
  87.         private _sound = selectRandom [QUOTE(PATHTO_R(sounds\heavy_crack_close.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close_filtered.wss))];
  88.         playSound3D [_sound, objNull, false, (getPosASL _vehicle), 2, 1, 1300];
  89.  
  90.         if (random 1 < 0.15) then {
  91.             [_vehicle, _ammo, _speed, random 1 < 0.15] call _spawnProjectile;
  92.         };
  93.     };
  94.     if (toLower _simType == "shotgrenade") then {
  95.         if (random 1 < 0.9) then {
  96.             _speed = 0;
  97.         };
  98.         [_vehicle, _ammo, _speed, random 1 < 0.5] call _spawnProjectile;
  99.     };
  100.     if (toLower _simType in ["shotrocket", "shotmissile", "shotsubmunitions"]) then {
  101.         if (random 1 < 0.1) then {
  102.             private _sound = selectRandom [QUOTE(PATHTO_R(sounds\cannon_crack_close.wss)), QUOTE(PATHTO_R(sounds\cannon_crack_close_filtered.wss))];
  103.             playSound3D [_sound, objNull, false, (getPosASL _vehicle), 3, 1, 1600];
  104.  
  105.             [_vehicle, _ammo, _speed, random 1 < 0.3] call _spawnProjectile;
  106.         } else {
  107.             createvehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld _effect2pos), [], 0 , "CAN_COLLIDE"];
  108.         };
  109.     };
  110.     if (toLower _simType in ["shotdirectionalbomb", "shotmine"]) then {
  111.         if (random 1 < 0.5) then {
  112.             // Not all explosives detonate on destruction, some have scripted alternatives
  113.             private _scripted = getNumber (_ammoCfg >> "triggerWhenDestroyed") == 1;
  114.             if !(_scripted) then {
  115.                 _ammo = getText (_ammoCfg >> "ace_explosives_Explosive");
  116.             };
  117.  
  118.             // If a scripted alternative doesn't exist use generic explosion
  119.             if (_ammo != "") then {
  120.                 [_vehicle, _ammo, 0, false] call _spawnProjectile;
  121.             } else {
  122.                 createvehicle ["SmallSecondary", (_vehicle modelToWorld _effect2pos), [], 0 , "CAN_COLLIDE"];
  123.             };
  124.         };
  125.     };
  126.     if (toLower _simType == "shotilluminating") then {
  127.         if (random 1 < 0.15) then {
  128.             [_vehicle, _ammo, _speed, random 1 < 0.3] call _spawnProjectile;
  129.         };
  130.     };
  131.  
  132.     [FUNC(detonateAmmunition), [_vehicle, _magazines, _totalAmmo], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute;
  133. };
  134. ERROR_1("mag with no ammo - %1", _magazine);
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top