From dfe7c079360687fa04e0445176ce733d87c73e3b Mon Sep 17 00:00:00 2001 From: VKing Date: Sat, 19 Dec 2015 12:10:12 +0100 Subject: [PATCH] Fix fnc_mortarInit, fnc_loadMagazine, some other stuff --- .../functions/fnc_canLoadMagazine.sqf | 15 ++-- .../functions/fnc_canUnloadMagazine.sqf | 2 +- .../mk6mortar/functions/fnc_loadMagazine.sqf | 82 +++++++++---------- addons/mk6mortar/functions/fnc_mortarInit.sqf | 3 +- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf b/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf index 6670228faf..c0858a328a 100644 --- a/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf +++ b/addons/mk6mortar/functions/fnc_canLoadMagazine.sqf @@ -5,7 +5,7 @@ * Arguments: * 0: static * 1: unit - * 2: magazineClassOptional + * 2: magazine class to check; if not given having any compatible magazine returns true (default: "") * * Return Value: * canLoadMagazine @@ -15,40 +15,39 @@ * * Public: Yes */ - #include "script_component.hpp" params ["_static","_unit",["_magazineClassOptional","",[""]]]; private ["_canLoadMagazine","_currentMagazine","_weapon","_listOfMagNames", "_hasCompatibleMagazine","_count"]; -if !(alive _static && {GVAR(useAmmoHandling)}) exitWith {false}; +if !(alive _static && GVAR(useAmmoHandling)) exitWith {false}; _canLoadMagazine = false; +_hasCompatibleMagazine = false; _currentMagazine = (magazinesAllTurrets _static) select 1; _weapon = (_static weaponsTurret [0]) select 0; _listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines"); -_hasCompatibleMagazine = false; _count = 0; //If function is called with an optional string then check if player has that magzine otherwise check all magazines of the player to see if they are compatible with the static weapon if (_magazineClassOptional != "") then { - if ([_unit,_magazineClassOptional] call EFUNC(common,hasMagazine)) then { + if ([_unit,_magazineClassOptional] call EFUNC(common,hasMagazine)) then { _hasCompatibleMagazine = true; }; -}else{ + } else { { if ([_unit,_x] call EFUNC(common,hasMagazine)) exitWith {_hasCompatibleMagazine = true}; } forEach _listOfMagNames; }; //If static weapon has a magazine then find the ammo count -if ((count (_static magazinesTurret [0])) > 0)then{ +if (count (_static magazinesTurret [0]) > 0) then { _count = _currentMagazine select 2; }; //If the static weapon doesn't have a magzine or a magazine with no bullets, the player has a compatible magazine and the static weapon has a barrel then you can load a magazine -if ( ( ((count (_static magazinesTurret [0])) == 0) || (_count == 0) ) && _hasCompatibleMagazine) then { +if ((count (_static magazinesTurret [0]) == 0 || _count == 0 ) && _hasCompatibleMagazine) then { _canLoadMagazine = true; }; _canLoadMagazine diff --git a/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf b/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf index e4a609b34d..8b2fc0d3ed 100644 --- a/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf +++ b/addons/mk6mortar/functions/fnc_canUnloadMagazine.sqf @@ -19,7 +19,7 @@ params ["_static","_unit"]; private ["_canUnloadMagazine","_ammoCount"]; -if !(alive _static && {GVAR(useAmmoHandling)}) exitWith {false}; +if !(alive _static && GVAR(useAmmoHandling)) exitWith {false}; _canUnloadMagazine = false; _ammoCount = ((magazinesAllTurrets _static) select 1) select 2; diff --git a/addons/mk6mortar/functions/fnc_loadMagazine.sqf b/addons/mk6mortar/functions/fnc_loadMagazine.sqf index 80737c7574..41b0162151 100644 --- a/addons/mk6mortar/functions/fnc_loadMagazine.sqf +++ b/addons/mk6mortar/functions/fnc_loadMagazine.sqf @@ -5,7 +5,7 @@ * Arguments: * 0: static * 1: unit - * 2: magazineClassOptional + * 2: magazine class to load; if not given the first compatible magazine is loaded (default: "") * * Return Value: * None @@ -21,45 +21,45 @@ params ["_static","_unit",["_magazineClassOptional","",[""]]]; private ["_weapon","_currentMagazine","_count","_magazines","_magazineDetails","_listOfMagNames", "_magazineClass","_magazineClassDetails","_parsed","_roundsLeft"]; -//Get weapon & magazine information of static weapon -_weapon = (_static weaponsTurret [0]) select 0; -_currentMagazine = (magazinesAllTurrets _static) select 1; -_currentMagazineClass = _currentMagazine select 0; -_count = _currentMagazine select 2; - -//Check all of the players magazines to see if they are compatible with the static weapon. First magazine that is compatible is chosen -//VKing: This section ought to be double checked. -_magazines = magazines _unit; -_magazineDetails = magazinesDetail _unit; -_listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines"); -_magazineClass = ""; -_magazineClassDetails = ""; -_parsed =""; -_roundsLeft = 0; -{ - if (_x in _listOfMagNames) exitWith { - _magazineClass = _magazines select _forEachIndex; - _magazineClassDetails = _magazineDetails select _forEachIndex; - }; -} forEach _magazines; -//If the static weapon already has an empty magazine then remove it -if (_count == 0) then { - [QGVAR(removeMagazine), [_static, _currentMagazineClass]] call EFUNC(common,globalEvent); -}; -//Find out the ammo count of the compatible magazine found -if (_magazineClassDetails != "") then{ - _parsed = _magazineClassDetails splitString "([]/: )"; - _parsed params ["_type", "", "", "_roundsLeftText", "_maxRoundsText"]; - _roundsLeft = parseNumber _roundsLeftText; - _magType = _type; -}; - //If function has been called with an optional classname hten add that magazine to the static weapon. Otherwise add the compatible magazine -if(_magazineClassOptional !="") then{ - _unit removeMagazine _magazineClassOptional; - [QGVAR(addMagazine), [_static, _magazineClassOptional]] call EFUNC(common,globalEvent); - }else{ - _unit removeMagazine _magazineClass; - [QGVAR(addMagazine), [_static, _magazineClass]] call EFUNC(common,globalEvent); - [QGVAR(setAmmo), _static, [_static, _magazineClass,_roundsLeft]] call EFUNC(common,targetEvent); +if(_magazineClassOptional != "") then { + _unit removeMagazine _magazineClassOptional; + [QGVAR(addMagazine), [_static, _magazineClassOptional]] call EFUNC(common,globalEvent); +} else { + //Get weapon & magazine information of static weapon + _weapon = (_static weaponsTurret [0]) select 0; + _currentMagazine = (magazinesAllTurrets _static) select 1; + _currentMagazineClass = _currentMagazine select 0; + _count = _currentMagazine select 2; + + //Check all of the players magazines to see if they are compatible with the static weapon. First magazine that is compatible is chosen + //VKing: This section ought to be double checked. + _magazines = magazines _unit; + _magazineDetails = magazinesDetail _unit; + _listOfMagNames = getArray(configFile >> "cfgWeapons" >> _weapon >> "magazines"); + _magazineClass = ""; + _magazineClassDetails = ""; + _parsed =""; + _roundsLeft = 0; + { + if (_x in _listOfMagNames) exitWith { + _magazineClass = _x; + _magazineClassDetails = _magazineDetails select _forEachIndex; + }; + } forEach _magazines; + //If the static weapon already has an empty magazine then remove it + if (_count == 0) then { + [QGVAR(removeMagazine), [_static, _currentMagazineClass]] call EFUNC(common,globalEvent); }; + //Find out the ammo count of the compatible magazine found + if (_magazineClassDetails != "") then{ + _parsed = _magazineClassDetails splitString "([]/: )"; + _parsed params ["_type", "", "", "_roundsLeftText", "_maxRoundsText"]; + _roundsLeft = parseNumber _roundsLeftText; + _magType = _type; + }; + + _unit removeMagazine _magazineClass; + [QGVAR(addMagazine), [_static, _magazineClass]] call EFUNC(common,globalEvent); + [QGVAR(setAmmo), _static, [_static, _magazineClass,_roundsLeft]] call EFUNC(common,targetEvent); +}; diff --git a/addons/mk6mortar/functions/fnc_mortarInit.sqf b/addons/mk6mortar/functions/fnc_mortarInit.sqf index b499462cbe..d1d4f6ea04 100644 --- a/addons/mk6mortar/functions/fnc_mortarInit.sqf +++ b/addons/mk6mortar/functions/fnc_mortarInit.sqf @@ -27,7 +27,8 @@ if (count magazines _mortar > 0) then { // Replace current weapon with ammo handling weapon private _currentWeapon = _mortar weaponsTurret [0] select 0; -if (getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith)) != "") then { +private _newWeapon = getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith)); +if (_newWeapon != "") then { _mortar removeWeaponGlobal _currentWeapon; _mortar addWeaponGlobal _newWeapon; };