Merge pull request #620 from zharf/check_gear_improvements

Check gear improvements
This commit is contained in:
Christian 2019-07-23 23:23:10 +02:00 committed by GitHub
commit c45f98a021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 269 additions and 33 deletions

View File

@ -19,44 +19,89 @@
params [["_backpack", ""]];
private _return = true;
private _playerItems = [];
if ((headgear player) != "") then {_playerItems pushBack (headgear player);};
if ((goggles player) != "") then {_playerItems pushBack (goggles player);};
if ((uniform player) != "") then {_playerItems pushBack (uniform player);};
if ((vest player) != "") then {_playerItems pushBack (vest player);};
if (((backpack player) != "") && ((backpack player) != _backpack)) then {_playerItems pushBack (backpack player);};
{_playerItems pushBackUnique _x;} forEach (assignedItems player);
{_playerItems pushBackUnique _x;} forEach (uniformItems player);
{_playerItems pushBackUnique _x;} forEach (vestItems player);
{_playerItems pushBackUnique _x;} forEach (backpackItems player);
{_playerItems pushBackUnique _x;} forEach (weapons player);
{if (_x != "") then {_playerItems pushBackUnique _x;}} forEach (primaryWeaponItems player);
{if (_x != "") then {_playerItems pushBackUnique _x;}} forEach (secondaryWeaponItems player);
{if (_x != "") then {_playerItems pushBackUnique _x;}} forEach (handgunItems player);
private _removedItems = [];
if !(toLower (headgear player) in KP_liberation_allowed_items) then {
_removedItems pushBack (headgear player);
removeHeadgear player;
};
if !(toLower (goggles player) in KP_liberation_allowed_items) then {
_removedItems pushBack (goggles player);
removeGoggles player;
};
if !(toLower (uniform player) in KP_liberation_allowed_items) then {
_removedItems pushBack (uniform player);
removeUniform player;
};
if !(toLower (vest player) in KP_liberation_allowed_items) then {
_removedItems pushBack (vest player);
removeVest player;
};
if (!(toLower (backpack player) in KP_liberation_allowed_items) && ((backpack player) != _backpack)) then {
_removedItems pushBack (backpack player);
removeBackpack player;
};
private _playerItems = assignedItems player;
_playerItems append ((getItemCargo (uniformContainer player)) select 0);
_playerItems append ((getItemCargo (vestContainer player)) select 0);
_playerItems append ((getItemCargo (backpackContainer player)) select 0);
_playerItems = _playerItems apply {toLower _x};
{
_removedItems pushBack _x;
player unassignItem _x;
player removeItems _x;
} forEach (((_playerItems arrayIntersect _playerItems) - KP_liberation_allowed_items) select { !(_x call F_isRadio) });
private _validItemsCount = {
(_x in KP_liberation_allowed_items)
|| ((_x find "acre") != -1)
|| ((_x find "tf_") != -1)
|| ((_x find "tfar_") != -1)
} count _playerItems;
private _playerMagazines = ((getMagazineCargo (uniformContainer player)) select 0);
_playerMagazines append ((getMagazineCargo (vestContainer player)) select 0);
_playerMagazines append ((getMagazineCargo (backpackContainer player)) select 0);
_playerMagazines = _playerMagazines apply {toLower _x};
{
_removedItems pushBack _x;
player removeMagazines _x;
} forEach ((_playerMagazines arrayIntersect _playerMagazines) - KP_liberation_allowed_items);
if (_validItemsCount != count _playerItems) then {
private _text = format ["[KP LIBERATION] [BLACKLIST] Found %1 at Player %2", (_playerItems - KP_liberation_allowed_items), name player];
_removedItems append ([uniformContainer player] call F_removeWeaponCargo);
_removedItems append ([vestContainer player] call F_removeWeaponCargo);
_removedItems append ([backpackContainer player] call F_removeWeaponCargo);
private _weapons = weapons player;
_weapons = _weapons apply {toLower _x};
{
player removeWeapon _x;
_removedItems pushBack _x;
} forEach (_weapons - KP_liberation_allowed_items);
private _weaponItems = primaryWeaponItems player;
_weaponItems append primaryWeaponMagazine player;
_weaponItems = _weaponItems apply {toLower _x};
{
player removePrimaryWeaponItem _x;
_removedItems pushBack _x;
} forEach (_weaponItems - KP_liberation_allowed_items);
_weaponItems = secondaryWeaponItems player;
_weaponItems append secondaryWeaponMagazine player;
_weaponItems = _weaponItems apply {toLower _x};
{
player removeSecondaryWeaponItem _x;
_removedItems pushBack _x;
} forEach (_weaponItems - KP_liberation_allowed_items);
_weaponItems = handgunItems player;
_weaponItems append handgunMagazine player;
_weaponItems = _weaponItems apply {toLower _x};
{
player removeHandgunItem _x;
_removedItems pushBack _x;
} forEach (_weaponItems - KP_liberation_allowed_items);
_removedItems = (_removedItems arrayIntersect _removedItems) - [""];
if !(_removedItems isEqualTo []) then {
private _text = format ["[KP LIBERATION] [BLACKLIST] Found %1 at Player %2", (_removedItems), name player];
_text remoteExec ["diag_log",2];
private _badItems = "";
{if (((_x find "acre") == -1) && ((_x find "tf_") == -1) && ((_x find "tfar_") == -1)) then {_badItems = _badItems + _x + "\n";};} forEach (_playerItems - KP_liberation_allowed_items);
hint format [localize "STR_BLACKLISTED_ITEM_FOUND", _badItems];
removeAllWeapons player;
removeAllItems player;
removeAllAssignedItems player;
removeUniform player;
removeVest player;
removeBackpack player;
removeHeadgear player;
removeGoggles player;
hint format [localize "STR_BLACKLISTED_ITEM_FOUND", _removedItems joinString "\n"];
_return = false;
};

View File

@ -0,0 +1,50 @@
/*
F_getWeaponComponents
File: F_kp_getWeaponComponents.sqf
Author: Zharf, based on CBA_fnc_weaponComponents by commy2
Date: 2019-06-21
Last Update: 2019-06-21
Description:
Snatched from CBA since we don't depend on it yet.
Reports class name of base weapon without attachments and all attachments belonging to a pre equipped weapon.
Base weapon and attachments are reported in lower case capitalization.
Fixed version of BIS_fnc_weaponComponents.
Parameter(s):
0: STRING - a weapons class name with attachments build in
Returns:
ARRAY
*/
params [["_weapon", "", [""]]];
private _config = configFile >> "CfgWeapons" >> _weapon;
// Return empty array if the weapon doesn't exist
if (!isClass _config) exitWith {
[];
};
// get attachments
private _attachments = [];
{
_attachments pushBack toLower getText (_x >> "item");
} forEach ("true" configClasses (_config >> "LinkedItems")); // inheritance is apparently disabled for these
// get first parent without attachments
private _baseWeapon = "";
while {isClass _config && {getNumber (_config >> "scope") > 0}} do { // Some preset weapons are scope = 1
if (count (_config >> "LinkedItems") == 0) exitWith {
_baseWeapon = configName _config;
};
_config = inheritsFrom _config;
};
private _components = [toLower _baseWeapon];
_components append _attachments;
_components

View File

@ -0,0 +1,29 @@
/*
F_isRadio
File: F_kp_isRadio.sqf
Author: Zharf
Date: 2019-07-07
Last Update: 2019-07-07
Description:
Returns whether the provided item is a radio or not
Parameter(s):
0: STRING - a class name to check
Returns:
BOOL
*/
params ["_item"];
private _ret = false;
if ((isClass (configFile >> "CfgPatches" >> "tfar_core")) || (isClass (configFile >> "CfgPatches" >> "task_force_radio"))) then {
_ret = _item call TFAR_fnc_isRadio;
} else {
if (isClass (configFile >> "CfgPatches" >> "acre_api")) then {
_ret = [_item] call acre_api_fnc_isRadio;
};
};
_ret

View File

@ -0,0 +1,109 @@
/*
F_removeWeaponCargo
File: F_kp_removeWeaponCargo.sqf
Author: Zharf, based on CBA_fnc_removeWeaponCargo by Jonpas
Date: 2019-06-21
Last Update: 2019-06-21
Description:
Removes weapons not found in KP_liberation_allowed_items from a cargo space
Warning: All weapon attachments/magazines in container will become detached.
Warning: Preset weapons without non-preset parents will get their attachments readded (engine limitation).
Parameter(s):
0: OBJECT - Object with cargo
Returns:
ARRAY
*/
params [["_container", objNull, [objNull]]];
if (isNull _container) exitWith {
[]
};
private _removed = [];
private _weaponsItemsCargo = weaponsItemsCargo _container;
clearWeaponCargoGlobal _container;
{
_x params ["_weapon", "_muzzle", "_pointer", "_optic", "_magazine", "_magazineGL", "_bipod"];
// weaponsItems magazineGL does not exist if not loaded (not even as empty array)
if (count _x < 7) then {
_bipod = _magazineGL;
_magazineGL = "";
};
// Some weapons don't have non-preset parents
_components = _weapon call F_getWeaponComponents;
private _weaponNonPreset = _components select 0;
if (_weaponNonPreset == "") then {
_weaponNonPreset = _weapon;
};
if (toLower _weapon in KP_liberation_allowed_items) then {
_container addWeaponCargoGlobal [_weaponNonPreset, 1];
// If weapon does not have a non-preset parent, only add attachments that were custom added
// Removed attachments cannot be handled (engine limitation) and will be readded due to having to readd preset weapon
private _presetAttachments = [];
if (_weaponNonPreset == _weapon) then {
_presetAttachments = _components;
};
if !(toLower _muzzle in _presetAttachments) then {
if (toLower _muzzle in KP_liberation_allowed_items) then {
_container addItemCargoGlobal [_muzzle, 1];
} else {
_removed pushBack _muzzle;
}
};
if !(toLower _pointer in _presetAttachments) then {
if (toLower _pointer in KP_liberation_allowed_items) then {
_container addItemCargoGlobal [_pointer, 1];
} else {
_removed pushBack _pointer;
}
};
if !(toLower _optic in _presetAttachments) then {
if (toLower _optic in KP_liberation_allowed_items) then {
_container addItemCargoGlobal [_optic, 1];
} else {
_removed pushBack _optic;
}
};
if !(toLower _bipod in _presetAttachments) then {
if (toLower _optic in KP_liberation_allowed_items) then {
_container addItemCargoGlobal [_optic, 1];
} else {
_removed pushBack _optic;
}
};
_magazine params [["_magazineClass", ""], ["_magazineAmmoCount", 0]];
if (_magazineClass != "") then {
if (toLower _magazineClass in KP_liberation_allowed_items) then {
_container addMagazineAmmoCargo [_magazineClass, 1, _magazineAmmoCount];
} else {
_removed pushBack _magazineClass;
}
};
_magazineGL params [["_magazineGLClass", ""], ["_magazineGLAmmoCount", 0]];
if (_magazineGLClass != "") then {
if (toLower _magazineGLClass in KP_liberation_allowed_items) then {
_container addMagazineAmmoCargo [_magazineGLClass, 1, _magazineGLAmmoCount];
} else {
_removed pushBack _magazineGLClass;
}
};
} else {
_removed pushBack _weapon;
}
} forEach _weaponsItemsCargo;
_removed;

View File

@ -58,9 +58,12 @@ F_getResistanceTier = compileFinal preprocessFileLineNumbers "scripts\shared\fun
F_spawnGuerillaGroup = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_spawnGuerillaGroup.sqf";
F_createCrate = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_createCrate.sqf";
F_isClassUAV = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_isClassUAV.sqf";
F_getWeaponComponents = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_getWeaponComponents.sqf";
F_removeWeaponCargo = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_removeWeaponCargo.sqf";
F_checkGear = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_checkGear.sqf";
F_setFobMass = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_setFobMass.sqf";
F_getSaveableParam = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_getSaveableParam.sqf";
F_setLoadableViV = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_setLoadableViV.sqf";
F_getNearestViVTransport = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_getNearestViVTransport.sqf";
F_addObjectInit = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_addObjectInit.sqf";
F_isRadio = compileFinal preprocessFileLineNumbers "scripts\shared\functions\F_kp_isRadio.sqf";