Vehicle selling for advanced trading

This should work fairly okay but I expect there may be a couple exploits
and glitches
This commit is contained in:
icomrade
2016-04-28 18:35:03 -04:00
parent d2ba027863
commit 55f3a9dc79
6 changed files with 210 additions and 44 deletions

View File

@@ -13,9 +13,30 @@ private ["_weaps","_mags","_extraText","_all","_total","_arrayOfTraderCat","_tot
_weaps = _this select 0;
_mags = _this select 1;
_extraText = _this select 2;
_all = _weaps + _mags ;
_vehTrade = false;
if (call Z_checkCloseVehicle) then {
_all = _weaps + _mags + [(typeOf Z_vehicle)];
_vehTrade = true;
} else {
_all = _weaps + _mags;
};
_total = count(_all);
_arrayOfTraderCat = Z_traderData;
_HasKeyCheck = {
_obj = _this select 0;
_inventory = _this select 1;
_keyFound = false;
_objectCharacterId = _obj getVariable ["CharacterID","0"];
_keyColor = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
{
if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in _keyColor) then {
if (str(getNumber(configFile >> "CfgWeapons" >> _x >> "keyid")) == _objectCharacterId) then {
_keyFound = true;
};
};
} count _inventory;
_keyFound;
};
_totalPrice = 0;
if(_total > 0)then{
{
@@ -24,7 +45,6 @@ if(_total > 0)then{
private ["_cat","_excists","_pic","_text","_type","_sell","_buy","_buyCurrency","_sellCurrency","_worth"];
_cat = format["Category_%1",(_arrayOfTraderCat select _forEachIndex select 1)];
_excists = isClass(missionConfigFile >> "CfgTraderCategory" >> _cat >> _y );
if(_excists)exitWith{
_pic = "";
_text = "";
@@ -44,7 +64,7 @@ if(_total > 0)then{
};
case (_type in ["trade_backpacks", "trade_any_vehicle"]) :
{
_pic = getText (configFile >> 'CfgVehicles' >> _y >> 'displayName');
_pic = getText (configFile >> 'CfgVehicles' >> _y >> 'picture');
_text = getText (configFile >> 'CfgVehicles' >> _y >> 'displayName');
};
};
@@ -52,6 +72,11 @@ if(_total > 0)then{
if( isNil '_text')then{
_text = _y;
};
_HasKey = true;
if (_vehTrade && {(typeOf Z_vehicle) == _y}) then {
_HasKey = [Z_vehicle, _all] call _HasKeyCheck;
};
if (!_HasKey) exitWith {};
_worth = 0;

View File

@@ -4,13 +4,13 @@ _vehicle = objNull;
_list = nearestObjects [(getPosATL player), ["AllVehicles"], Z_VehicleDistance];
{
if(!isNull _x && local _x && !isPlayer _x && alive _x && !(_x isKindOf "zZombie_base"))then{
systemChat format["Selected %1",typeOf _x];
_vehicle = _x;
};
}count _list;
_result = false;
if(!isNull _vehicle)then{
Z_vehicle = _vehicle;
systemChat format["Selected %1",typeOf Z_vehicle];
_result = true;
[format["Buying in %1.", typeOf Z_vehicle]] call Z_filleTradeTitle;
};

View File

@@ -13,12 +13,12 @@ _vehicle = objNull;
_list = nearestObjects [(getPosATL player), ["AllVehicles"], Z_VehicleDistance];
{
if (!isNull _x && local _x && !isPlayer _x && alive _x && !(_x isKindOf "zZombie_base")) then {
systemChat format["Selected %1",typeOf _x];
_vehicle = _x;
};
}count _list;
if (!isNull _vehicle) then {
systemChat format["Selected %1",typeOf _vehicle];
_pic = getText (configFile >> 'CfgVehicles' >> (typeOf _vehicle) >> 'picture');
_formattedText = format [

View File

@@ -1,4 +1,4 @@
private ["_index","_tempArray","_outcome","_weaponsArray","_itemsArray","_bpArray","_bpCheckArray","_weaponsCheckArray","_itemsCheckArray"];
private ["_index","_tempArray","_outcome","_vehCheckArray","_vehArray","_weaponsArray","_itemsArray","_bpArray","_bpCheckArray","_weaponsCheckArray","_itemsCheckArray","_VehKey","_wA","_mA","_money","_itemData","_success"];
_index = count (Z_SellArray) - 1;
_tempArray = Z_SellArray;
@@ -9,8 +9,82 @@ if(_index > -1)then{
_itemsArray = [];
_bpArray = [];
_bpCheckArray = [];
_vehArray = [];
_vehCheckArray = [];
_weaponsCheckArray = [];
_itemsCheckArray = [];
_deleteTradedVehicle = {
private ["_localResult2","_VehKey2"];
_VehKey2 = _this select 0;
if ((count _VehKey2) > 0) then {
{
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;
_part_in = typeOf _vehicle;
_qty_in = 1;
_activatingPlayer = player;
_distance = Z_VehicleDistance;
_returnInfo = [];
_objects = nearestObjects [(getPosATL player), [_part_in], _distance];
_qty = ({(typeOf _x) == _part_in} count _objects);
if (_qty >= _qty_in) then {
_obj = (_objects select 0);
_hitpoints = _obj call vehicle_getHitpoints;
_okToSell = true;
_tires = 0;
_tireDmg = 0;
_damage = 0;
{
if(["Wheel",_x,false] call fnc_inString) then {
_damage = [_obj,_x] call object_getHit;
_tireDmg = _tireDmg + _damage;
_tires = _tires + 1;
};
} forEach _hitpoints;
if(_tireDmg > 0 && _tires > 0) then {
if((_tireDmg / _tires) > 0.75) then {
_okToSell = false;
};
};
_objectID = _obj getVariable ["ObjectID","0"];
_objectUID = _obj getVariable ["ObjectUID","0"];
_objectCharacterId = _obj getVariable ["CharacterID","0"];
_notSetup = (_objectID == "0" && _objectUID == "0");
if(local _obj && !isNull _obj && alive _obj && !_notSetup) then {
if(_okToSell) then {
_returnInfo = [_objectCharacterId, _obj, _objectID, _objectUID];
} else {
systemChat format[localize "str_epoch_player_182",_textPartIn]; _returnInfo = [];
};
} else {
systemChat format[localize "str_epoch_player_245"]; _returnInfo = [];
};
};
_returnInfo;
};
{
private ["_type","_name"];
_type = _x select 1;
@@ -32,24 +106,42 @@ if(_index > -1)then{
_bpArray set [count(_bpArray),_name];
_bpCheckArray set [count(_bpCheckArray),[_x select 2, _x select 11]];
};
case (_type == "trade_any_vehicle") :
{
if (local Z_vehicle) then {
_VehKey = Z_vehicle call _sellVehicle;
if (count _VehKey > 0) then {
_vehArray set [count(_vehArray),_VehKey];
_vehCheckArray set [count(_vehCheckArray),[_x select 2, _x select 11]];
};
}count Z_SellArray;
} else {
systemChat format["Get in the driver seat to be able to trade to your vehicle."];
};
};
};
}forEach Z_SellArray;
if(Z_SellingFrom == 0)then{
_outcome = [unitBackpack player,_itemsArray,_weaponsArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
_outcome = [unitBackpack player,_itemsArray,_weaponsArray, _vehArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
};
if(Z_SellingFrom == 1)then{
_outcome = [Z_vehicle,_itemsArray,_weaponsArray,_bpArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
_outcome = [Z_vehicle,_itemsArray,_weaponsArray,_bpArray, _vehArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
};
//gear
if(Z_SellingFrom == 2)then{
private ["_localResult", "_vehTraded"];
_wA = [];
_mA = [];
_vehTraded = false;
{
if (_x select 1 == "trade_any_vehicle") then {
_localResult = _vehArray call _deleteTradedVehicle;
if (_localResult == 1) then {_vehTraded = true;};
} else {
_localResult = [player,(_x select 0),1] call BIS_fnc_invRemove;
if( _localResult != 1)then{
if(_localResult != 1)then{
if(_x select 1 == "trade_items")then{
_mA set [count(_mA),0];
}else{
@@ -62,12 +154,16 @@ if(_index > -1)then{
_wA set [count(_wA),1];
};
};
};
}count Z_SellArray;
}forEach Z_SellArray;
_outcome set [0,_mA];
_outcome set [1,_wA];
_outcome set [2,[]];
if (_vehTraded) then {
_outcome set [3,[1]];
};
};
_money = 0;
@@ -82,6 +178,10 @@ if(_index > -1)then{
{
_money = _money + ( ( ((_bpCheckArray select _forEachIndex) select 0) ) * _x) ;
}forEach (_outcome select 2);
if (count _outcome > 3) then {
_money = _money + ((_vehCheckArray select 0) select 0);
};
} else {
{
_itemData = _itemsCheckArray select _forEachIndex;
@@ -95,8 +195,11 @@ if(_index > -1)then{
_itemData = _bpCheckArray select _forEachIndex;
_money = _money + ( (_itemData select 0) * (_itemData select 1) * _x);
}forEach (_outcome select 2);
if ((count _outcome) > 3) then {
_itemData = _vehCheckArray select 0;
_money = _money + ((_itemData select 0) * (_itemData select 1));
};
};
if(typeName _money == "SCALAR") then {
if (Z_SingleCurrency) then {
_success = [player,_money] call SC_fnc_addCoins;

View File

@@ -6,13 +6,28 @@
Author:
Zupa 2014-09-30
---------------------------------------------------------------------------- */
private ["_unit", "_items","_weaps","_normalItems","_normalWeaps", "_count", "_i", "_unit_allItems", "_unit_allItems_types", "_unit_allItems_count", "_item_type", "_item_count", "__returnVar"];
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"];
_unit = _this select 0;
_items = _this select 1;
_weaps = _this select 2;
_bags = [];
if(count _this > 3)then{
_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;
};
};
if (count _this == 5) then {
_vehInfo = (_this select 4) select 0;
_keyID = _vehInfo select 0;
};
};
_normalItems = [];
@@ -78,20 +93,6 @@ _normalItems = _normalItems - ["soldItem"];
_unit addMagazineCargoGlobal [_x, 1];
}count _normalItems;
{
_inCargo = _normalWeaps find _x;
if(_inCargo > -1)then{
_normalWeaps set [_inCargo, "soldItem"];
_returnWeap set [count(_returnWeap),1];
}else{
_returnWeap set [count(_returnWeap),0];
};
}count _weaps;
_normalWeaps = _normalWeaps - ["soldItem"];
{
_unit addWeaponCargoGlobal [_x, 1];
}count _normalWeaps;
{
_inCargo = _normalBags find _x;
if(_inCargo > -1)then{
@@ -101,12 +102,49 @@ _normalWeaps = _normalWeaps - ["soldItem"];
_returnBag set [count(_returnBag),0];
};
}count _bags;
_normalWeaps = _normalWeaps - ["soldItem"];
{
_unit addBackpackCargoGlobal [_x, 1];
}count _normalBags;
if (count _vehInfo > 0) 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;
};
{
_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];
};
}else{
_returnWeap set [count(_returnWeap),0];
};
}count _weaps;
_normalWeaps = _normalWeaps - ["soldItem"];
{
_unit addWeaponCargoGlobal [_x, 1];
}count _normalWeaps;
_normalWeaps = _normalWeaps - ["soldItem"];
_returnVar set [0,_returnMag];
_returnVar set [1,_returnWeap];
_returnVar set [2,_returnBag];
_returnVar
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

@@ -47,7 +47,7 @@ DZE_SafeZonePosArray = []; //Prevent players in safeZones from being killed if t
/****** Advanced Trading Variables ***********/
DZE_advancedTrading = true; //Use advanced trading system. WARNING: set to false if you use database traders, you should use config-traders anyway!
Z_AT_FolderLocation = '\z\addons\dayz_code\actions\AdvancedTrading';
Z_VehicleDistance = 30; // Distance that a vehicle needs to be to see it's content or to sell it.
Z_VehicleDistance = 40; // Distance that a vehicle needs to be to see it's content or to sell it.
Z_SingleCurrency = false; // Does your server use a single currency system.
Z_AllowTakingMoneyFromBackpack = true; // When buying items with DEFAULT CURRENCY to any inventory. Do you allow the trader to take money from your backpack.
Z_AllowTakingMoneyFromVehicle = true; // When buying items with DEFAULT CURRENCY to any inventory. Do you allow the trader to take money from your vehicle.