mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Cookoff - add function to get ammo (#4779)
* Cookoff - add function to get ammo Fix #4565 - Function adds virtual ammo for rearm vehicles Remove FUNC(secondaryExplosions) - which duplicatd detonateAmunition Tweak timeBetweenAmmoDetonation calculation to use all ammo, not just the current mag Allow GVAR(enableAmmoCookoff) effect to work with GVAR(enable)=false * Fix header * Cleanup getting ammo from turrets
This commit is contained in:
parent
0046ba4bbb
commit
bce0913019
@ -4,5 +4,5 @@ PREP(engineFire);
|
||||
PREP(cookOff);
|
||||
PREP(cookOffBox);
|
||||
PREP(blowOffTurret);
|
||||
PREP(secondaryExplosions);
|
||||
PREP(detonateAmmunition);
|
||||
PREP(getVehicleAmmo);
|
||||
|
@ -80,11 +80,9 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace;
|
||||
// secondary explosions
|
||||
["AllVehicles", "killed", {
|
||||
params ["_vehicle"];
|
||||
if (_vehicle getVariable [QGVAR(enable),GVAR(enable)]) then {
|
||||
_vehicle call FUNC(secondaryExplosions);
|
||||
if (_vehicle getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmoCookoff)]) then {
|
||||
[_vehicle, magazinesAmmo _vehicle] call FUNC(detonateAmmunition);
|
||||
};
|
||||
if (_vehicle getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmoCookoff)]) then {
|
||||
([_vehicle] call FUNC(getVehicleAmmo)) params ["_mags", "_total"];
|
||||
[_vehicle, _mags, _total] call FUNC(detonateAmmunition);
|
||||
};
|
||||
}, nil, ["Man","StaticWeapon"]] call CBA_fnc_addClassEventHandler;
|
||||
|
||||
|
@ -44,9 +44,9 @@ if (local _box) then {
|
||||
|
||||
// These functions are smart and do all the cooking off work
|
||||
if (local _box) then {
|
||||
_box call FUNC(secondaryExplosions);
|
||||
if (_box getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmoCookoff)]) then {
|
||||
[_box, magazinesAmmo _box] call FUNC(detonateAmmunition);
|
||||
([_box] call FUNC(getVehicleAmmo)) params ["_mags", "_total"];
|
||||
[_box, _mags, _total] call FUNC(detonateAmmunition);
|
||||
};
|
||||
|
||||
// This shit is busy being on fire, magazines aren't accessible/usable
|
||||
|
@ -4,6 +4,10 @@
|
||||
*
|
||||
* Arguments:
|
||||
* 0: vehicle <OBJECT>
|
||||
* 1: Ammo Array <ARRAY>
|
||||
* 0: Magazine Classname <STRING>
|
||||
* 1: Ammo Count <NUMBER>
|
||||
* 2: Total Ammo Count <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
@ -16,7 +20,7 @@
|
||||
#include "script_component.hpp"
|
||||
#define MAX_TIME_BETWEEN_AMMO_DET 25
|
||||
|
||||
params ["_vehicle", "_magazines"];
|
||||
params ["_vehicle", "_magazines", "_totalAmmo"];
|
||||
|
||||
if (isNull _vehicle) exitWith {}; // vehicle got deleted
|
||||
if (_magazines isEqualTo []) exitWith {}; // nothing to detonate anymore
|
||||
@ -27,21 +31,22 @@ private _magazine = _magazines select _magazineIndex;
|
||||
_magazine params ["_magazineClassname", "_amountOfMagazines"];
|
||||
|
||||
if (_amountOfMagazines > 0) exitWith {
|
||||
private _newMagCount = _amountOfMagazines - floor(1 + random(6));
|
||||
if (_newMagCount <= 0) then {
|
||||
private _removed = _amountOfMagazines min floor(1 + random(6));
|
||||
|
||||
_amountOfMagazines = _amountOfMagazines - _removed;
|
||||
if (_amountOfMagazines <= 0) then {
|
||||
_magazines deleteAt _magazineIndex;
|
||||
} else {
|
||||
_magazine set [1, _newMagCount]; // clear out the magazine
|
||||
_magazine set [1, _amountOfMagazines]; // clear out the magazine
|
||||
};
|
||||
private _timeBetweenAmmoDetonation = (random 7) * (1 / random (_amountOfMagazines)) min MAX_TIME_BETWEEN_AMMO_DET;
|
||||
_timeBetweenAmmoDetonation = _timeBetweenAmmoDetonation max 0.1;
|
||||
private _timeBetweenAmmoDetonation = (((random 10) / (sqrt _totalAmmo)) min MAX_TIME_BETWEEN_AMMO_DET) max 0.1;
|
||||
TRACE_2("",_totalAmmo,_timeBetweenAmmoDetonation);
|
||||
_totalAmmo = _totalAmmo - _removed;
|
||||
|
||||
private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "ammo");
|
||||
private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;
|
||||
|
||||
private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
|
||||
private _simulationTime = getNumber (_ammoCfg >> "simulation");
|
||||
private _caliber = getNumber (_ammoCfg >> "caliber");
|
||||
private _simType = getText (_ammoCfg >> "simulation");
|
||||
|
||||
private _effect2pos = _vehicle selectionPosition "destructionEffect2";
|
||||
@ -60,7 +65,7 @@ if (_amountOfMagazines > 0) exitWith {
|
||||
private _velVec = _vectorAmmo vectorMultiply _speed;
|
||||
_projectile setVectorDir _velVec;
|
||||
_projectile setVelocity _velVec;
|
||||
[ACE_player, _projectile, [1,0,0,1]] call EFUNC(frag,addTrack);
|
||||
// [ACE_player, _projectile, [1,0,0,1]] call EFUNC(frag,addTrack); // visual debuging from ace_frag
|
||||
} else {
|
||||
_projectile setDamage 1;
|
||||
};
|
||||
@ -124,6 +129,6 @@ if (_amountOfMagazines > 0) exitWith {
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(detonateAmmunition), [_vehicle, _magazines], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute;
|
||||
[FUNC(detonateAmmunition), [_vehicle, _magazines, _totalAmmo], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute;
|
||||
};
|
||||
[FUNC(detonateAmmunition), [_vehicle, _magazines], random 3] call CBA_fnc_waitAndExecute;
|
||||
ERROR_1("mag with no ammo - %1", _magazine);
|
||||
|
56
addons/cookoff/functions/fnc_getVehicleAmmo.sqf
Normal file
56
addons/cookoff/functions/fnc_getVehicleAmmo.sqf
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Gets all magazines inside of a vehicle.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle <Object>
|
||||
*
|
||||
* Return Value:
|
||||
* 0: Ammo Array <ARRAY>
|
||||
* 0: Magazine Classname <STRING>
|
||||
* 1: Ammo Count <NUMBER>
|
||||
* 1: Total Ammo Count <NUMBER>
|
||||
*
|
||||
* Example:
|
||||
* [vehicle player] call ace_cookoff_fnc_getVehicleAmmo
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_vehicle"];
|
||||
TRACE_1("getVehicleAmmo",_vehicle);
|
||||
|
||||
private _ammoToDetonate = [];
|
||||
private _totalAmmo = 0;
|
||||
|
||||
// Get ammo from turrets
|
||||
{
|
||||
_x params ["_mag", "", "_count"];
|
||||
if (_count > 0) then {
|
||||
_ammoToDetonate pushBack [_mag, _count];
|
||||
_totalAmmo = _totalAmmo + _count;
|
||||
};
|
||||
} forEach (magazinesAllTurrets _vehicle);
|
||||
|
||||
// Get ammo from cargo space
|
||||
{
|
||||
_x params ["_mag", "_count"];
|
||||
if (_count > 0) then {
|
||||
_ammoToDetonate pushBack [_mag, _count];
|
||||
_totalAmmo = _totalAmmo + _count;
|
||||
};
|
||||
} forEach (magazinesAmmoCargo _vehicle);
|
||||
|
||||
// Get ammo from transportAmmo / ace_rearm
|
||||
private _vehCfg = configFile >> "CfgVehicles" >> typeOf _vehicle;
|
||||
if (((getNumber (_vehCfg >> "transportAmmo")) > 1000) || {isClass (_vehCfg >> "ACE_Actions" >> "ACE_MainActions" >> QEGVAR(rearm,TakeAmmo))}) then {
|
||||
TRACE_1("transportAmmo vehicle - adding virtual ammo",typeOf _vehicle);
|
||||
|
||||
_ammoToDetonate pushBack ["2000Rnd_65x39_belt", 2000];
|
||||
_totalAmmo = _totalAmmo + 2000;
|
||||
_ammoToDetonate pushBack ["20Rnd_105mm_HEAT_MP", 100];
|
||||
_totalAmmo = _totalAmmo + 100;
|
||||
};
|
||||
|
||||
[_ammoToDetonate, _totalAmmo]
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Author: Maddmatt, commy2
|
||||
* Generate an amount of secondary explosions
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle <OBJECT>
|
||||
* 1: Amount <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
#define SECONDARIES_DELAY (1 + random 45)
|
||||
|
||||
params ["_vehicle", "_amount"];
|
||||
|
||||
if (isNil "_amount") then {
|
||||
// calculate amount of secondary explosions if not specified
|
||||
_amount = 0;
|
||||
|
||||
{
|
||||
_x params ["_magazine", "_count"];
|
||||
|
||||
private _ammo = getText (_magazine call CBA_fnc_getItemConfig >> "ammo");
|
||||
|
||||
if (IS_EXPLOSIVE_AMMO(_ammo)) then {
|
||||
if (_ammo isKindOf "ShellBase") then {
|
||||
ADD(_amount,_count);
|
||||
} else {
|
||||
ADD(_amount,_count/50);
|
||||
};
|
||||
};
|
||||
} forEach magazinesAmmo _vehicle;
|
||||
};
|
||||
|
||||
if (_amount <= 0) exitWith {};
|
||||
|
||||
private _fnc_secondaryExplosion = {
|
||||
params ["_vehicle", "_amount", "_fnc_secondaryExplosion"];
|
||||
|
||||
private _position = _vehicle modelToWorld (_vehicle selectionPosition "destructionEffect2");
|
||||
|
||||
// these CfgAmmo objects are always global
|
||||
createVehicle ["SmallSecondary", _position, [], 0, "CAN_COLLIDE"];
|
||||
|
||||
DEC(_amount);
|
||||
|
||||
if (!isNull _vehicle && {_amount > 0}) then {
|
||||
[_fnc_secondaryExplosion, [_vehicle, _amount, _fnc_secondaryExplosion], SECONDARIES_DELAY] call CBA_fnc_waitAndExecute;
|
||||
};
|
||||
};
|
||||
|
||||
[_fnc_secondaryExplosion, [_vehicle, _amount, _fnc_secondaryExplosion], SECONDARIES_DELAY] call CBA_fnc_waitAndExecute;
|
||||
|
||||
nil
|
||||
|
||||
/*SencondaryExplosion
|
||||
SecondaryExp
|
||||
SecondarySmoke
|
||||
GrenadeExploLight
|
||||
*/
|
Loading…
Reference in New Issue
Block a user