mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Attempt to fix turret locality issues
This commit is contained in:
parent
3072bd9d22
commit
cf9c49f13c
@ -22,29 +22,12 @@ if !(local _vehicle) exitWith { // TODO if there are players inside the turrets
|
||||
[_this, QFUNC(rearmEntireVehicleSuccess), _vehicle] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
||||
{
|
||||
_turretPath = _x;
|
||||
_magazines = _vehicle magazinesTurret _turretPath;
|
||||
if (isServer) then {
|
||||
{
|
||||
_magazine = _x;
|
||||
_currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
|
||||
_maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines);
|
||||
_maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
|
||||
_currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath];
|
||||
|
||||
TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine);
|
||||
|
||||
if (_currentMagazines < _maxMagazines) then {
|
||||
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
|
||||
for "_idx" from 1 to (_maxMagazines - _currentMagazines) do {
|
||||
_vehicle addMagazineTurret [_magazine, _turretPath];
|
||||
};
|
||||
} else {
|
||||
if (_currentRounds > 0 || {_magazine == "SmokeLauncherMag"}) then { // When SmokeLauncherMag is empty removeMagazineTurret has no effect
|
||||
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
|
||||
} else {
|
||||
_vehicle removeMagazineTurret [_magazine, _turretPath];
|
||||
};
|
||||
};
|
||||
} foreach _magazines;
|
||||
} foreach REARM_TURRET_PATHS;
|
||||
_turretOwnerID = _target turretOwner _x;
|
||||
EGVAR(common,remoteFnc) = [[_vehicle, _x], QFUNC(rearmEntireVehicleSuccesssLocal), 0];
|
||||
_turretOwnerID publicVariableClient QEGVAR(common,remoteFnc);
|
||||
} count REARM_TURRET_PATHS;
|
||||
} else {
|
||||
[_this, QUOTE(DFUNC(rearmEntireVehicleSuccess)), 1] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: GitHawk
|
||||
* Rearm an entire turret locally.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"];
|
||||
params ["_args"];
|
||||
_args params ["_vehicle", "_turretPath"];
|
||||
|
||||
_magazines = _vehicle magazinesTurret _turretPath;
|
||||
{
|
||||
_magazine = _x;
|
||||
_currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
|
||||
_maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines);
|
||||
_maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
|
||||
_currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath];
|
||||
|
||||
TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine);
|
||||
|
||||
if (_currentMagazines < _maxMagazines) then {
|
||||
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
|
||||
for "_idx" from 1 to (_maxMagazines - _currentMagazines) do {
|
||||
_vehicle addMagazineTurret [_magazine, _turretPath];
|
||||
};
|
||||
} else {
|
||||
if (_currentRounds > 0 || {_magazine == "SmokeLauncherMag"}) then { // When SmokeLauncherMag is empty removeMagazineTurret has no effect
|
||||
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
|
||||
} else {
|
||||
_vehicle removeMagazineTurret [_magazine, _turretPath];
|
||||
};
|
||||
};
|
||||
} foreach _magazines;
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_rounds", "_currentRounds", "_maxMagazines", "_dummy", "_weaponSelect"];
|
||||
private ["_dummy", "_weaponSelect", "_turretOwnerID"];
|
||||
params ["_args"];
|
||||
_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
|
||||
|
||||
@ -40,60 +40,10 @@ if (local _unit) then {
|
||||
_unit setVariable [QGVAR(selectedWeaponOnRearm), nil];
|
||||
};
|
||||
|
||||
if !(local _target) exitWith { // TODO if there are players inside the turrets they will not be rearmed due to locality issues
|
||||
[_this, QUOTE(DFUNC(rearmSuccess)), _target] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
||||
_rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
||||
_currentRounds = 0;
|
||||
|
||||
_maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
||||
if (_maxMagazines == 1) then {
|
||||
if (GVAR(level) == 1) then {
|
||||
// Fill magazine completely
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
} else {
|
||||
// Fill only at most _numRounds
|
||||
_target setMagazineTurretAmmo [_magazineClass, ((_target magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath];
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
if (isServer) then {
|
||||
_turretOwnerID = _target turretOwner _turretPath;
|
||||
EGVAR(common,remoteFnc) = [_this, QFUNC(rearmSuccessLocal), 0];
|
||||
_turretOwnerID publicVariableClient QEGVAR(common,remoteFnc);
|
||||
} else {
|
||||
for "_idx" from 1 to _maxMagazines do {
|
||||
_currentRounds = _target magazineTurretAmmo [_magazineClass, _turretPath];
|
||||
if (_currentRounds > 0) exitWith {
|
||||
if (GVAR(level) == 2) then {
|
||||
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nMagazine: %5\nNumRounds: %6\nMagazine: %7", _target, _turretPath, _numMagazines, _maxMagazines, _currentRounds, _numRounds, _magazineClass];
|
||||
// Fill only at most _numRounds
|
||||
if ((_currentRounds + _numRounds) > _rounds) then {
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
if (_numMagazines < _maxMagazines) then {
|
||||
_target addMagazineTurret [_magazineClass, _turretPath];
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds - _rounds, _turretPath];
|
||||
};
|
||||
} else {
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath];
|
||||
};
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
} else {
|
||||
// Fill current magazine completely and fill next magazine partially
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
if (_numMagazines < _maxMagazines) then {
|
||||
_target addMagazineTurret [_magazineClass, _turretPath];
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath];
|
||||
};
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
};
|
||||
_target removeMagazineTurret [_magazineClass, _turretPath];
|
||||
_numMagazines = _numMagazines - 1;
|
||||
};
|
||||
[_this, QUOTE(DFUNC(rearmSuccess)), 1] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
82
addons/rearm/functions/fnc_rearmSuccessLocal.sqf
Normal file
82
addons/rearm/functions/fnc_rearmSuccessLocal.sqf
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Author: GitHawk
|
||||
* Rearms a vehicle on the turret owner.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Params <ARRAY>
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Unit <OBJECT>
|
||||
* 2: Turret Path <ARRAY>
|
||||
* 3: Number of magazines <NUMBER>
|
||||
* 4: Magazine Classname <STRING>
|
||||
* 5: Number of rounds <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [[vehicle, player, [-1], 2, "5000Rnd_762x51_Belt", 500]] call ace_rearm_fnc_rearmSuccess
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_rounds", "_currentRounds", "_maxMagazines", "_dummy", "_weaponSelect"];
|
||||
params ["_args"];
|
||||
_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
|
||||
|
||||
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5", _target, _turretPath, _numMagazines, _magazineClass, _numRounds];
|
||||
|
||||
_rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
||||
_currentRounds = 0;
|
||||
|
||||
_maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
||||
if (_maxMagazines == 1) then {
|
||||
if (GVAR(level) == 1) then {
|
||||
// Fill magazine completely
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
} else {
|
||||
// Fill only at most _numRounds
|
||||
_target setMagazineTurretAmmo [_magazineClass, ((_target magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath];
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
} else {
|
||||
for "_idx" from 1 to _maxMagazines do {
|
||||
_currentRounds = _target magazineTurretAmmo [_magazineClass, _turretPath];
|
||||
if (_currentRounds > 0) exitWith {
|
||||
if (GVAR(level) == 2) then {
|
||||
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nMagazine: %5\nNumRounds: %6\nMagazine: %7", _target, _turretPath, _numMagazines, _maxMagazines, _currentRounds, _numRounds, _magazineClass];
|
||||
// Fill only at most _numRounds
|
||||
if ((_currentRounds + _numRounds) > _rounds) then {
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
if (_numMagazines < _maxMagazines) then {
|
||||
_target addMagazineTurret [_magazineClass, _turretPath];
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds - _rounds, _turretPath];
|
||||
};
|
||||
} else {
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath];
|
||||
};
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
} else {
|
||||
// Fill current magazine completely and fill next magazine partially
|
||||
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
||||
if (_numMagazines < _maxMagazines) then {
|
||||
_target addMagazineTurret [_magazineClass, _turretPath];
|
||||
_target setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath];
|
||||
};
|
||||
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
||||
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
||||
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
||||
};
|
||||
};
|
||||
_target removeMagazineTurret [_magazineClass, _turretPath];
|
||||
_numMagazines = _numMagazines - 1;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user