Epoch/Sources/epoch_code/compile/traders/EPOCH_startNpcTrade.sqf

132 lines
4.1 KiB
Plaintext
Raw Normal View History

2015-12-14 18:09:09 +00:00
/*
2018-01-13 14:12:54 +00:00
Author: He-Man - Ignatz-Gaming
2015-12-14 18:09:09 +00:00
2018-01-13 14:12:54 +00:00
Contributors: Raimonds Virtoss
2015-12-14 18:09:09 +00:00
Description:
2018-01-13 14:12:54 +00:00
Move Items in Tradermenu from TraderOut window to Traderinventory
2015-12-14 18:09:09 +00:00
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
2018-01-13 14:12:54 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/traders/EPOCH_startNpcTrade.sqf
2015-12-14 18:09:09 +00:00
*/
2018-01-13 14:12:54 +00:00
private ["_PlayerItemsOutBox","_TraderItemsOutBox","_config","_current_crypto","_sizeIn","_arrayIn","_item","_rounds","_mags","_itemMags","_index","_sizeOut","_arrayOut","_itemWorth","_itemTax","_tax","_maxrnd"];
2015-09-14 20:55:36 +00:00
if (!isNil "EPOCH_TRADE_STARTED") exitWith{};
2016-01-08 22:27:07 +00:00
if (isNull _this) exitWith{};
2015-09-14 20:55:36 +00:00
2016-01-08 04:32:52 +00:00
if (alive _this) then {
2018-01-13 14:12:54 +00:00
_PlayerItemsOutBox = 41501;
_TraderItemsOutBox = 41502;
2015-09-14 20:55:36 +00:00
_config = 'CfgPricing' call EPOCH_returnConfig;
_current_crypto = EPOCH_playerCrypto;
2018-01-13 14:12:54 +00:00
_sizeIn = lbSize _PlayerItemsOutBox;
2015-09-14 20:55:36 +00:00
_arrayIn = [];
2018-01-13 14:12:54 +00:00
if (_sizeIn > 0) then {
for "_i" from 0 to (_sizeIn - 1) do {
_item = lbData [_PlayerItemsOutBox, _i];
_rounds = lbValue [_PlayerItemsOutBox, _i];
2015-09-14 20:55:36 +00:00
if (isClass (_config >> _item)) then{
2018-01-13 14:12:54 +00:00
_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;
2015-09-14 20:55:36 +00:00
if ([_item, "CfgWeapons"] call EPOCH_fnc_isAny) then {
if (_item in items player) then {
player removeItem _item;
2018-01-13 14:12:54 +00:00
_arrayIn pushBack [_item,_rounds];
_added = true;
}
else {
2015-12-14 18:09:09 +00:00
if (_item == primaryweapon player) then {
player removeweapon _item;
2018-01-13 14:12:54 +00:00
_arrayIn pushBack [_item,_rounds];
_added = true;
2015-12-17 17:24:11 +00:00
};
2015-09-14 20:55:36 +00:00
};
2018-01-13 14:12:54 +00:00
}
else {
2015-09-14 20:55:36 +00:00
if ([_item, "CfgVehicles"] call EPOCH_fnc_isAny) then {
2015-12-14 18:09:09 +00:00
if (_item == backpack player) then {
removeBackpack player;
2018-01-13 14:12:54 +00:00
_arrayIn pushBack [_item,_rounds];
_added = true;
}
else {
2015-12-17 17:24:11 +00:00
_vehicles = _this nearEntities[[_item], 30];
if (!(_vehicles isEqualTo[])) then {
_vehicle = _vehicles select 0;
if (!isNull _vehicle) then {
if (local _vehicle) then {
_vehSlot = _vehicle getVariable["VEHICLE_SLOT", "ABORT"];
if (_vehSlot != "ABORT") then {
2018-01-13 14:12:54 +00:00
_arrayIn pushBack [_item,_rounds];
_added = true;
2015-12-17 17:24:11 +00:00
};
2015-09-14 20:55:36 +00:00
};
};
};
};
2018-01-13 14:12:54 +00:00
}
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;
{
2018-01-15 17:48:36 +00:00
_x call EPOCH_fnc_addMagazineOverflow;
2018-01-13 14:12:54 +00:00
} foreach _itemMags;
2015-09-14 20:55:36 +00:00
};
};
};
2018-01-13 14:12:54 +00:00
if (_added) then {
_current_crypto = _current_crypto + _itemWorth;
};
2015-09-14 20:55:36 +00:00
};
};
};
2018-01-13 14:12:54 +00:00
_sizeOut = lbSize _TraderItemsOutBox;
2015-09-14 20:55:36 +00:00
_arrayOut = [];
if (_sizeOut > 0) then {
2018-01-13 14:12:54 +00:00
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");
2015-09-14 20:55:36 +00:00
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
2018-01-13 14:12:54 +00:00
_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));
2015-09-14 20:55:36 +00:00
if (_current_crypto >= _itemWorth) then {
_current_crypto = _current_crypto - _itemWorth;
2018-01-13 14:12:54 +00:00
_arrayOut pushBack [_item,_rounds];
2015-09-14 20:55:36 +00:00
};
};
};
};
2018-01-13 14:12:54 +00:00
if !(_arrayIn isEqualTo[] && _arrayOut isEqualTo[]) then {
2015-12-14 18:09:09 +00:00
EPOCH_TRADE_STARTED = true;
2015-12-23 17:38:11 +00:00
[_this, _arrayIn, _arrayOut, player, Epoch_personalToken] remoteExec ["EPOCH_server_makeNPCTrade",2];
2015-09-14 20:55:36 +00:00
closeDialog 0;
};
2015-10-28 15:16:00 +00:00
};