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

191 lines
5.0 KiB
Plaintext
Raw Normal View History

2015-12-14 18:09:09 +00:00
/*
Author: Aaron Clark - EpochMod.com
Contributors: He-Man
Description:
NPC trade code
Licence:
Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike
Github:
2016-06-13 16:54:19 +00:00
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/traders/EPOCH_startNpcTrade.sqf
2015-12-14 18:09:09 +00:00
Example:
cursorTarget call EPOCH_startNpcTrade;
Parameter(s):
_this: OBJECT
Returns:
NOTHING
*/
Release 0.3.8 (#502) * first build for 0.3.8 * 0.3.8.0190 * 0.3.8.0202 * 0.3.8.0213 * 0.3.7.0214 * 0.3.8.0222 * 0.3.8.0246 * 0.3.8.0247 fixed typo * 0.3.8.0249 more fixes for server compiler * 0.3.8.0256 * add build number and simple batch file for packing * match build number with internal * add build numbers to server pbo's and mission files also reworked build script for more options * 0.3.8.0261 * 0.3.8.0261 * 0.3.8.0283 * 0.3.8.0284 * changelog * 0.3.8.0307 * 0.3.8.0311 * remove old BEC plugin * update redis-server.exe to latest build and full config * 0.3.8.0314 * 0.3.8.0315 * inverse logic This should correctly prevent spawning these units nearby jammer or protection zones * use pushbackUnique here * optimized loot function by using selectRandom instead of slower sqf logic * 0.3.8.0316 * make use of new getDir functionality instead of BIS fnc * add lower disconnect value to server.cfg * use new getpos functionality * 0.3.8.0317 * 0.3.8.0319 * 0.3.8.0327 * 0.3.8.0338 changelog update tba * changelog * 0.3.8.0341 * BE update * 0.3.8.0353 * changelog * removed duplicates * 0.3.8.0355 fixed error in getIDC * 0.3.8.0356 revert to BIS_fnc_param as params threw errors * 0.3.8.0357 fixes for #496 #497 * 0.3.8.0359 fixed #497 fixed #496 * 0.3.8.0365 * 0.3.8.0371 * 0.3.8.0373 * 0.3.8.0379 * 0.3.8.0381 * 0.3.8.0386 * 0.3.8.0393 * 0.3.8.0395 * 0.3.8.0396 * 0.3.8.0397 * 0.3.8.0406 * 0.3.8.0409 * 0.3.8.0410 loot balance suppress error in spawnloot make near object check based on building size * 0.3.8.0412 * 0.3.8.0414 removed classes with scope 0 test remove loot trash on gear for #498 fixed #501 * 0.3.8.0415 * same
2016-04-08 20:21:46 +00:00
private ["_vehSlot","_vehicle","_vehicles","_item","_current_crypto","_itemWorth","_itemTax","_tax","_config","_sizeOut","_arrayIn","_arrayOut"];
2015-09-14 20:55:36 +00:00
if (!isNil "EPOCH_TRADE_COMPLETE") exitWith {};
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 {
2015-09-14 20:55:36 +00:00
_config = 'CfgPricing' call EPOCH_returnConfig;
_current_crypto = EPOCH_playerCrypto;
// _arrayIn = Sell Array
_sizeOut = lbSize 41501;
_arrayIn = [];
if (_sizeOut > 0) then {
for "_i" from 0 to(_sizeOut - 1) do {
_item = lbData[41501, _i];
if (isClass (_config >> _item)) then{
2015-10-28 15:16:00 +00:00
// test remove items to be sold and add to array
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;
_arrayIn pushBack _item;
2015-12-17 17:24:11 +00:00
} else {
2015-12-14 18:09:09 +00:00
if (_item == primaryweapon player) then {
player removeweapon _item;
_arrayIn pushBack _item;
2015-12-17 17:24:11 +00:00
};
2015-09-14 20:55:36 +00:00
};
2015-12-17 17:24:11 +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;
_arrayIn pushBack _item;
2015-12-17 17:24:11 +00:00
} else {
_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 {
_arrayIn pushBack _item;
// will be removed server side
};
2015-09-14 20:55:36 +00:00
};
};
};
};
2015-12-17 17:24:11 +00:00
} else {
2015-09-14 20:55:36 +00:00
if (_item in magazines player) then {
player removeMagazine _item;
_arrayIn pushBack _item;
};
};
};
2015-10-28 15:16:00 +00:00
// test
2015-09-14 20:55:36 +00:00
};
};
};
// _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 (!(_arrayIn isEqualTo[]) || !(_arrayOut isEqualTo[])) then {
2015-12-14 18:09:09 +00:00
EPOCH_TRADE_STARTED = true;
2015-09-14 20:55:36 +00:00
// make trade
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
// close menu
closeDialog 0;
[_arrayIn, _arrayOut] spawn{
waitUntil{ uiSleep 0.1; !isNil "EPOCH_TRADE_COMPLETE" };
// SOLD ITEMS ARRAY
if !((EPOCH_TRADE_COMPLETE select 0) isEqualTo[]) then {
if ((EPOCH_TRADE_COMPLETE select 0) isEqualTo(_this select 0)) then {
2016-06-18 01:22:29 +00:00
['Items Sold', 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
}
else {
2016-06-18 01:22:29 +00:00
['Failed To Sell Items', 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
// PURCHASED ITEMS ARRAY
if !((EPOCH_TRADE_COMPLETE select 1) isEqualTo[]) then {
if ((EPOCH_TRADE_COMPLETE select 1) isEqualTo(_this select 1)) then {
2015-10-28 15:16:00 +00:00
_errorMsg = 'Items Purchased: ';
2015-09-14 20:55:36 +00:00
// add purchased items
{
if ([_x, "CfgWeapons"] call EPOCH_fnc_isAny) then {
2015-10-28 15:16:00 +00:00
_errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgWeapons" >> (_x) >> "displayName")];
_type = getNumber(configfile >> "CfgWeapons" >> (_x) >> "type");
_addWeaponToHands = false;
switch (_type) do {
2015-09-14 20:55:36 +00:00
case 1: {
if (primaryWeapon player == "") then {
_addWeaponToHands = true;
};
};
case 2: {
if (secondaryWeapon player == "") then {
_addWeaponToHands = true;
};
};
case 4: {
if (handgunWeapon player == "") then {
_addWeaponToHands = true;
};
};
};
2015-10-28 15:16:00 +00:00
if (_addWeaponToHands) then {
player addWeapon _x;
2015-12-14 18:09:09 +00:00
}
else {
2015-10-28 15:16:00 +00:00
_x call EPOCH_fnc_addItemOverflow;
};
2015-12-16 21:19:14 +00:00
} else {
2015-12-17 17:24:11 +00:00
if ([_x, "CfgMagazines"] call EPOCH_fnc_isAny) then {
_errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgMagazines" >> (_x) >> "displayName")];
_x call EPOCH_fnc_addItemOverflow;
2015-12-16 21:19:14 +00:00
} else {
2015-12-17 17:24:11 +00:00
_errorMsg = _errorMsg + format["%1, ", getText(configfile >> "CfgVehicles" >> (_x) >> "displayName")];
2015-09-14 20:55:36 +00:00
};
};
} forEach(_this select 1);
2016-06-18 01:22:29 +00:00
[_errorMsg, 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
}
else {
2016-06-18 01:22:29 +00:00
['Failed To Purchase Items', 5] call Epoch_message;
2015-09-14 20:55:36 +00:00
};
};
EPOCH_TRADE_COMPLETE = nil;
EPOCH_TRADE_STARTED = nil;
};
};
2015-10-28 15:16:00 +00:00
};