mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
add ai_switchMagazine
This commit is contained in:
parent
22d45be421
commit
b7abfeaeb5
@ -4,6 +4,7 @@ PREP(aceRearmGetCarryMagazines);
|
||||
|
||||
PREP(ai_handleFired);
|
||||
PREP(ai_handleGetIn);
|
||||
PREP(ai_switchMagazine);
|
||||
PREP(ai_reload);
|
||||
|
||||
PREP(assemble_canDeployTripod);
|
||||
|
@ -16,6 +16,7 @@
|
||||
[QGVAR(addTurretMag), LINKFUNC(reload_handleAddTurretMag)] call CBA_fnc_addEventHandler;
|
||||
[QGVAR(removeTurretMag), LINKFUNC(reload_handleRemoveTurretMag)] call CBA_fnc_addEventHandler;
|
||||
[QGVAR(returnAmmo), LINKFUNC(reload_handleReturnAmmo)] call CBA_fnc_addEventHandler;
|
||||
[QGVAR(ai_reload), LINKFUNC(ai_reload)] call CBA_fnc_addEventHandler;
|
||||
|
||||
|
||||
|
||||
|
@ -7,16 +7,17 @@
|
||||
* 0: CSW <OBJECT>
|
||||
* 1: Gunner <OBJECT>
|
||||
* 2: Skip reload time <BOOL> (default: false)
|
||||
* 3: Clear forced magazine after reloading (default: true)
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
params ["_vehicle", "_gunner", ["_instantReload", false]];
|
||||
params ["_vehicle", "_gunner", ["_instantReload", false], ["_clearForcedMag", false]];
|
||||
TRACE_3("AI reload",_vehicle,_gunner,_instantReload);
|
||||
|
||||
// API, to be used by artillerytables
|
||||
// API, used for ai_switchMagazine
|
||||
private _forcedMag = _vehicle getVariable [QGVAR(forcedMag), ""];
|
||||
private _turretIndex = [_gunner] call EFUNC(common,getTurretIndex);
|
||||
if (_turretIndex isEqualTo []) then {
|
||||
@ -40,6 +41,10 @@ private _magazineInfo = [];
|
||||
};
|
||||
} forEach _loadableMagazines;
|
||||
|
||||
if (_clearForcedMag) then {
|
||||
_vehicle setVariable [QGVAR(forcedMag), nil, true];
|
||||
};
|
||||
|
||||
if (_magazineInfo isEqualTo []) exitWith {};
|
||||
_magazineInfo params ["_carryMag", "_turretPath", "_loadInfo", "_magSource", "", "_ammo"];
|
||||
|
||||
|
36
addons/csw/functions/fnc_ai_switchMagazine.sqf
Normal file
36
addons/csw/functions/fnc_ai_switchMagazine.sqf
Normal file
@ -0,0 +1,36 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: LinkIsGrim
|
||||
* Handles AI magazine switching
|
||||
* Magazine must be compatible and available, use ace_csw_fnc_getAvailableAmmo
|
||||
*
|
||||
* Arguments:
|
||||
* 0: CSW <OBJECT>
|
||||
* 1: Carry Magazine <STRING>
|
||||
* 2: Turret Path <ARRAY> (default: [0])
|
||||
* 3: Skip reload time <BOOL> (default: false)
|
||||
* 4: Clear forced magazine after reloading <BOOL> (default: true)
|
||||
*
|
||||
* Return Value:
|
||||
* Successful <BOOL>
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
params [["_vehicle", objNull, [objNull]], ["_carryMag", "", [""]], ["_turretPath", [0], [[0]]], ["_instantReload", false, [false]], ["_clearForcedMag", true, [true]]];
|
||||
|
||||
if !(alive _vehicle && {!(isNull _vehicle turretUnit _turretPath)} && {!isNull _vehicle}) exitWith {false};
|
||||
|
||||
// must be config case
|
||||
_carryMag = configName (configFile >> "CfgMagazines" >> _carryMag);
|
||||
if (_carryMag isEqualTo "") exitWith {false};
|
||||
|
||||
private _availableMags = [_vehicle] call FUNC(getAvailableAmmo);
|
||||
if !(_carryMag in _availableMags) exitWith {false};
|
||||
|
||||
_vehicle setVariable [QGVAR(forcedMag), _carryMag, true];
|
||||
|
||||
private _gunner = _vehicle turretUnit _turretPath;
|
||||
|
||||
[QGVAR(ai_reload), [_vehicle, _gunner, _instantReload, _clearForcedMag], _gunner] call CBA_fnc_targetEvent;
|
||||
|
||||
true
|
Loading…
Reference in New Issue
Block a user