Jump to content

Add items to the traders?


Guest

Recommended Posts

#include "missionconfigfile\CfgPricing.hpp" in description.ext

 

OP_NpcTraderAdd.sqf



private ["_uiItem","_item","_worth","_cryptoCount","_control","_selected","_index","_sizeOut","_array"];
_control = _this select 0;
_selected = _this select 1;

_uiItem = (_selected select 0) lbData (_selected select 1);

if (isClass(missionconfigfile >> "CfgPricing" >> _uiItem)) 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);

_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(missionconfigfile >> "CfgPricing" >> _item >> "price");
_cryptoCount = _cryptoCount + _worth;
};
};
ctrlSetText [41004, (format ["%1 Krypto", _cryptoCount])];

_cryptoCount = 0;
_sizeOut = lbSize 41502;
//_array = [];
if (_sizeOut > 0) then {
for "_i" from 0 to (_sizeOut - 1) do {
_item = lbData [41502, _i];
//_array pushBack _item;
_itemWorth = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "price");
_itemTax = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "tax");
_tax = _itemWorth * (EPOCH_taxRate + _itemTax);
_itemWorth = ceil(_itemWorth + _tax);
//diag_log format["_finalWorth %1", _finalWorth];
_cryptoCount = _cryptoCount + _itemWorth;
};
};
ctrlSetText [41005, (format ["%1 Krypto", _cryptoCount])];
};

 

OP_StartNpcsTrade.sqf



private["_item", "_currQty", "_tradeType", "_itemWorth", "_aiItems", "_itemClasses", "_itemQtys", "_qtyIndex", "_tradeTotal", "_tradeQtyTotal", "_errorMsg", "_target", "_sizeOut", "_array", "_makeTrade", "_vehSlot", "_vehicle", "_vehicles", "_display", "_addWeaponToHands", "_type", "_tax"];

if (!isNil "EPOCH_TRADE_COMPLETE") exitWith {};
if (!isNil "EPOCH_TRADE_STARTED") exitWith{};

if (!isNull _this) then{

EPOCH_TRADE_STARTED = true;

_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(missionconfigfile >> "CfgPricing" >> _item)) then{


// test remove items to be sold and add to array
if ([_item, "CfgWeapons"] call EPOCH_isAny) then{
if (_item in items player) then{
player removeItem _item;
_arrayIn pushBack _item;
};
} else {
if ([_item, "CfgVehicles"] call EPOCH_isAny) then{
_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
};
};
};
};
} else {
if (_item in magazines player) then{
player removeMagazine _item;
_arrayIn pushBack _item;
};
};
};
// 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(missionconfigfile >> "CfgPricing" >> _item)) then{
_itemWorth = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "price");
_itemTax = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "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{

// make trade
EPOCH_MAKENPCTRADE = [_this, _arrayIn, _arrayOut, player, Epoch_personalToken];
publicVariableServer "EPOCH_MAKENPCTRADE";

// close menu
closeDialog 0;

[_arrayIn, _arrayOut] spawn{

waitUntil{ sleep 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{
_errorMsg = 'Items Sold';
0 = [format["%1", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;

}
else {
_errorMsg = 'Failed To Sell Items';
0 = [format["%1", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;
};
};

// PURCHASED ITEMS ARRAY
if !((EPOCH_TRADE_COMPLETE select 1) isEqualTo[]) then{
if ((EPOCH_TRADE_COMPLETE select 1) isEqualTo(_this select 1)) then{

_errorMsg = 'Items Purchased';

// add purchased items
{
if ([_x, "CfgWeapons"] call EPOCH_isAny) then{
if (player canAdd _x) then{
player addItem _x;
}
else {
_type = getNumber(configfile >> "CfgWeapons" >> (_x) >> "type");
_addWeaponToHands = false;
switch (_type) do {
case 1: {
if (primaryWeapon player == "") then{
_addWeaponToHands = true;
};
};
case 2: {
if (secondaryWeapon player == "") then{
_addWeaponToHands = true;
};
};
case 4: {
if (handgunWeapon player == "") then{
_addWeaponToHands = true;
};
};
};
if (_addWeaponToHands) then{
player addWeapon _x;
}
else {
_errorMsg = "Not enough space";
};
};

}
else {
if ([_x, "CfgMagazines"] call EPOCH_isAny) then{
if (player canAdd _x) then{
player addMagazine _x;
}
else {
_errorMsg = "Not enough space";
};
};
};
} forEach(_this select 1);


0 = [format["%1", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;
}
else {
_errorMsg = 'Failed To Purchase Items';
0 = [format["%1", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;
};
};

EPOCH_TRADE_COMPLETE = nil;
EPOCH_TRADE_STARTED = nil;
};
};
};

 
 

precompile.sqf




diag_log 'EMOD: Precompile Running';
EPOCH_npcTraderAdd = compileFinal preprocessFileLineNumbers "custom\a3_epoch_code\compile\traders\OP_npcTraderAdd.sqf";
EPOCH_startNpcTrade = compileFinal preprocessFileLineNumbers "custom\a3_epoch_code\compile\traders\OP_startNpcTrade.sqf";
call compile preprocessFileLineNumbers "custom\a3_epoch_code\init\fn_init.sqf";
diag_log 'EMOD: Precompile Finished';

 
 
so wats missing? ;p
 
 
Link to comment
Share on other sites

in description.ext                #include "missionconfigfile\CfgPricing.hpp" in description.ext

 

download emod and follow instructions

 

and put your CfgPricing in wat ever folder u named it         "missionconfigfile\CfgPricing.hpp"                 missionconfigfile is mine

Link to comment
Share on other sites

 

#include "missionconfigfile\CfgPricing.hpp" in description.ext

 

OP_NpcTraderAdd.sqf

private ["_uiItem","_item","_worth","_cryptoCount","_control","_selected","_index","_sizeOut","_array"];

_control = _this select 0;

_selected = _this select 1;

_uiItem = (_selected select 0) lbData (_selected select 1);

if (isClass(missionconfigfile >> "CfgPricing" >> _uiItem)) 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);

_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(missionconfigfile >> "CfgPricing" >> _item >> "price");

_cryptoCount = _cryptoCount + _worth;

};

};

ctrlSetText [41004, (format ["%1 Krypto", _cryptoCount])];

_cryptoCount = 0;

_sizeOut = lbSize 41502;

//_array = [];

if (_sizeOut > 0) then {

for "_i" from 0 to (_sizeOut - 1) do {

_item = lbData [41502, _i];

//_array pushBack _item;

_itemWorth = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "price");

_itemTax = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "tax");

_tax = _itemWorth * (EPOCH_taxRate + _itemTax);

_itemWorth = ceil(_itemWorth + _tax);

//diag_log format["_finalWorth %1", _finalWorth];

_cryptoCount = _cryptoCount + _itemWorth;

};

};

ctrlSetText [41005, (format ["%1 Krypto", _cryptoCount])];

};

 

OP_StartNpcsTrade.sqf

private["_item", "_currQty", "_tradeType", "_itemWorth", "_aiItems", "_itemClasses", "_itemQtys", "_qtyIndex", "_tradeTotal", "_tradeQtyTotal", "_errorMsg", "_target", "_sizeOut", "_array", "_makeTrade", "_vehSlot", "_vehicle", "_vehicles", "_display", "_addWeaponToHands", "_type", "_tax"];

if (!isNil "EPOCH_TRADE_COMPLETE") exitWith {};

if (!isNil "EPOCH_TRADE_STARTED") exitWith{};

if (!isNull _this) then{

EPOCH_TRADE_STARTED = true;

_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(missionconfigfile >> "CfgPricing" >> _item)) then{

// test remove items to be sold and add to array

if ([_item, "CfgWeapons"] call EPOCH_isAny) then{

if (_item in items player) then{

player removeItem _item;

_arrayIn pushBack _item;

};

} else {

if ([_item, "CfgVehicles"] call EPOCH_isAny) then{

_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

};

};

};

};

} else {

if (_item in magazines player) then{

player removeMagazine _item;

_arrayIn pushBack _item;

};

};

};

// 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(missionconfigfile >> "CfgPricing" >> _item)) then{

_itemWorth = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "price");

_itemTax = getNumber(missionconfigfile >> "CfgPricing" >> _item >> "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{

// make trade

EPOCH_MAKENPCTRADE = [_this, _arrayIn, _arrayOut, player, Epoch_personalToken];

publicVariableServer "EPOCH_MAKENPCTRADE";

// close menu

closeDialog 0;

[_arrayIn, _arrayOut] spawn{

waitUntil{ sleep 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{

_errorMsg = 'Items Sold';

0 = [format["%1", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;

}

else {

_errorMsg = 'Failed To Sell Items';

0 = [format["%1", _errorMsg], 0, 1, 5, 2, 0, 1] spawn bis_fnc_dynamictext;

};

};

// PURCHASED ITEMS ARRAY

if !((EPOCH_TRADE_COMPLETE select 1) isEqualTo[]) then{

if ((EPOCH_TRADE_COMPLETE select 1) isEqualTo(_this select 1)) then{

_errorMsg = 'Items Purchased';

// add purchased items

{

if ([_x, "CfgWeapons"] call EPOCH_isAny) then{

if (player canAdd _x) then{

player addItem _x;

}

else {

_type = getNumber(configfile >> "CfgWeapons" >> (_x) >> "type");

_addWeaponToHands = false;

switch (_type) do {

case 1: {

if (primaryWeapon player == "") then{

_addWeaponToHands = true;

};

};

case 2: {

if (secondaryWeapon player == "") then{

_addWeaponToHands = true;

};

};

case 4: {

if (handgunWeapon player == "") then{

_addWeaponToHands = true;

};

};

};

if (_addWeaponToHands) then{

player addWeapon _x;

}

else {

_errorMsg = "Not enough space";

};

};

}

else {

if ([_x, "CfgMagazines"] call EPOCH_isAny) then{

if (player canAdd _x) then{

player addMagazine _x;

}

else {

_errorMsg = "Not enough space";

};

};

};

} forEach(_this select 1);

0 = [format["%1", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;

}

else {

_errorMsg = 'Failed To Purchase Items';

0 = [format["%1", _errorMsg], 0, 0.4, 5, 2, 0, 2] spawn bis_fnc_dynamictext;

};

};

EPOCH_TRADE_COMPLETE = nil;

EPOCH_TRADE_STARTED = nil;

};

};

};

 
 

precompile.sqf

diag_log 'EMOD: Precompile Running';

EPOCH_npcTraderAdd = compileFinal preprocessFileLineNumbers "custom\a3_epoch_code\compile\traders\OP_npcTraderAdd.sqf";

EPOCH_startNpcTrade = compileFinal preprocessFileLineNumbers "custom\a3_epoch_code\compile\traders\OP_startNpcTrade.sqf";

call compile preprocessFileLineNumbers "custom\a3_epoch_code\init\fn_init.sqf";

diag_log 'EMOD: Precompile Finished';

 
 
so wats missing? ;p
 
 

 

Server side make npc trade, thats whats missing

Link to comment
Share on other sites

server did not boot wen i changed it to that :/

 

i changed all the configFile >> "CfgPricing to missionconfigfile >> "CfgPricing in Epoch_server_MakeNpcTrade

 

that correct?

 

also would i have to do it with the CfgVehicles too..is that possibly why server did not load?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×
×
  • Create New...