Fix keys not deleting

Should work fine, but more validation is always good, I tested selling
from all inventories with DZE_SaleRequiresKey true and false.
This commit is contained in:
icomrade
2016-07-29 00:55:20 -04:00
parent d31df4f1fc
commit bdf0870f3e
4 changed files with 83 additions and 63 deletions

View File

@@ -0,0 +1,68 @@
private ["_localResult2","_VehKey2","_keyArr","_deleteRet","_vehicle","_delType","_containerFindKey"];
_VehKey2 = (_this select 0) select 0;
_delType = _this select 1;
_containerFindKey = {
private ["_keys","_weapTypes"];
_keys = [];
_weapTypes = (_this select 1) select 0;
{
if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]) then {
if (str(getNumber(configFile >> "CfgWeapons" >> _x >> "keyid")) == (_this select 0)) then {
_keys set [count _keys, _x];
};
};
} forEach _weapTypes;
_keys;
};
if ((count _VehKey2) > 0) then {
if ((_VehKey2 select 0) == "0" || _delType in ["trade_any_bicycle", "trade_any_bicycle_old", "trade_any_vehicle_free"]) then {
_localResult2 = 1;
} else {
{
if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]) then {
if (str(getNumber(configFile >> "CfgWeapons" >> _x >> "keyid")) == (_VehKey2 select 0)) then {
_localResult2 = [player,_x,1] call BIS_fnc_invRemove;
};
};
} forEach (items player);
if ((typeOf (unitBackPack player)) != "") then {
_keyArr = [(_VehKey2 select 0), (getWeaponCargo (unitBackpack player))] call _containerFindKey;
_deleteRet = [unitBackpack player,[],_keyArr] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
if (isNil "_localResult2") then {
_localResult2 = ((_deleteRet select 1) select 0);
} else {
if (_localResult2 == 0) then {
_localResult2 = ((_deleteRet select 1) select 0);
};
};
};
_vehicle = Z_vehicle;
if (count _this > 2 && {isNull _vehicle}) then {
_vehicle = _this select 2;
};
if (!isNull _vehicle) then {
_keyArr = [(_VehKey2 select 0), (getWeaponCargo _vehicle)] call _containerFindKey;
_deleteRet = [_vehicle,[],_keyArr] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
if (isNil "_localResult2") then {
_localResult2 = ((_deleteRet select 1) select 0);
} else {
if (_localResult2 == 0) then {
_localResult2 = ((_deleteRet select 1) select 0);
};
};
};
if (!DZE_SaleRequiresKey) then {_localResult2 = 1;};
};
if (isNil "_localResult2") then {
_localResult2 = 0;
} else {
PVDZ_obj_Destroy = [(_VehKey2 select 2),(_VehKey2 select 3),player];
publicVariableServer "PVDZ_obj_Destroy";
deleteVehicle (_VehKey2 select 1);
};
} else {
_localResult2 = 0;
};
_localResult2;

View File

@@ -15,34 +15,6 @@ _weaponsCheckArray = [];
_itemsCheckArray = [];
_itemsToLog = [[],[],[],"sell"];
_deleteTradedVehicle = {
private ["_localResult2","_VehKey2"];
_VehKey2 = (_this select 0) select 0;
_delType = _this select 1;
if ((count _VehKey2) > 0) then {
if ((_VehKey2 select 0) == "0" || _delType in ["trade_any_bicycle", "trade_any_bicycle_old", "trade_any_vehicle_free"] || !DZE_SaleRequiresKey) then {
_localResult2 = 1;
} else {
{
if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]) then {
if (str(getNumber(configFile >> "CfgWeapons" >> _x >> "keyid")) == (_VehKey2 select 0)) then {
_localResult2 = [player,_x,1] call BIS_fnc_invRemove;
};
};
} forEach (items player);
};
if (isNil "_localResult2") then {
_localResult2 = 0;
} else {
PVDZ_obj_Destroy = [(_VehKey2 select 2),(_VehKey2 select 3),player];
publicVariableServer "PVDZ_obj_Destroy";
deleteVehicle (_VehKey2 select 1);
};
} else {
_localResult2 = 0;
};
_localResult2;
};
_sellVehicle = {
private ["_distance","_damage","_tireDmg","_tires","_okToSell","_returnInfo","_textPartIn","_obj","_hitpoints","_objectID","_objectUID","_objectCharacterId","_notSetup","_part_in","_qty_in","_activatingPlayer","_objects","_qty","_vehicle"];
_vehicle = _this select 0;
@@ -92,6 +64,7 @@ _sellVehicle = {
};
_returnInfo;
};
{
private ["_type","_name"];
_type = _x select 1;
@@ -151,7 +124,7 @@ if (Z_SellingFrom == 2)then{
{
if ((_x select 1) in ["trade_any_vehicle", "trade_any_vehicle_free", "trade_any_vehicle_old", "trade_any_bicycle", "trade_any_bicycle_old", "trade_any_boat", "trade_any_boat_old"]) then {
_localResult = [_vehArray, (_x select 1)] call _deleteTradedVehicle;
_localResult = [_vehArray, (_x select 1)] call DZE_deleteTradedVehicle;
if (_localResult == 1) then {_vehTraded = true;};
} else {
if (_x select 1 == "trade_backpacks") then {

View File

@@ -6,27 +6,24 @@
Author:
Zupa 2014-09-30
---------------------------------------------------------------------------- */
private ["_unit","_items","_weaps","_normalItems","_normalWeaps","_unit_allItems","_unit_allItems_types","_unit_allItems_count","_bags","_vehInfo","_keyID","_counter","_normalBagss","_inCargo","_deleteVeh","_normalBags","_unit_allWeaps","_unit_allWeaps_types","_unit_allWeaps_count","_unit_allBags","_unit_allBags_types","_unit_allBags_count","_returnVar","_returnMag","_returnWeap","_returnBag"];
private ["_bags","_vehInfo","_forEachIndex","_counter","_normalBagss","_inCargo","_unit","_items","_weaps","_normalItems","_normalWeaps","_normalBags","_unit_allItems","_unit_allItems_types","_unit_allItems_count","_unit_allWeaps","_unit_allWeaps_types","_unit_allWeaps_count","_unit_allBags","_unit_allBags_types","_unit_allBags_count","_returnVar","_returnMag","_returnWeap","_returnBag"];
_unit = _this select 0;
_items = _this select 1;
_weaps = _this select 2;
_bags = [];
_vehInfo = [];
_keyID = 0;
_deleteVeh = false;
if(count _this > 3) then {
if (count (_this select 3) > 0) then {
if (typeName ((_this select 3) select 0) == "STRING") then {
_bags = _this select 3;
} else {
_vehInfo = (_this select 3) select 0;
_keyID = _vehInfo select 0;
_vehInfo = _this select 3;
};
};
if (count _this == 5) then {
_vehInfo = (_this select 4) select 0;
_keyID = _vehInfo select 0;
_vehInfo = _this select 4;
};
};
@@ -106,30 +103,11 @@ _normalItems = _normalItems - ["soldItem"];
_unit addBackpackCargoGlobal [_x, 1];
}count _normalBags;
if (count _vehInfo > 0) then {
if (!((_vehInfo select 4) in ["trade_any_bicycle", "trade_any_bicycle_old", "trade_any_vehicle_free"])) then {
{
if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]) then {
if (str(getNumber(configFile >> "CfgWeapons" >> _x >> "keyid")) == _keyID) then {
_weaps set [count _weaps, _x];
_deleteVeh = True;
};
};
} count _normalWeaps;
if (_keyID == "0" || !DZE_SaleRequiresKey) then {_deleteVeh = True;};
} else {
_deleteVeh = True;
};
};
{
_inCargo = _normalWeaps find _x;
if(_inCargo > -1)then{
_normalWeaps set [_inCargo, "soldItem"];
if (!_deleteVeh && {(!(configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"]))}) then {
_returnWeap set [count(_returnWeap),1];
};
_returnWeap set [count(_returnWeap),1];
}else{
_returnWeap set [count(_returnWeap),0];
};
@@ -141,15 +119,15 @@ _normalWeaps = _normalWeaps - ["soldItem"];
}count _normalWeaps;
_normalWeaps = _normalWeaps - ["soldItem"];
if (count _vehInfo > 0) then {
_sell = [_vehInfo, ((_vehInfo select 0) select 4), _unit] call DZE_deleteTradedVehicle;
if (_sell > 0) then {
_returnVar set [3,[1]];
};
};
_returnVar set [0,_returnMag];
_returnVar set [1,_returnWeap];
_returnVar set [2,_returnBag];
if (_deleteVeh) then {
_returnVar set [3,[1]];
PVDZ_obj_Destroy = [(_vehInfo select 2),(_vehInfo select 3),player];
publicVariableServer "PVDZ_obj_Destroy";
deleteVehicle (_vehInfo select 1);
};
_returnVar;

View File

@@ -100,6 +100,7 @@ if(isNil "Z_AdvancedTradingInit")then{
Z_payDefault = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_payDefault.sqf");
Z_calcDefaultCurrency = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_calcDefaultCurrency.sqf");
z_calcDefaultCurrencyNoImg = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_calcDefaultCurrencyNoImg.sqf");
DZE_deleteTradedVehicle = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\DZE_deleteTradedVehicle.sqf");
Z_AdvancedTradingInit = true;
};