Handle not full mags in Trader

This commit is contained in:
He-Man 2018-01-13 15:12:54 +01:00
parent 3bbf2de4f5
commit 2ccb006697
10 changed files with 618 additions and 492 deletions

View File

@ -1,32 +1,30 @@
/*
Author: Aaron Clark - EpochMod.com
Author: He-Man - Ignatz-Gaming
Contributors: He-Man
Contributors: Raimonds Virtoss
Description:
NPC trade filter code
Filter Items in Trader Dialog
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/traders/EPOCH_NPCTraderMenuFilter.sqf
Example:
onLBSelChanged = "_this call EPOCH_NPCTraderMenuFilter";
Parameter(s):
_this select 0: CONTROL
_this select 1: NUMBER - Index ID
Returns:
NOTHING
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_NPCTraderFilter.sqf
*/
disableSerialization;
//[[[cog import generate_private_arrays ]]]
private ["_FilterArray","_MainCategorie","_MainCategoriearray","_SubCategorieItems","_aiItems","_config","_control","_display","_id","_isPlayerFilter","_item","_itemCount","_itemOfferCount","_items","_name","_offerArray","_picture","_playeritems","_qty","_qtys","_sizeOut","_slot","_sortarray","_subcategories","_type","_vehicles"];
//[[[end]]]
private [ "_PlayerFilerDropDown","_PlayerItemsBox","_PlayerItemsOutBox","_TraderItemsBox","_TraderItemsOutBox","_config","_MainCategoriearray","_FilterArray","_MainCategorie","_subcategories","_SubCategorieItems",
"_slot","_isPlayerFilter","_item","_rounds","_maxrnd","_tooltip","_qty","_id","_vehicles","_VehOfferArray","_sizeOut","_type","_itemCount","_itemOfferCount","_name","_picture","_items","_qtys","_sortarray"
];
params ["_control","_index"];
_PlayerFilerDropDown = 42100;
_PlayerItemsBox = 41500;
_PlayerItemsOutBox = 41501;
_TraderItemsBox = 41503;
_TraderItemsOutBox = 41502;
_config = 'CfgItemSort' call EPOCH_returnConfig;
_MainCategoriearray = getarray (_config >> "MainCategories" >> "Classes");
_FilterArray = [];
@ -46,96 +44,109 @@ if (_index != 0) then {
};
if !(isNull EPOCH_lastNPCtradeTarget) then {
_slot = EPOCH_lastNPCtradeTarget getVariable["AI_SLOT", -1];
_isPlayerFilter = (ctrlIDC _control == 42100);
if (_slot != -1) then {
_isPlayerFilter = (ctrlIDC _control == _PlayerFilerDropDown);
if (_isPlayerFilter) then {
_sizeOut = lbSize 41501;
_offerArray = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41501, _i];
_offerArray pushBack _item;
};
};
lbClear 41500;
_playeritems = ((items player)+(magazines player));
if (primaryWeapon player != "") then {
_playeritems pushback primaryWeapon player;
};
if (count backpackItems player == 0 && count backpackmagazines player == 0 && backpack player != "") then {
_playeritems pushback backpack player;
};
lbClear _PlayerItemsBox;
{
_item = _x;
_rounds = 1;
if (_item isequaltype []) then {
_item = _x select 0;
_rounds = _x select 1;
};
if !(_item isequalto "") then {
_maxrnd = 1;
_tooltip = "";
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_qty = _rounds/_maxrnd;
if (_qty < 1) then {
_tooltip = format ["%1 rounds left in Magazine",_rounds];
};
if (_index == 0 || (tolower _item) in _FilterArray) then {
_itemCount = {_x == _item} count ((items player)+(magazines player)+[backpack player]+[primaryweapon player]);
_itemOfferCount = {_x == _item} count _offerArray;
if (_itemCount > _itemOfferCount) then {
_offerArray pushBack _item;
_id = lbAdd [41500, _x call EPOCH_itemDisplayName];
lbSetData [41500, _id, _x];
lbSetPicture [41500, _id, _x call EPOCH_itemPicture];
_id = lbAdd [_PlayerItemsBox, _item call EPOCH_itemDisplayName];
lbSetData [_PlayerItemsBox, _id, _item];
lbSetValue [_PlayerItemsBox, _id, _rounds];
lbSetPicture [_PlayerItemsBox, _id, _item call EPOCH_itemPicture];
if !(_tooltip isequalto "") then {
lbSetTooltip [_PlayerItemsBox, _id, _tooltip];
lbSetColor [_PlayerItemsBox,_id,[1,(_rounds/_maxrnd),0,1]];
};
};
};
} forEach _playeritems;
} forEach EPOCH_NpcTradePlayerItems;
_vehicles = player nearEntities [["LandVehicle","Ship","Air","Tank"], 30];
{
if (local _x) then {
_type = typeOf _x;
if (_index == 0 || (tolower _type) in _FilterArray) then {
_itemCount = { typeOf _x == _type } count _vehicles;
_itemOfferCount = { _x == _type } count _offerArray;
if (_itemCount > _itemOfferCount) then {
_offerArray pushBack _type;
_config = configFile >> "CfgVehicles" >> _type;
_name = getText(_config >> "displayName");
_picture = getText(_config >> "picture");
_id = lbAdd[41500, _name];
lbSetData[41500, _id, _type];
lbSetPicture[41500, _id, _picture];
if !(_vehicles isequalto []) then {
_VehOfferArray = [];
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
if (_item iskindof "Landvehicle" || _item iskindof "AIR" || _item iskindof "SHIP" || _item iskindof "TANK") then {
_VehOfferArray pushBack _item;
};
};
};
} forEach _vehicles;
_display = (findDisplay -8);
_control = (_display displayCtrl 41500);
lbsort _control;
{
if (local _x) then {
_type = typeOf _x;
if (_index == 0 || (tolower _type) in _FilterArray) then {
_itemCount = { typeOf _x == _type } count _vehicles;
_itemOfferCount = { _x == _type } count _VehOfferArray;
if (_itemCount > _itemOfferCount) then {
_config = configFile >> "CfgVehicles" >> _type;
_name = getText(_config >> "displayName");
_picture = getText(_config >> "picture");
_id = lbAdd[_PlayerItemsBox, _name];
lbSetData[_PlayerItemsBox, _id, _type];
lbSetValue [_PlayerItemsBox, _id, 1];
lbSetPicture[_PlayerItemsBox, _id, _picture];
};
};
};
} forEach _vehicles;
};
lbsort ((findDisplay -8) displayCtrl _PlayerItemsBox);
}
else {
lbClear 41503;
_sizeOut = lbSize 41502;
_offerArray = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_id = lbData [41502, _i];
_offerArray pushBack _id;
};
};
_aiItems = EPOCH_lastNPCtradeTarget getVariable["AI_ITEMS", []];
if ((count _aiItems) == 2) then {
_items = _aiItems select 0;
_qtys = _aiItems select 1;
lbClear _TraderItemsBox;
if ((count EPOCH_NpcTradeTraderItems) == 2) then {
_items = EPOCH_NpcTradeTraderItems select 0;
_qtys = EPOCH_NpcTradeTraderItems select 1;
_sortarray = [];
{
_sortarray pushback [_x call EPOCH_itemDisplayName,_x,_qtys select _foreachindex];
} foreach _items;
_sortarray sort true;
{
_item = _x select 1;
_x params ["_displayname","_item","_rounds"];
if !(_item isequalto "") then {
if (_index == 0 || (tolower _item) in _FilterArray) then {
_qty = ((_x select 2) - ({_x == _item} count _offerArray));
_maxrnd = 1;
_tooltip = "";
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_qty = (_rounds/_maxrnd);
if (_qty >= 1) then {
_qty = floor _qty;
}
else {
_qty = ceil _qty;
_tooltip = format ["%1 rounds left in Magazine",_rounds];
};
if (_qty > 0) then {
_id = lnbAddRow[41503, ["", str(_qty),_x select 0]];
lnbSetData [41503, [_id,0], _item];
lnbSetValue [41503, [_id,0], _qty];
lnbSetPicture [41503, [_id,0], _item call EPOCH_itemPicture];
_id = lnbAddRow [_TraderItemsBox, ["", str(_qty),_displayname]];
lnbSetData [_TraderItemsBox, [_id,0], _item];
lnbSetValue [_TraderItemsBox, [_id,0], _rounds];
lnbSetPicture [_TraderItemsBox, [_id,0], _item call EPOCH_itemPicture];
if !(_tooltip isequalto "") then {
lbSetTooltip [_TraderItemsBox, _id*3, _tooltip];
lnbSetColor [_TraderItemsBox,[_id,2],[1,(_rounds/_maxrnd),0,1]];
};
};
};
};

View File

@ -1,7 +1,7 @@
/*
Author: Aaron Clark - EpochMod.com
Contributors: He-Man
Contributors: He-Man - Ignatz-Gaming
Description:
NPC trade code
@ -22,7 +22,7 @@
NOTHING
*/
//[[[cog import generate_private_arrays ]]]
private ["_addWeaponToHands","_arrayIn","_arrayOut","_config","_current_crypto","_errorMsg","_item","_itemTax","_itemWorth","_sizeOut","_tax","_type","_vehSlot","_vehicle","_vehicles"];
private ["_addWeaponToHands","_item","_type"];
//[[[end]]]
params [["_returnIn",[]],["_returnOut",[]],["_message",""]];
@ -31,8 +31,9 @@ if (isNil "EPOCH_TRADE_STARTED") exitWith{};
if !(_returnOut isEqualTo[]) then {
// add purchased items
{
if ([_x, "CfgWeapons"] call EPOCH_fnc_isAny) then {
_type = getNumber(configfile >> "CfgWeapons" >> (_x) >> "type");
_x params ["_item","_count"];
if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then {
_type = getNumber(configfile >> "CfgWeapons" >> _item >> "type");
_addWeaponToHands = false;
switch (_type) do {
case 1: {
@ -52,15 +53,15 @@ if !(_returnOut isEqualTo[]) then {
};
};
if (_addWeaponToHands) then {
player addWeapon _x;
player addWeapon _item;
}
else {
_x call EPOCH_fnc_addItemOverflow;
_item call EPOCH_fnc_addItemOverflow;
};
}
else {
if ([_x, "CfgMagazines"] call EPOCH_fnc_isAny) then {
_x call EPOCH_fnc_addItemOverflow;
if ([_item, "CfgMagazines"] call EPOCH_fnc_isAny) then {
[_item,_count] call EPOCH_fnc_addMagazineOverflow;
};
};
} forEach _returnOut;
@ -71,3 +72,4 @@ if !(_message isequalto "") then {
};
EPOCH_TRADE_STARTED = nil;

View File

@ -1,39 +1,91 @@
//[[[cog import generate_private_arrays ]]]
private ["_errormsg","_aiItems","_allowAdd","_array","_config","_cryptoCount","_index","_item","_itemClasses","_itemQtys","_itemTax","_itemWorth","_limit","_qtyIndex","_sizeOut","_slot","_stockLimit","_tax","_uiItem","_worth"];
//[[[end]]]
/*
Author: He-Man - Ignatz-Gaming
Contributors: Raimonds Virtoss
Description:
Move Items in Tradermenu between Playerinventory <-> PlayerOut window
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd.sqf
*/
private [ "_PlayerFilerDropDown","_PlayerItemsBox","_PlayerItemsOutBox","_TraderItemsOutBox","_CryptoInCtrl","_CryptoOutCtrl","_allowAdd","_uiItem","_rounds","_itemIcon","_itemColor","_errormsg","_stockLimit","_config",
"_itemClasses","_itemQtys","_qtyIndex","_limit","_sizeOut","_item","_vehicle","_itemName","_index","_maxrnd","_ItemIndex","_cryptoCount","_worth","_itemTax","_tax"
];
params ["_control","_selected"];
_selected params ["_CurControl","_id"];
_PlayerFilerDropDown = 42100;
_PlayerItemsBox = 41500;
_PlayerItemsOutBox = 41501;
_TraderItemsOutBox = 41502;
_CryptoInCtrl = 41004;
_CryptoOutCtrl = 41005;
if !(isNull EPOCH_lastNPCtradeTarget) then {
_allowAdd = true;
_uiItem = _CurControl lbData _id;
_rounds = _CurControl lbValue _id;
_itemIcon = _CurControl lbPicture _id;
_itemColor = _CurControl lbColor _id;
_errormsg = "";
_stockLimit = false;
_uiItem = (_selected select 0) lbData (_selected select 1);
_errormsg = "Limit one per trade";
_config = 'CfgPricing' call EPOCH_returnConfig;
if (isClass(_config >> _uiItem)) then{
if !(_control in[41500, 41503]) then {
// limit adding more if item is over stocked
if (_control == 41501) then {
_slot = EPOCH_lastNPCtradeTarget getVariable["AI_SLOT", -1];
_aiItems = EPOCH_lastNPCtradeTarget getVariable["AI_ITEMS", [[], []] ];
_itemClasses = _aiItems select 0;
_itemQtys = _aiItems select 1;
// find item and get current qty
_qtyIndex = _itemClasses find _uiItem;
if (_qtyIndex != -1) then {
_limit = ["CfgTraderLimits", _uiItem, 100] call EPOCH_fnc_returnConfigEntryV2;
if (_itemQtys select _qtyIndex >= _limit) then{
_stockLimit = true;
_allowAdd = false;
if (isClass (_config >> _uiItem)) then {
if (_control == _PlayerItemsOutBox) then {
_itemClasses = EPOCH_NpcTradeTraderItems select 0;
_itemQtys = EPOCH_NpcTradeTraderItems select 1;
_qtyIndex = _itemClasses find _uiItem;
if (_qtyIndex != -1) then {
_itemQty = _itemQtys select _qtyIndex;
_maxrnd = 1;
if ([_uiItem,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _uiItem >> "count");
};
_itemQty = _itemQty / _maxrnd;
_sizeIn = lbSize _PlayerItemsOutBox;
if (_sizeIn > 0) then {
for "_i" from 0 to (_sizeIn - 1) do {
_InItem = lbData [_PlayerItemsOutBox, _i];
if ((lbData [_PlayerItemsOutBox, _i]) == _uiItem) then {
_itemQty = _itemQty + ((lbValue [_PlayerItemsOutBox, _i])/_maxrnd);
};
};
};
_limit = ["CfgTraderLimits", _uiItem, 100] call EPOCH_fnc_returnConfigEntryV2;
if (_itemQty >= _limit) then{
_stockLimit = true;
_allowAdd = false;
};
};
if (_uiItem isKindOf "Air" || _uiItem isKindOf "Ship" || _uiItem isKindOf "LandVehicle" || _uiItem isKindOf "Tank") then {
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
_errormsg = "Limit one per trade";
};
};
};
if (!_allowAdd) exitwith {};
_sizeOut = lbSize _TraderItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[_TraderItemsOutBox, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
_errormsg = "Limit one per trade";
};
};
};
if (!_allowAdd) exitwith {};
if (["CfgEpochClient", "DisallowSellOnDamage", false] call EPOCH_fnc_returnConfigEntryV2) then {
{
_vehicle = _x;
@ -49,73 +101,87 @@ if !(isNull EPOCH_lastNPCtradeTarget) then {
} foreach ((getAllHitPointsDamage _vehicle) select 0);
};
if (!_allowAdd) exitwith {};
} foreach (EPOCH_lastNPCtradeTarget nearEntities[[_uiItem], 30]);
} foreach (EPOCH_lastNPCtradeTarget nearEntities [[_uiItem], 30]);
};
// check if a vehicle is already on the list
_sizeOut = lbSize 41501;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41501, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
};
};
};
_sizeOut = lbSize 41502;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41502, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
};
};
};
// disallow adding item to list of already one
};
};
if (_allowAdd) then {
_index = lbAdd[_control, ((_selected select 0) lbText(_selected select 1))];
lbSetData[_control, _index, _uiItem];
lbSetPicture[_control, _index, ((_selected select 0) lbPicture(_selected select 1))];
(_selected select 0) lbDelete(_selected select 1);
_itemName = _CurControl lbText _id;
_index = lbAdd [_control, _itemName];
lbSetData [_control, _index, _uiItem];
lbSetValue [_control,_index, _rounds];
lbSetPicture [_control, _index, _itemIcon];
lbSetColor [_control,_index,_itemColor];
if (_control == _PlayerItemsBox && !(_uiItem iskindof "Landvehicle" || _uiItem iskindof "SHIP" || _uiItem iskindof "AIR" || _uiItem iskindof "TANK")) then {
EPOCH_NpcTradePlayerItems pushback [_uiItem,_rounds];
}
else {
if ([_uiItem,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _uiItem >> "count");
if !((_rounds/_maxrnd) >= 1) then {
_tooltip = format ["%1 rounds left in Magazine",_rounds];
lbSetTooltip [_control,_index,_tooltip];
};
};
_ItemIndex = EPOCH_NpcTradePlayerItems find [_uiItem,_rounds];
if (_ItemIndex < 0) then {
_ItemIndex = EPOCH_NpcTradePlayerItems find _uiItem;
};
if (_ItemIndex > -1) then {
EPOCH_NpcTradePlayerItems deleteat _ItemIndex;
};
};
_CurControl lbDelete _id;
_cryptoCount = 0;
_sizeOut = lbSize 41501;
//_array = [];
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41501, _i];
//_array pushBack _item;
_worth = getNumber(_config >> _item >> "price");
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
_rounds = lbValue [_PlayerItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText[41004, (format["%1 Krypto", _cryptoCount])];
ctrlSetText [_CryptoInCtrl, (format["%1 Krypto", _cryptoCount])];
_cryptoCount = 0;
_sizeOut = lbSize 41502;
_sizeOut = lbSize _TraderItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41502, _i];
_itemWorth = getNumber(_config >> _item >> "price");
_itemTax = getNumber(_config >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
_cryptoCount = _cryptoCount + _itemWorth;
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_TraderItemsOutBox, _i];
_rounds = lbValue [_TraderItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_itemTax = getNumber (_config >> _item >> "tax");
_tax = _worth * (EPOCH_taxRate + _itemTax);
_worth = ceil(_worth + _tax);
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText[41005, (format["%1 Krypto", _cryptoCount])];
} else {
ctrlSetText [_CryptoOutCtrl, (format["%1 Krypto", _cryptoCount])];
if (_control == _PlayerItemsBox) then {
lbSetCurSel [_PlayerFilerDropDown, 0];
};
}
else {
if (_stockLimit) then{
["Trader has the maximum amount of this item", 5] call Epoch_message;
} else {
}
else {
[_errormsg, 5] call Epoch_message;
};
};
};
} else {
}
else {
closeDialog 0;
};

View File

@ -1,88 +1,156 @@
//[[[cog import generate_private_arrays ]]]
private ["_allowAdd","_array","_config","_cryptoCount","_index","_item","_itemIcon","_itemName","_itemTax","_itemWorth","_qty","_sizeOut","_tax","_uiItem","_uiQty","_worth"];
//[[[end]]]
/*
Author: He-Man - Ignatz-Gaming
Contributors: Raimonds Virtoss
Description:
Move Items in Tradermenu from Traderinventory to TraderOut window
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd2.sqf
*/
private [ "_PlayerItemsOutBox","_TraderItemsBox","_TraderItemsOutBox","_CryptoInCtrl","_CryptoOutCtrl","_allowAdd","_uiItem","_rounds","_itemIcon","_itemName","_itemColor","_errormsg","_soldrounds","_tooltip","_config",
"_ItemIndex","_sizeOut","_item","_maxrnd","_uiQty","_index","_cryptoCount","_worth","_itemTax","_tax"
];
params ["_control","_selected"];
_selected params ["_CurControl","_id"];
_allowAdd = true;
_PlayerItemsOutBox = 41501;
_TraderItemsBox = 41503;
_TraderItemsOutBox = 41502;
_CryptoInCtrl = 41004;
_CryptoOutCtrl = 41005;
_uiItem = (_selected select 0) lnbData[(_selected select 1), 0];
_config = 'CfgPricing' call EPOCH_returnConfig;
if (isClass (_config >> _uiItem)) then{
if (_uiItem isKindOf "Air" || _uiItem isKindOf "Ship" || _uiItem isKindOf "LandVehicle" || _uiItem isKindOf "Tank") then {
// check if a vehicle is already on the list
_sizeOut = lbSize 41501;
//_array = [];
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41501, _i];
//_array pushBack _item;
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
if !(isNull EPOCH_lastNPCtradeTarget) then {
_allowAdd = true;
_uiItem = _CurControl lnbData [_id, 0];
_rounds = _CurControl lnbValue [_id, 0];
_itemIcon = _CurControl lnbPicture [_id, 0];
_itemName = _CurControl lnbText [_id, 2];
_itemColor = _CurControl lnbColor [_id, 2];
_errormsg = "";
_soldrounds = 0;
_tooltip = "";
_config = 'CfgPricing' call EPOCH_returnConfig;
if (isClass (_config >> _uiItem)) then{
_ItemIndex = (EPOCH_NpcTradeTraderItems select 0) find _uiItem;
if (_ItemIndex > -1) then {
if (_uiItem isKindOf "Air" || _uiItem isKindOf "Ship" || _uiItem isKindOf "LandVehicle" || _uiItem isKindOf "Tank") then {
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
_errormsg = "Limit one per trade";
};
};
};
if (!_allowAdd) exitwith {};
_sizeOut = lbSize _TraderItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData [_TraderItemsOutBox, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
_errormsg = "Limit one per trade";
};
};
};
};
};
_sizeOut = lbSize 41502;
//_array = [];
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41502, _i];
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") exitWith{
_allowAdd = false;
if (_allowAdd) then {
_maxrnd = 1;
if ([_uiItem,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _uiItem >> "count");
};
if ((_rounds/_maxrnd) >= 1) then {
_soldrounds = _maxrnd;
}
else {
_soldrounds = _rounds;
};
_rounds = _rounds - _soldrounds;
if (_rounds < 1) then {
_CurControl lnbDeleteRow _id;
}
else {
_uiQty = _rounds /_maxrnd;
if (_uiQty >= 1) then {
_uiQty = floor _uiQty;
}
else {
_uiQty = ceil _uiQty;
_tooltip = format ["%1 rounds left in Magazine",_rounds];
};
lnbSetText [_TraderItemsBox, [_id, 1], str (_uiQty)];
lnbSetValue [_TraderItemsBox, [_id, 0], _rounds];
if !(_tooltip isequalto "") then {
lbSetTooltip [_TraderItemsBox, _id*3, _tooltip];
lnbSetColor [_TraderItemsBox,[_id,2],[1,(_rounds/_maxrnd),0,1]];
};
};
if (_soldrounds > 0) then {
_index = lbAdd [_control, _itemName];
lbSetData [_control, _index, _uiItem];
lbSetValue [_control,_index, _soldrounds];
lbSetPicture [_control, _index, _itemIcon];
lbSetColor [_control,_index,_itemColor];
if ([_uiItem,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _uiItem >> "count");
if !((_soldrounds/_maxrnd) >= 1) then {
_tooltip = format ["%1 rounds left in Magazine",_soldrounds];
lbSetTooltip [_control,_index,_tooltip];
};
};
};
(EPOCH_NpcTradeTraderItems select 1) set [_ItemIndex,_rounds];
_cryptoCount = 0;
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
_rounds = lbValue [_PlayerItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [_CryptoInCtrl, (format["%1 Krypto", _cryptoCount])];
_cryptoCount = 0;
_sizeOut = lbSize _TraderItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_TraderItemsOutBox, _i];
_rounds = lbValue [_TraderItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_itemTax = getNumber (_config >> _item >> "tax");
_tax = _worth * (EPOCH_taxRate + _itemTax);
_worth = ceil(_worth + _tax);
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [_CryptoOutCtrl, (format["%1 Krypto", _cryptoCount])];
}
else {
["Limit one per trade", 5] call Epoch_message;
};
};
// disallow adding item to list of already one
};
if (_allowAdd) then {
_itemName = (_selected select 0) lnbText[(_selected select 1), 2];
_index = lbAdd [_control, _itemName];
lbSetData [_control, _index, _uiItem];
_itemIcon = (_selected select 0) lnbPicture [(_selected select 1), 0];
lbSetPicture [_control, _index, _itemIcon];
_uiQty = (_selected select 0) lnbValue [(_selected select 1), 0];
if (_uiQty <= 1) then {
(_selected select 0) lnbDeleteRow (_selected select 1);
} else {
_qty = _uiQty - 1;
lnbSetText[41503, [(_selected select 1), 1], str(_qty)];
lnbSetValue[41503, [(_selected select 1), 0], _qty];
};
_cryptoCount = 0;
_sizeOut = lbSize 41501;
//_array = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41501, _i];
//_array pushBack _item;
_worth = getNumber(_config >> _item >> "price");
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [41004, (format ["%1 Krypto", _cryptoCount])];
_cryptoCount = 0;
_sizeOut = lbSize 41502;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41502, _i];
_itemWorth = getNumber(_config >> _item >> "price");
_itemTax = getNumber(_config >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
_cryptoCount = _cryptoCount + _itemWorth;
};
};
ctrlSetText [41005, (format ["%1 Krypto", _cryptoCount])];
} else {
["Limit one per trade", 5] call Epoch_message;
};
};

View File

@ -1,41 +1,72 @@
//[[[cog import generate_private_arrays ]]]
private ["_array","_config","_cryptoCount","_item","_itemTax","_itemWorth","_sizeOut","_tax","_uiItem","_worth"];
//[[[end]]]
params ["_control","_selected"];
/*
Author: He-Man - Ignatz-Gaming
_uiItem = (_selected select 0) lbData(_selected select 1);
Contributors: Raimonds Virtoss
Description:
Move Items in Tradermenu from TraderOut window to Traderinventory
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd3.sqf
*/
private ["_TraderFilerDropDown","_PlayerItemsOutBox","_TraderItemsOutBox","_CryptoInCtrl","_CryptoOutCtrl","_uiItem","_rounds","_config","_ItemIndex","_cryptoCount","_sizeOut","_item","_worth","_maxrnd","_itemTax","_tax"];
params ["_control","_selected"];
_selected params ["_CurControl","_id"];
_TraderFilerDropDown = 42101;
_PlayerItemsOutBox = 41501;
_TraderItemsOutBox = 41502;
_CryptoInCtrl = 41004;
_CryptoOutCtrl = 41005;
_uiItem = _CurControl lbData _id;
_rounds = _CurControl lbValue _id;
_config = 'CfgPricing' call EPOCH_returnConfig;
if (isClass (_config >> _uiItem)) then{
(_selected select 0) lbDelete (_selected select 1);
lbSetCurSel[42101, 0];
if (isClass (_config >> _uiItem)) then {
_ItemIndex = (EPOCH_NpcTradeTraderItems select 0) find _uiItem;
if (_ItemIndex >= 0) then {
(EPOCH_NpcTradeTraderItems select 1) set [_ItemIndex,(EPOCH_NpcTradeTraderItems select 1 select _ItemIndex) + _rounds];
};
_CurControl lbDelete _id;
lbSetCurSel [_TraderFilerDropDown, 0];
_cryptoCount = 0;
_sizeOut = lbSize 41501;
//_array = [];
_sizeOut = lbSize _PlayerItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41501, _i];
//_array pushBack _item;
_worth = getNumber(_config >> _item >> "price");
_item = lbData [_PlayerItemsOutBox, _i];
_rounds = lbValue [_PlayerItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [41004, (format ["%1 Krypto", _cryptoCount])];
ctrlSetText [_CryptoInCtrl, (format["%1 Krypto", _cryptoCount])];
_cryptoCount = 0;
_sizeOut = lbSize 41502;
_sizeOut = lbSize _TraderItemsOutBox;
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41502, _i];
_itemWorth = getNumber(_config >> _item >> "price");
_itemTax = getNumber(_config >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
_cryptoCount = _cryptoCount + _itemWorth;
_item = lbData [_TraderItemsOutBox, _i];
_rounds = lbValue [_TraderItemsOutBox, _i];
_worth = getNumber (_config >> _item >> "price");
_itemTax = getNumber (_config >> _item >> "tax");
_tax = _worth * (EPOCH_taxRate + _itemTax);
_worth = ceil (_worth + _tax);
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_worth = round (_worth*(_rounds/_maxrnd));
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [41005, (format ["%1 Krypto", _cryptoCount])];
ctrlSetText [_CryptoOutCtrl, (format["%1 Krypto", _cryptoCount])];
};

View File

@ -1,6 +1,19 @@
//[[[cog import generate_private_arrays ]]]
private ["_MainCategoriearray","_categorie","_config","_ok","_slot","_target"];
//[[[end]]]
/*
Author: He-Man - Ignatz-Gaming
Contributors: Raimonds Virtoss
Description:
Start the Trader Trading Menu
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_startNPCTraderMenu.sqf
*/
private ["_config","_MainCategoriearray","_target","_slot","_index","_ok","_categorie"];
_config = 'CfgItemSort' call EPOCH_returnConfig;
_MainCategoriearray = getarray (_config >> "MainCategories" >> "Classes");
_target = cursorTarget;
@ -8,6 +21,20 @@ if (alive _target) then {
_slot = _target getVariable ["AI_SLOT",-1];
if (_slot != -1) then {
EPOCH_lastNPCtradeTarget = _target;
EPOCH_NpcTradePlayerItems = (items player)+(magazinesammo player);
if (primaryWeapon player != "") then {
EPOCH_NpcTradePlayerItems pushback primaryWeapon player;
};
if (count backpackItems player == 0 && count backpackmagazines player == 0 && backpack player != "") then {
EPOCH_NpcTradePlayerItems pushback backpack player;
};
EPOCH_NpcTradeTraderItems = [[],[]];
{
_index = _foreachindex;
{
(EPOCH_NpcTradeTraderItems select _index) pushback _x;
} foreach _x
} foreach (_target getvariable ["AI_Items",[[],[]]]);
closeDialog 0;
_ok = createdialog "TradeNPCMenu";
if (!_ok) exitWith {};
@ -15,10 +42,10 @@ if (alive _target) then {
((uiNamespace getVariable "EPOCH_EpochGameUI2") displayCtrl 21208) ctrlSetText format["%1", EPOCH_playerCrypto];
{
_categorie = _x select 1;
lbAdd[42100,_categorie];
lbAdd[42101,_categorie]
lbAdd [42100,_categorie];
lbAdd [42101,_categorie]
} forEach _MainCategoriearray;
lbSetCurSel[42100, 0];
lbSetCurSel[42101, 0];
lbSetCurSel [42100, 0];
lbSetCurSel [42101, 0];
};
};

View File

@ -1,65 +1,64 @@
/*
Author: Aaron Clark - EpochMod.com
Author: He-Man - Ignatz-Gaming
Contributors: He-Man
Contributors: Raimonds Virtoss
Description:
NPC trade code
Move Items in Tradermenu from TraderOut window to Traderinventory
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/traders/EPOCH_startNpcTrade.sqf
Example:
cursorTarget call EPOCH_startNpcTrade;
Parameter(s):
_this: OBJECT
Returns:
NOTHING
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_startNpcTrade.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_addWeaponToHands","_arrayIn","_arrayOut","_config","_current_crypto","_errorMsg","_item","_itemTax","_itemWorth","_sizeOut","_tax","_type","_vehSlot","_vehicle","_vehicles"];
//[[[end]]]
private ["_PlayerItemsOutBox","_TraderItemsOutBox","_config","_current_crypto","_sizeIn","_arrayIn","_item","_rounds","_mags","_itemMags","_index","_sizeOut","_arrayOut","_itemWorth","_itemTax","_tax","_maxrnd"];
if (!isNil "EPOCH_TRADE_STARTED") exitWith{};
if (isNull _this) exitWith{};
if (alive _this) then {
_PlayerItemsOutBox = 41501;
_TraderItemsOutBox = 41502;
_config = 'CfgPricing' call EPOCH_returnConfig;
_current_crypto = EPOCH_playerCrypto;
// _arrayIn = Sell Array
_sizeOut = lbSize 41501;
_sizeIn = lbSize _PlayerItemsOutBox;
_arrayIn = [];
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41501, _i];
if (_sizeIn > 0) then {
for "_i" from 0 to (_sizeIn - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
_rounds = lbValue [_PlayerItemsOutBox, _i];
if (isClass (_config >> _item)) then{
// test remove items to be sold and add to array
_itemWorth = getNumber (_config >> _item >> "price");
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_itemWorth = round (_itemWorth*(_rounds/_maxrnd));
_added = false;
if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then {
if (_item in items player) then {
player removeItem _item;
_arrayIn pushBack _item;
} else {
_arrayIn pushBack [_item,_rounds];
_added = true;
}
else {
if (_item == primaryweapon player) then {
player removeweapon _item;
_arrayIn pushBack _item;
_arrayIn pushBack [_item,_rounds];
_added = true;
};
};
} else {
}
else {
if ([_item, "CfgVehicles"] call EPOCH_fnc_isAny) then {
if (_item == backpack player) then {
removeBackpack player;
_arrayIn pushBack _item;
} else {
_arrayIn pushBack [_item,_rounds];
_added = true;
}
else {
_vehicles = _this nearEntities[[_item], 30];
if (!(_vehicles isEqualTo[])) then {
_vehicle = _vehicles select 0;
@ -67,56 +66,66 @@ if (alive _this) then {
if (local _vehicle) then {
_vehSlot = _vehicle getVariable["VEHICLE_SLOT", "ABORT"];
if (_vehSlot != "ABORT") then {
_arrayIn pushBack _item;
// will be removed server side
_arrayIn pushBack [_item,_rounds];
_added = true;
};
};
};
};
};
} else {
if (_item in magazines player) then {
player removeMagazine _item;
_arrayIn pushBack _item;
}
else {
_mags = magazinesAmmo player;
_itemMags = [];
{
_x params ["_className","_count"];
if (_className isequalto _item) then {
_itemMags pushBack _x;
};
} forEach _mags;
_index = _itemMags find [_item,_rounds];
if (_index >= 0) then {
_arrayIn pushback (_itemMags deleteat _index);
_added = true;
player removemagazines _item;
{
player addmagazine _x;
} foreach _itemMags;
};
};
};
// test
};
};
};
// _arrayOut = Purchase Array
_sizeOut = lbSize 41502;
_arrayOut = [];
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41502, _i];
if (isClass (_config >> _item)) then{
_itemWorth = getNumber(_config >> "price");
_itemTax = getNumber(_config >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
if (_current_crypto >= _itemWorth) then {
_current_crypto = _current_crypto - _itemWorth;
_arrayOut pushBack _item;
if (_added) then {
_current_crypto = _current_crypto + _itemWorth;
};
};
};
};
if (!(_arrayIn isEqualTo[]) || !(_arrayOut isEqualTo[])) then {
_sizeOut = lbSize _TraderItemsOutBox;
_arrayOut = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [_TraderItemsOutBox, _i];
_rounds = lbValue [_TraderItemsOutBox, _i];
if (isClass (_config >> _item)) then {
_itemWorth = getNumber (_config >> _item >> "price");
_itemTax = getNumber (_config >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil (_itemWorth + _tax);
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_itemWorth = round (_itemWorth*(_rounds/_maxrnd));
if (_current_crypto >= _itemWorth) then {
_current_crypto = _current_crypto - _itemWorth;
_arrayOut pushBack [_item,_rounds];
};
};
};
};
if !(_arrayIn isEqualTo[] && _arrayOut isEqualTo[]) then {
EPOCH_TRADE_STARTED = true;
// make trade
[_this, _arrayIn, _arrayOut, player, Epoch_personalToken] remoteExec ["EPOCH_server_makeNPCTrade",2];
// close menu
closeDialog 0;
};
};

View File

@ -1,67 +0,0 @@
disableSerialization;
//[[[cog import generate_private_arrays ]]]
private ["_array","_filterArray","_item","_items","_magazines","_sizeOut","_weapons","_xIndex"];
//[[[end]]]
params ["_control","_index"];
// [weapons, mags, items]
_filterArray = [
[true,true,true], // all
// [true,false,false], // weapons only
[false,true,false], // mags only
[false,false,true] // items only
];
lbClear 1500;
// _weapons = ((_filterArray select _index) select 0);
_magazines = ((_filterArray select _index) select 1);
_items = ((_filterArray select _index) select 2);
_sizeOut = lbSize 1501;
_array = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [1501, _i];
_array pushBack _item;
};
};
/*
if (_weapons) then {
{
if !(_x in _array) then {
_xIndex = lbAdd [1500, _x call EPOCH_itemDisplayName];
lbSetData [1500, _xIndex, _x];
lbSetPicture [1500, _xIndex, _x call EPOCH_itemPicture];
} else {
_array set [_array find _x,nil];
};
} forEach weapons player;
};
*/
if (_magazines) then {
{
if (getNumber(configfile >> "CfgMagazines" >> _x >> "count") == 1) then {
if !(_x in _array) then {
_xIndex = lbAdd[1500, _x call EPOCH_itemDisplayName];
lbSetData[1500, _xIndex, _x];
lbSetPicture[1500, _xIndex, _x call EPOCH_itemPicture];
}
else {
_array set[_array find _x, nil];
};
};
} forEach magazines player;
};
if (_items) then {
{
if !(_x in _array) then {
_xIndex = lbAdd [1500, _x call EPOCH_itemDisplayName];
lbSetData [1500, _xIndex, _x];
lbSetPicture [1500, _xIndex, _x call EPOCH_itemPicture];
} else {
_array set [_array find _x,nil];
};
} forEach items player;
};

View File

@ -79,7 +79,6 @@ class CfgClientFunctions
class startNPCTraderMenu {};
class NPCTraderMenuFilter {};
class startNpcTrade {};
class tradeFilter {};
class takeCrypto {};
class startBankTransfer {};
class calcDamageCost {};

View File

@ -1,7 +1,7 @@
/*
Author: Aaron Clark - EpochMod.com
Contributors:
Contributors: He-Man - Ignatz-Gaming
Description:
NPC trade mech
@ -12,9 +12,13 @@
Github:
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_trading/EPOCH_server_makeNPCTrade.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_MaxBankDebit","_SkipOut","_VAL","_aiItems","_bankBalance","_bankData","_cIndex","_config","_currQty","_current_crypto","_current_cryptoRaw","_errorMsg","_final_location","_foundSmoke","_group","_helipad","_helipads","_item","_itemClasses","_itemQty","_itemQtys","_itemTax","_itemWorth","_itemsIn","_itemsOut","_lockOwner","_makeTradeIn","_message","_nearByHolder","_objHiveKey","_objOwner","_playerCryptoLimit","_playerGroup","_playerNetID","_playerUID","_position","_qtyIndex","_response","_return","_returnIn","_returnOut","_road","_serverSettingsConfig","_slot","_smoke","_tax","_tmpposition","_tradeIn","_tradeOut","_tradeQtyTotal","_tradeTotal","_vars","_vehHiveKey","_vehObj","_vehSlot","_vehicle","_vehicleBought","_vehicleSold","_vehicles","_vehslot","_wH","_wHPos","_wp","_kIndex","_playerCStats","_playerKarma","_playerKarmaAdj"];
//[[[end]]]
private [ "_MaxBankDebit","_SkipOut","_VAL","_aiItems","_bankBalance","_bankData","_cIndex","_config","_currQty","_current_crypto","_current_cryptoRaw","_errorMsg","_final_location","_foundSmoke",
"_group","_helipad","_helipads","_item","_itemClasses","_itemQty","_itemQtys","_itemTax","_itemWorth","_itemsIn","_itemsOut","_lockOwner","_makeTradeIn","_message","_nearByHolder",
"_objHiveKey","_objOwner","_playerCryptoLimit","_playerGroup","_playerNetID","_playerUID","_position","_qtyIndex","_response","_return","_returnIn","_returnOut","_road",
"_serverSettingsConfig","_slot","_smoke","_tax","_tmpposition","_tradeIn","_tradeOut","_tradeQtyTotal","_tradeTotal","_vars","_vehHiveKey","_vehObj","_vehSlot","_vehicle","_vehicleBought",
"_vehicleSold","_vehicles","_vehslot","_wH","_wHPos","_wp","_kIndex","_playerCStats","_playerKarma","_playerKarmaAdj"
];
params ["_trader","_itemsIn","_itemsOut","_player",["_token","",[""]] ];
_playerUID = getplayeruid _player;
@ -54,56 +58,48 @@ if (_slot != -1) then {
_itemClasses = _aiItems select 0;
_itemQtys = _aiItems select 1;
{
_item = _x;
_itemQty = 1;
if (isClass (_config >> _item)) then{
_x params ["_item","_itemQty"];
if (isClass (_config >> _item)) then {
_itemWorth = getNumber(_config >> _item >> "price");
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_itemWorth = round (_itemWorth*(_itemQty/_maxrnd));
_makeTradeIn = false;
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") then{
_vehicles = _trader nearEntities[[_item], 30];
if !(_vehicles isEqualTo[]) then {
_vehicle = _vehicles select 0;
if (!isNull _vehicle) then {
_playerNetID = owner _player;
if (_playerNetID == (owner _vehicle)) then {
_vehSlot = _vehicle getVariable["VEHICLE_SLOT", "ABORT"];
if (!_vehicleSold && _vehSlot != "ABORT") then {
_BaseClass = _vehicle getvariable ["VEHICLE_BaseClass",""];
if !(_BaseClass isequalto "") then {
_item = _BaseClass;
_itemsIn set [_foreachindex,_item];
_itemsIn set [_foreachindex,[_item,_itemQty]];
};
removeFromRemainsCollector[_vehicle];
removeFromRemainsCollector [_vehicle];
deleteVehicle _vehicle;
_vehicleSold = true;
_vehHiveKey = format["%1:%2", (call EPOCH_fn_InstanceID), _vehSlot];
_VAL = [];
["Vehicle", _vehHiveKey, _VAL] call EPOCH_fnc_server_hiveSET;
EPOCH_VehicleSlots pushBack _vehSlot;
missionNamespace setVariable ['EPOCH_VehicleSlotCount', count EPOCH_VehicleSlots, true];
_makeTradeIn = true;
};
};
};
};
} else {
}
else {
_makeTradeIn = true;
};
if (_makeTradeIn) then {
_returnIn pushBack _item;
_returnIn pushBack [_item,_itemQty];
_tradeIn = _tradeIn + _itemWorth;
_current_crypto = _current_crypto + _itemWorth;
_tradeQtyTotal = _tradeQtyTotal + _itemQty;
@ -114,7 +110,7 @@ if (_slot != -1) then {
_itemQtys pushBack _itemQty;
} else {
_currQty = _itemQtys select _qtyIndex;
_itemQtys set[_qtyIndex, (_currQty + _itemQty)];
_itemQtys set [_qtyIndex, (_currQty + _itemQty)];
};
};
// send karma stat to seller
@ -127,80 +123,73 @@ if (_slot != -1) then {
};
};
} forEach _itemsIn;
_response = ["Bank", _playerUID] call EPOCH_fnc_server_hiveGETRANGE;
if ((_response select 0) == 1 && (_response select 1) isEqualType []) then {
_bankData = _response select 1;
if !(_bankData isEqualTo[]) then {
_MaxBankDebit = [_serverSettingsConfig, "MaxBankDebitforTrade", -999999] call EPOCH_fnc_returnConfigEntry;
_bankBalance = _bankData select 0;
if (_bankBalance < _MaxBankDebit) then {
if (_tradeIn > 0) then {
_bankBalance = _bankBalance + _tradeIn;
_return = ["Bank", _playerUID, EPOCH_expiresBank, [_bankBalance]] call EPOCH_fnc_server_hiveSETEX;
_message = _message + "Items sold, but the Money goes to your Bank - to much Bank-Debit";
}
else {
_message = _message + "Purchase not possible - to much Bank-Debit";
};
_current_crypto = _current_cryptoRaw;
_tradeIn = 0;
_itemsIn = [];
_itemsOut = [];
_SkipOut = true;
_response = ["Bank", _playerUID] call EPOCH_fnc_server_hiveGETRANGE;
if ((_response select 0) == 1 && (_response select 1) isEqualType []) then {
_bankData = _response select 1;
if !(_bankData isEqualTo[]) then {
_MaxBankDebit = [_serverSettingsConfig, "MaxBankDebitforTrade", -999999] call EPOCH_fnc_returnConfigEntry;
_bankBalance = _bankData select 0;
if (_bankBalance < _MaxBankDebit) then {
if (_tradeIn > 0) then {
_bankBalance = _bankBalance + _tradeIn;
_return = ["Bank", _playerUID, EPOCH_expiresBank, [_bankBalance]] call EPOCH_fnc_server_hiveSETEX;
_message = _message + "Items sold, but the Money goes to your Bank - to much Bank-Debit";
}
else {
_message = _message + "Purchase not possible - to much Bank-Debit";
};
_current_crypto = _current_cryptoRaw;
_tradeIn = 0;
_itemsIn = [];
_itemsOut = [];
_SkipOut = true;
};
};
};
if (!_SkipOut) then {
{
_item = _x;
_itemQty = 1;
_x params ["_item","_itemQty"];
if (isClass (_config >> _item)) then{
_itemWorth = getNumber(_config >> _item >> "price");
_itemTax = getNumber(_config >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
_itemWorth = ceil (_itemWorth + _tax);
_maxrnd = 1;
if ([_item,"cfgMagazines"] call Epoch_fnc_isAny) then {
_maxrnd = getnumber (configfile >> "cfgMagazines" >> _item >> "count");
};
_itemWorth = round (_itemWorth*(_itemQty/_maxrnd));
_qtyIndex = _itemClasses find _item;
// add items to array
if (_qtyIndex != -1) then {
_currQty = _itemQtys select _qtyIndex;
if (_currQty >= _itemQty) then {
if (_current_crypto >= _itemWorth) then {
if (_item isKindOf "Air" || _item isKindOf "Ship" || _item isKindOf "LandVehicle" || _item isKindOf "Tank") then{
if (!_vehicleBought) then {
if !(EPOCH_VehicleSlots isEqualTo[]) then {
_position = getPosATL _player;
_helipad = nearestObjects[_player, ["Land_HelipadEmpty_F", "Land_HelipadCircle_F"], 100];
_helipads = [];
_smoke = nearestObject[_player, "SmokeShell"];
if (!isNull _smoke) then {
_helipad pushBack _smoke;
};
// water check
if (_item isKindOf "Ship") then {
{
if (surfaceIsWater (getposATL _x)) then {
_helipads pushBack _x;
}
} forEach _helipad;
} else {
}
else {
{
if !(surfaceIsWater (getposATL _x)) then {
_helipads pushBack _x;
}
} forEach _helipad;
};
if !(_helipads isEqualTo[]) then {
_foundSmoke = false;
{
if (_x isKindOf "SmokeShell") then {
@ -208,7 +197,8 @@ if (_slot != -1) then {
if (_objOwner == owner _player) then {
_position = getPosATL _x;
_foundSmoke = true;
} else {
}
else {
{
if (_objOwner == owner _x) exitWith{
_position = getPosATL _x;
@ -222,12 +212,14 @@ if (_slot != -1) then {
if !(_foundSmoke) then {
_position = getPosATL (_helipads select 0);
};
} else {
}
else {
_tmpposition = [];
if (_item isKindOf "Ship") then {
_tmpposition = [_position, 20, 150, 5, 0, 1000, 1] call BIS_fnc_findSafePos;
_tmpposition = [_tmpposition, 0, 60, 10, 2, 1000, 0] call BIS_fnc_findSafePos;
} else {
}
else {
_tmpposition = [_position, 20, 120, 5, 0, 2000, 0] call BIS_fnc_findSafePos;
};
if ((count _tmpposition) == 2) then {
@ -244,29 +236,21 @@ if (_slot != -1) then {
};
};
};
// select available slot
_vehslot = EPOCH_VehicleSlots select 0;
// Remove from available slots
EPOCH_VehicleSlots = EPOCH_VehicleSlots - [_vehslot];
missionNamespace setVariable ['EPOCH_VehicleSlotCount', count EPOCH_VehicleSlots, true];
_vehicleBought = true;
// Group access
_lockOwner = getPlayerUID _player;
_playerGroup = _player getVariable["GROUP", ""];
if (_playerGroup != "") then {
_lockOwner = _playerGroup;
};
_vehObj = [_item,_position,random 360,true,_vehslot,_lockOwner,"NONE",false,false] call EPOCH_spawn_vehicle;
_final_location = getPosATL _vehObj;
_group = group _player;
_wp = _group addWaypoint [_final_location, 0];
deleteWaypoint [_group, 0];
_returnOut pushBack _item;
_returnOut pushBack [_item,_itemQty];
_itemQtys set[_qtyIndex, (_currQty - _itemQty)];
_tradeOut = _tradeOut - _itemWorth;
_current_crypto = _current_crypto - _itemWorth;
@ -277,8 +261,8 @@ if (_slot != -1) then {
[_errorMsg, 5] remoteExec ['Epoch_message',_player];
};
};
} else {
}
else {
if (_item isKindOf "Bag_Base") then {
_wH = objNull;
_nearByHolder = nearestObjects [_player,["groundWeaponHolder"],3];
@ -288,13 +272,14 @@ if (_slot != -1) then {
_wHPos = ASLToATL _wHPos;
};
_wH = createVehicle ["groundWeaponHolder",_wHPos, [], 0, "CAN_COLLIDE"];
} else {
}
else {
_wH = _nearByHolder select 0;
};
_wH addBackpackCargoGlobal [_item,1];
};
_returnOut pushBack _item;
_itemQtys set[_qtyIndex, (_currQty - _itemQty)];
_returnOut pushBack [_item,_itemQty];
_itemQtys set [_qtyIndex, (_currQty - _itemQty)];
_tradeOut = _tradeOut - _itemWorth;
_current_crypto = _current_crypto - _itemWorth;
_tradeQtyTotal = _tradeQtyTotal + _itemQty;
@ -312,8 +297,6 @@ if (_slot != -1) then {
};
} forEach _itemsOut;
};
if !(_itemsIn isEqualTo []) then {
if (_itemsIn isEqualTo _returnIn) then {
_message = _message + "All Items sold";
@ -336,10 +319,7 @@ if (_slot != -1) then {
_message = _message + "Not all Items purchased";
};
};
_tradeTotal = _tradeIn + _tradeOut;
if !(_returnIn isequalto [] && _returnOut isEqualTo []) then {
_trader setVariable["AI_ITEMS", [_itemClasses, _itemQtys], true];
_objHiveKey = format["%1:%2", (call EPOCH_fn_InstanceID), _slot];