mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #284 from KoffeinFlummi/beltRepacking
MagRepack - Belt Repacking / Child Actions
This commit is contained in:
commit
e03d3ed619
@ -6,11 +6,9 @@ class CfgVehicles {
|
||||
displayName = "$STR_ACE_MagazineRepack_RepackMagazines";
|
||||
condition = QUOTE(true);
|
||||
exceptions[] = {"isNotInside"};
|
||||
statement = QUOTE([_player] call FUNC(openSelectMagazineUI));
|
||||
showDisabled = 0;
|
||||
insertChildren = QUOTE(_this call FUNC(getMagazineChildren));
|
||||
priority = -2;
|
||||
icon = QUOTE(PATHTOF(UI\repack_ca.paa));
|
||||
hotkey = "R";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
ADDON = false;
|
||||
|
||||
PREP(getMagazineChildren);
|
||||
PREP(magazineRepackFinish);
|
||||
PREP(magazineRepackProgress);
|
||||
PREP(openSelectMagazineUI);
|
||||
PREP(simulateRepackEvents);
|
||||
PREP(startRepackingMagazine);
|
||||
|
||||
|
@ -17,12 +17,19 @@ class CfgPatches {
|
||||
#include "CfgVehicles.hpp"
|
||||
|
||||
class ACE_Settings {
|
||||
//Time to move a round from one magazine to another
|
||||
class GVAR(TimePerAmmo) {
|
||||
value = 1.5;
|
||||
typeName = "SCALAR";
|
||||
};
|
||||
//Time to swap between magazines when repacking
|
||||
class GVAR(TimePerMagazine) {
|
||||
value = 2.0;
|
||||
typeName = "SCALAR";
|
||||
};
|
||||
//Time to relink 2 belts together
|
||||
class GVAR(TimePerBeltLink) {
|
||||
value = 8.0;
|
||||
typeName = "SCALAR";
|
||||
};
|
||||
};
|
||||
|
54
addons/magazinerepack/functions/fnc_getMagazineChildren.sqf
Normal file
54
addons/magazinerepack/functions/fnc_getMagazineChildren.sqf
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: PabstMirror,commy2, esteldunedain, Ruthberg
|
||||
* Gets magazine children for interaciton menu
|
||||
*
|
||||
* Argument:
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Player <OBJECT>
|
||||
*
|
||||
* Return value:
|
||||
* ChildActiosn<ARRAY>
|
||||
*
|
||||
* Example:
|
||||
* [player, player] call ace_magazinerepack_fnc_getMagazineChildren
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unitMagazines", "_unitMagCounts", "_xFullMagazineCount", "_index", "_actions", "_displayName", "_picture", "_action"];
|
||||
|
||||
PARAMS_2(_target,_player);
|
||||
|
||||
// get all mags and ammo count
|
||||
_unitMagazines = [];
|
||||
_unitMagCounts = [];
|
||||
{
|
||||
EXPLODE_4_PVT(_x,_xClassname,_xCount,_xLoaded,_xType);
|
||||
_xFullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
|
||||
|
||||
//for every partial magazine, that is either in inventory or can be moved there
|
||||
if ((_xCount < _xFullMagazineCount) && {_xCount > 0} && {(!_xLoaded) || {_player canAdd _magazineClassname}}) then {
|
||||
_index = _unitMagazines find _xClassname;
|
||||
if (_index == -1) then {
|
||||
_unitMagazines pushBack _xClassname;
|
||||
_unitMagCounts pushBack [_xCount];
|
||||
} else {
|
||||
(_unitMagCounts select _index) pushBack _xCount;
|
||||
};
|
||||
};
|
||||
} forEach (magazinesAmmoFull _player);
|
||||
|
||||
//Create the action children for all appropriate magazines
|
||||
_actions = [];
|
||||
{
|
||||
if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything)
|
||||
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName");
|
||||
_picture = getText (configFile >> "CfgMagazines" >> _x >> "picture");
|
||||
|
||||
_action = [_x, _displayName, _picture, {_this call FUNC(startRepackingMagazine)}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
|
||||
_actions pushBack [_action, [], _player];
|
||||
};
|
||||
} forEach _unitMagazines;
|
||||
|
||||
_actions
|
@ -19,13 +19,16 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_structuredOutputText", "_picture", "_fullMags", "_partialMags", "_fullMagazineCount"];
|
||||
|
||||
PARAMS_4(_args,_elapsedTime,_totalTime,_errorCode);
|
||||
EXPLODE_2_PVT(_args,_magazineClassname,_lastAmmoCount);
|
||||
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _magazineClassname >> "count");
|
||||
|
||||
_structuredOutputText =
|
||||
//Don't show anything if player can't interact:
|
||||
if (!([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith))) exitWith {};
|
||||
|
||||
if (_errorCode == 0) then {
|
||||
_structuredOutputText = if (_errorCode == 0) then {
|
||||
format ["<t align='center'>%1</t><br/>", (localize "STR_ACE_MagazineRepack_RepackComplete")];
|
||||
} else {
|
||||
format ["<t align='center'>%1</t><br/>", (localize "STR_ACE_MagazineRepack_RepackInterrupted")];
|
||||
@ -34,19 +37,20 @@ if (_errorCode == 0) then {
|
||||
_picture = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "picture");
|
||||
_structuredOutputText = _structuredOutputText + format ["<img align='center' size='1.8' color='#ffffff' image='%1'/> <br/>", _picture];
|
||||
|
||||
_fullMags = 0;
|
||||
_partialMags = 0;
|
||||
{
|
||||
EXPLODE_2_PVT(_x,_xClassname,_xCount);
|
||||
if ((_xClassname == _magazineClassname) && {_xCount > 0}) then {
|
||||
if (_xCount == _fullMagazineCount) then {
|
||||
_fullMags = _fullMags + 1;
|
||||
} else {
|
||||
_partialMags = _partialMags + 1;
|
||||
};
|
||||
};
|
||||
} forEach (magazinesAmmoFull ACE_player);
|
||||
//EFUNC(common,displayTextStructured) doesn't have room for this, and I don't think it's nessacary, can fix in the future if wanted:
|
||||
|
||||
_structuredOutputText = _structuredOutputText + format [("<t align='center'>" + (localize "STR_ACE_MagazineRepack_RepackedMagazinesCount") + "</t>"), _fullMags, _partialMags];
|
||||
// _fullMags = 0;
|
||||
// _partialMags = 0;
|
||||
// {
|
||||
// EXPLODE_2_PVT(_x,_xClassname,_xCount);
|
||||
// if ((_xClassname == _magazineClassname) && {_xCount > 0}) then {
|
||||
// if (_xCount == _fullMagazineCount) then {
|
||||
// _fullMags = _fullMags + 1;
|
||||
// } else {
|
||||
// _partialMags = _partialMags + 1;
|
||||
// };
|
||||
// };
|
||||
// } forEach (magazinesAmmoFull ACE_player);
|
||||
// _structuredOutputText = _structuredOutputText + format [("<t align='center'>" + (localize "STR_ACE_MagazineRepack_RepackedMagazinesCount") + "</t>"), _fullMags, _partialMags];
|
||||
|
||||
[parseText _structuredOutputText] call EFUNC(common,displayTextStructured);
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
|
||||
* Opens the selectMenu UI to chose which magazine to repack.
|
||||
* Only shows classnames that have 2+ partial magazines
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit (player) <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* [_player] call ace_magazinerepack_fnc_openSelectMagazineUI
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unitMagazines", "_unitMagCounts", "_xFullMagazineCount", "_index", "_actions", "_displayName", "_picture"];
|
||||
|
||||
PARAMS_1(_unit);
|
||||
|
||||
_unitMagazines = [];
|
||||
_unitMagCounts = [];
|
||||
|
||||
// get all mags and ammo count
|
||||
{
|
||||
EXPLODE_2_PVT(_x,_xClassname,_xCount);
|
||||
_xFullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
|
||||
|
||||
if ((_xCount != _xFullMagazineCount) && {_xCount > 0}) then {//for every partial magazine
|
||||
_index = _unitMagazines find _xClassname;
|
||||
if (_index == -1) then {
|
||||
_unitMagazines pushBack _xClassname;
|
||||
_unitMagCounts pushBack [_xCount];
|
||||
} else {
|
||||
(_unitMagCounts select _index) pushBack _xCount;
|
||||
};
|
||||
};
|
||||
} forEach (magazinesAmmoFull _unit);
|
||||
|
||||
_actions = [localize "STR_ACE_MagazineRepack_SelectMagazineMenu", localize "STR_ACE_MagazineRepack_SelectMagazine"] call EFUNC(interaction,prepareSelectMenu);
|
||||
|
||||
{
|
||||
if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything)
|
||||
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName");
|
||||
_picture = getText (configFile >> "CfgMagazines" >> _x >> "picture");
|
||||
_actions = [_actions, _displayName, _picture, _x] call EFUNC(interaction,addSelectableItem);
|
||||
};
|
||||
} forEach _unitMagazines;
|
||||
|
||||
[
|
||||
_actions,
|
||||
{ [_this] call FUNC(startRepackingMagazine); },
|
||||
{
|
||||
call EFUNC(interaction,hideMenu); //ToDo: Self Interaction Integration
|
||||
}
|
||||
] call EFUNC(interaction,openSelectMenu);
|
@ -6,12 +6,13 @@
|
||||
* Arguments:
|
||||
* 0: How many rounds in a full magazine <NUMBER>
|
||||
* 1: Array of rounds in magazines <ARRAY>
|
||||
* 2: Magazine is a belt <BOOL>
|
||||
*
|
||||
* Return Value:
|
||||
* Array in format [time, isBullet, array of ammo counts] <ARRAY>
|
||||
*
|
||||
* Example:
|
||||
* [5, [1,2,3,8]] call ace_magazinerepack_fnc_simulateRepackEvents =
|
||||
* [10, [1,2,3,8], false] call ace_magazinerepack_fnc_simulateRepackEvents =
|
||||
* [[1.5,true,[0,2,3,9]],[3.5,false,[0,2,3,9]],[5,true,[0,1,3,10]],[7,false,[0,1,3,10]],[8.5,true,[0,0,4,10]],[10.5,false,[0,0,4,10]]]
|
||||
*
|
||||
* Public: No
|
||||
@ -20,7 +21,7 @@
|
||||
|
||||
private ["_newMagFnc", "_time", "_events", "_swapAmmoFnc", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
|
||||
|
||||
PARAMS_2(_fullMagazineCount,_arrayOfAmmoCounts);
|
||||
PARAMS_3(_fullMagazineCount,_arrayOfAmmoCounts,_isBelt);
|
||||
|
||||
// Sort Ascending - Don't modify original
|
||||
_arrayOfAmmoCounts = (+_arrayOfAmmoCounts) call BIS_fnc_sortNum;
|
||||
@ -29,13 +30,23 @@ _newMagFnc = {
|
||||
_time = _time + GVAR(TimePerMagazine);
|
||||
_events pushBack [_time, false, +_arrayOfAmmoCounts];
|
||||
};
|
||||
_swapAmmoFnc = {
|
||||
for "_swapProgress" from 0 to (_ammoSwaped - 1) do {
|
||||
_time = _time + GVAR(TimePerAmmo);
|
||||
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - 1)];
|
||||
_arrayOfAmmoCounts set [_highIndex, ((_arrayOfAmmoCounts select _highIndex) + 1)];
|
||||
|
||||
_swapAmmoFnc = if (_isBelt) then {
|
||||
{
|
||||
_time = _time + GVAR(TimePerBeltLink);
|
||||
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - _ammoSwaped)];
|
||||
_arrayOfAmmoCounts set [_highIndex, ((_arrayOfAmmoCounts select _highIndex) + _ammoSwaped)];
|
||||
_events pushBack [_time, true, +_arrayOfAmmoCounts];
|
||||
};
|
||||
}
|
||||
} else {
|
||||
{
|
||||
for "_swapProgress" from 0 to (_ammoSwaped - 1) do {
|
||||
_time = _time + GVAR(TimePerAmmo);
|
||||
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - 1)];
|
||||
_arrayOfAmmoCounts set [_highIndex, ((_arrayOfAmmoCounts select _highIndex) + 1)];
|
||||
_events pushBack [_time, true, +_arrayOfAmmoCounts];
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
_lowIndex = 0;
|
||||
|
@ -5,7 +5,9 @@
|
||||
* Precalcs all the event timings and starts the progressBar.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Magazine Classname <STRING>
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Player <OBJECT>
|
||||
* 2: Magazine Classname <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
@ -17,18 +19,21 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unit", "_fullMagazineCount", "_startingAmmoCounts", "_simEvents", "_totalTime"];
|
||||
private ["_magazineCfg", "_fullMagazineCount", "_isBelt", "_startingAmmoCounts", "_simEvents", "_totalTime"];
|
||||
|
||||
PARAMS_3(_target,_player,_magazineClassname);
|
||||
|
||||
PARAMS_1(_magazineClassname);
|
||||
if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");};
|
||||
|
||||
_unit = ACE_player;
|
||||
|
||||
[ACE_player] call EFUNC(common,goKneeling);
|
||||
call EFUNC(interaction,hideMenu);//ToDo: Self Interaction Integration
|
||||
|
||||
_magazineCfg = configfile >> "CfgMagazines" >> _magazineClassname;
|
||||
// Calculate actual ammo to transfer during repack
|
||||
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _magazineClassname >> "count");
|
||||
_fullMagazineCount = getNumber (_magazineCfg >> "count");
|
||||
//Is linked belt magazine:
|
||||
_isBelt = (isNumber (_magazineCfg >> "ACE_isBelt")) && {(getNumber (_magazineCfg >> "ACE_isBelt")) == 1};
|
||||
|
||||
//Check canInteractWith:
|
||||
if (!([_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith))) exitWith {};
|
||||
|
||||
[_player] call EFUNC(common,goKneeling);
|
||||
|
||||
_startingAmmoCounts = [];
|
||||
{
|
||||
@ -36,25 +41,25 @@ _startingAmmoCounts = [];
|
||||
if ((_xClassname == _magazineClassname) && {(_xCount != _fullMagazineCount) && {_xCount > 0}}) then {
|
||||
if (_xLoaded) then {
|
||||
//Try to Remove from weapon and add to inventory, otherwise ignore
|
||||
if (_unit canAdd _magazineClassname) then {
|
||||
if (_player canAdd _magazineClassname) then {
|
||||
switch (_xType) do {
|
||||
case (1): {_unit removePrimaryWeaponItem _magazineClassname;};
|
||||
case (2): {_unit removeHandgunItem _magazineClassname;};
|
||||
case (4): {_unit removeSecondaryWeaponItem _magazineClassname;};
|
||||
case (1): {_player removePrimaryWeaponItem _magazineClassname;};
|
||||
case (2): {_player removeHandgunItem _magazineClassname;};
|
||||
case (4): {_player removeSecondaryWeaponItem _magazineClassname;};
|
||||
default {ERROR("Loaded Location Invalid");};
|
||||
};
|
||||
_unit addMagazine [_magazineClassname, _xCount];
|
||||
_player addMagazine [_magazineClassname, _xCount];
|
||||
_startingAmmoCounts pushBack _xCount;
|
||||
};
|
||||
} else {
|
||||
_startingAmmoCounts pushBack _xCount;
|
||||
};
|
||||
};
|
||||
} forEach (magazinesAmmoFull _unit);
|
||||
} forEach (magazinesAmmoFull _player);
|
||||
|
||||
if ((count _startingAmmoCounts) < 2) exitwith {ERROR("Not Enough Mags to Repack");};
|
||||
|
||||
_simEvents = [_fullMagazineCount, _startingAmmoCounts] call FUNC(simulateRepackEvents);
|
||||
_simEvents = [_fullMagazineCount, _startingAmmoCounts, _isBelt] call FUNC(simulateRepackEvents);
|
||||
_totalTime = (_simEvents select ((count _simEvents) - 1) select 0);
|
||||
|
||||
[
|
||||
@ -63,5 +68,6 @@ _totalTime,
|
||||
{_this call FUNC(magazineRepackFinish)},
|
||||
{_this call FUNC(magazineRepackFinish)},
|
||||
(localize "STR_ACE_MagazineRepack_RepackingMagazine"),
|
||||
{_this call FUNC(magazineRepackProgress)}
|
||||
{_this call FUNC(magazineRepackProgress)},
|
||||
["isNotInside"]
|
||||
] call EFUNC(common,progressBar);
|
||||
|
@ -1,12 +1,11 @@
|
||||
class CfgMagazines {
|
||||
class CA_Magazine;
|
||||
class 150Rnd_762x51_Box : CA_Magazine {
|
||||
ACE_isBelt = 1;
|
||||
};
|
||||
|
||||
class CA_Magazine;
|
||||
class 150Rnd_762x51_Box : CA_Magazine {
|
||||
ACE_isBelt = 1;
|
||||
};
|
||||
|
||||
class 100Rnd_65x39_caseless_mag;
|
||||
class 200Rnd_65x39_cased_Box : 100Rnd_65x39_caseless_mag {
|
||||
ACE_isBelt = 1;
|
||||
};
|
||||
};
|
||||
class 100Rnd_65x39_caseless_mag;
|
||||
class 200Rnd_65x39_cased_Box : 100Rnd_65x39_caseless_mag {
|
||||
ACE_isBelt = 1;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user