Jump to content

[FIX] Better trade_ files (proper logging, etc)


Recommended Posts

I was browsing through the files that SC provided us and I noticed that most of the trade_* files lack some features and have some bugs in them. For me the most annoying thing was logging which made it rather difficult to keep track of who's buying what. So I took the time to review all of the trade_ files and fixed what needed fixing. 

 

Currently these files only work with Soul's DLL. 

 

 

 

What did I change?

  • trade_any_bicycle.sqf - logging fixed
  • trade_any_boat.sqf - logging fixed
  • trade_any_vehicle.sqf - logging fixed
  • trade_backpacks.sqf - logging fixed, added a check if player already has a backpack when buying a new one
  • trade_items.sqf - logging added (didn't have any logging at all)
  • trade_weapons.sqf - logging fixed, added a check that prevents buying 2 primaries in a single slot

So instead of these logs:

18:44:11 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a Coins in/at trader city Branibor for 1x Coins" 

You now get something much more readable like:

18:44:11 "EPOCH SERVERTRADE: Player: ROCU[] (xx) bought a FoodmuttonCooked in/at trader city Branibor for 120x Coins"
18:45:12 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a FoodmuttonCooked in/at Unknown Trader for 60x Coins"
18:52:33 "EPOCH SERVERTRADE: Player: ROCU[] (xx) bought a DZ_GunBag_EP1 in/at trader city Sabina for 6000x Coins"
19:28:16 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a ItemVault in/at trader city Bilgrad for 100000x Coins"

On top of that I tidied the code up a bit where possible. I removed the systemChat messages because they were unnecessary and full of grammar errors. Also logs now display "Unknown trader" instead of "Any" if you aren't in a trader zone.

 

 

 

Download

 

Download available here! [GitHub]

 

Mirror link available here! [upload.ee]

 

 

Edit// Due to popular demand I also made a second version of these files without the trading animation in it. They're in my GitHub (link above) in the folder gold (No Animation). If you don't want to use the "No Animation" files then just ignore/delete that folder.

 

 

Copy & replace these files into your \gold\ folder inside your mission's PBO. Remember to back up the old files just in case.

 

If you want a step-by-step guide instead of copy & replace, check here:

(Note! It is recommended that you use my files instead of doing it step-by-step. Step-by-step only includes the more critical fixes and not much else.)

 

 

Open: 
    trade_any_bicycle.sqf
    trade_any_boat.sqf
    trade_any_vehicle.sqf
    trade_weapons.sqf

 

Find:

if (isNil "inTraderCity") then { inTraderCity = "Unknown Trader City" };
PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_obj,inTraderCity];

Replace it with:

if (isNil "inTraderCity") then {
	inTraderCity = "Unknown Trader"; 
} else {
	if (inTraderCity == "Any") then {
		inTraderCity = "Unknown Trader"; 
	};
};

if (_bos == 1) then {
	// Selling
	PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_in,inTraderCity,CurrencyName,_qty_out];
} else {
	// Buying
	PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_out,inTraderCity,CurrencyName,_qty_in];
};

Open trade_backpacks.sqf

 

Find:

_bos = 0;

Below it, add:

_abort = false;
_msg = "";

Find:

if(_buy_o_sell == "buy") then {
	//_qty = {_x == _part_in} count magazines player;
	_qty = player getVariable ["cashMoney",0]; // get your money variable	
} else {

Replace it with:

if(_buy_o_sell == "buy") then {
	//_qty = {_x == _part_in} count magazines player;
	_qty = player getVariable ["cashMoney",0]; // get your money variable	
	_bag = unitBackpack player;
	_class = typeOf _bag;
	if(!isNil "_class") then {
		if(_class != "") then {
			_abort = true;
			_msg = "Drop or sell your current backpack before you can buy a new one.";
		};
	};
} else {

Find:

if (_qty >= _qty_in) then {

	cutText [(localize "str_epoch_player_105"), "PLAIN DOWN"]; 

Above it, add:

if (_abort) exitWith {
	cutText [_msg, "PLAIN DOWN"];
	DZE_ActionInProgress = false;
}; 

Find:

if (isNil "inTraderCity") then { inTraderCity = "Unknown Trader City" };
PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_bag,inTraderCity]; 

Replace it with:

if (isNil "inTraderCity") then {
	inTraderCity = "Unknown Trader"; 
} else {
	if (inTraderCity == "Any") then {
		inTraderCity = "Unknown Trader"; 
	};
};

if (_bos == 1) then {
	// Selling
	PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_in,inTraderCity,CurrencyName,_qty_out];
} else {
	// Buying
	PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_part_out,inTraderCity,CurrencyName,_qty_in];
};

Open trade_items.sqf

 

Find:

cutText [format["Traded %1 %2 for %3",_price,CurrencyName,_textPart], "PLAIN DOWN"];

Below it, add:

// Logging
if (isNil "_name") then { _name = "Unknown Item"; };
if (isNil "inTraderCity") then {
	inTraderCity = "Unknown Trader"; 
} else {
	if (inTraderCity == "Any") then {
		inTraderCity = "Unknown Trader"; 
	};
};

PVDZE_obj_Trade = [_activatingPlayer,_traderID,0,_name,inTraderCity,CurrencyName,_price];
publicVariableServer "PVDZE_obj_Trade";

Find:

cutText [format[("Traded %1 for %2 %3"),_textPart,_price,CurrencyName], "PLAIN DOWN"];

Below it, add:

// Logging
if (isNil "_name") then { _name = "Unknown Item"; };
if (isNil "inTraderCity") then {
	inTraderCity = "Unknown Trader City"; 
} else {
	if (inTraderCity == "Any") then {
		inTraderCity = "Unknown Trader"; 
	};
};

PVDZE_obj_Trade = [_activatingPlayer,_traderID,1,_name,inTraderCity,CurrencyName,_price];
publicVariableServer "PVDZE_obj_Trade";
Open trade_weapons.sqf
 
Find:
_bos = 0; 

Below it, add:

_abort = false;
_msg = ""; 

Find:

if(_buy_o_sell == "buy") then {
	//_qty = {_x == _part_in} count magazines player;
	_qty = player getVariable ["cashMoney",0]; // get your money variable	
} else {
	_qty = {_x == _part_in} count weapons player;
	_bos = 1;
}; 

Replace it with:

if(_buy_o_sell == "buy") then {
	//_qty = {_x == _part_in} count magazines player;
	_qty = player getVariable ["cashMoney",0]; // Single Currency
	
	// buying item type must NOT exist if rifle or pistol
	_msg = "Drop or sell your current weapon before you can buy a new one.";
	_config = (configFile >> "CfgWeapons" >> _part_out);
	_configName = configName(_config);
	_wepType = getNumber(_config >> "Type");

	_isPistol = (_wepType == 2);
	_isRifle = (_wepType == 1);
	_isToolBelt = (_wepType == 131072);
	_isBinocs = (_wepType == 4096);

	if (_isRifle) then {
		_abort = ((primaryWeapon player) != "");
	};
	if (_isPistol) then {
		_secondaryWeapon = "";
		{
			if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Type")) == 2) exitWith {
					_secondaryWeapon = _x;
			};
		} count (weapons player);
		_abort = (_secondaryWeapon != "");
	};
	if(_isToolBelt || _isBinocs) then {
		_abort = (_configName in (weapons player));
		_msg = "Drop or sell your current toolbelt item before you can buy a new one.";
	};
} else {
	_qty = {_x == _part_in} count weapons player;
	_bos = 1;
	
	_msg = "Need the weapon in your hands before you can sell it.";
	_config = (configFile >> "CfgWeapons" >> _part_in);
	_configName = configName(_config);
	_wepType = getNumber(_config >> "Type");

	_isToolBelt = (_wepType == 131072);
	_isBinocs = (_wepType == 4096);

	_abort = (!(_configName in (weapons player)));

	if(_isToolBelt || _isBinocs) then {
		_msg = "Need the item on your toolbelt before you can sell it.";
	};
};

if (_abort) exitWith {
	cutText [_msg, "PLAIN DOWN"];
	DZE_ActionInProgress = false;
}; 

 

 

 

Be aware

 

Even tho I tested these files pretty thoroughly I can't guarantee that they work perfectly on your server. It all depends which mods you have installed and how heavily modified your files are. Speaking of which, if you have modified your trade_ files before for a different mod, I suggest applying the mod changes to my fixed files not the other way around. And remember: backup.

Edited by Rocu
Link to comment
Share on other sites

 

You mean search for this 

PVDZE_obj_Trade = [_activatingPlayer,_traderID,_bos,_obj,inTraderCity,CurrencyName,_qty_in];

Because zupa 1.1 had config option for currencyName

 

You're right. Edited first post. I'll be updating all the files to the correct state anyway.

Link to comment
Share on other sites

Any chance you could give set by step changes instead of replacing files ?

 

Updated first post. Tho I must say it's still recommended to use my files to copy & replace instead. I only listed the most critical fixes in the step-by-step guide. But it's your choice.

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

Hey dude, great fixes been using this for some time.

Just wondered what the trade_items_wo_db.sqf acutally does.

It seems very similar to trade_items just no DB calls.

I cant see this being called anywhere. Any ideas ? I must have missed something, Its late B)

 

Taaa

Link to comment
Share on other sites

Hey dude, great fixes been using this for some time.

Just wondered what the trade_items_wo_db.sqf acutally does.

It seems very similar to trade_items just no DB calls.

I cant see this being called anywhere. Any ideas ? I must have missed something, Its late B)

 

Taaa

 

Glad to have helped. Well, it is what the file says it is :P trade_items_wo_db = trade items without database.

Actually if I'm not mistaken it's the file that handles all those "off the shelves" deals. Deals that don't require database (that's where the name comes in) and are only done client-side. Like trading zombie meat for bio meat, trading tin cans for scrap metal, etc.

Link to comment
Share on other sites

thanks for the update Ruco!

 

tested and it works great ... i removed the animation for the (sell) trade items aswell

 

trade_items.sqf

 

private ["_qty","_buy_o_sell","_playerCash","_needed","_abort","_removed","_tradeCounter","_traderID","_total_trades","_activatingPlayer","_finish_trade","_name","_textPart","_price","_emptySlots","_free_magazine_slots"];



if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_103") , "PLAIN DOWN"] }; // Trade already in progress
DZE_ActionInProgress = true;

_buy_o_sell = (_this select 3) select 4;
_activatingPlayer = player;


if(_buy_o_sell == "buy") then {
// BUYING
_finish_trade = {
{player removeAction _x} forEach s_player_parts;s_player_parts = [];
s_player_parts_crtl = -1;
DZE_ActionInProgress = false;
dayzTradeResult = nil;
};

_name = (_this select 3) select 0;
_textPart = (_this select 3) select 6;
_price = (_this select 3) select 3;
_traderID = (_this select 3) select 7;

_emptySlots = [player] call BIS_fnc_invSlotsEmpty;
_free_magazine_slots = _emptySlots select 4;

_tradeCounter = 0;

if(_free_magazine_slots < 1) exitWith {
cutText [(localize "STR_DAYZ_CODE_2"), "PLAIN DOWN"]; // You do not have enough room in your inventory
DZE_ActionInProgress = false;
};

_playerCash = player getVariable ["cashMoney",0];
_total_trades = floor(_playerCash / _price);
if (_total_trades < 1) exitWith {
_needed = _price - _playerCash;
cutText [format[(localize "str_epoch_player_184"),_needed,CurrencyName] , "PLAIN DOWN"];
call _finish_trade;
};
if (_total_trades > _free_magazine_slots) then {
_total_trades = _free_magazine_slots;
};

_abort = false;

// perform number of total trades
for "_x" from 1 to _total_trades do {
_tradeCounter = _tradeCounter + 1;

// cutText ["Starting trade, stand still to complete.", "PLAIN DOWN"];
if(_total_trades == 1) then {
cutText [(localize "STR_EPOCH_PLAYER_105"), "PLAIN DOWN"]; // Starting trade, stand still to complete trade.
} else {
cutText [format[(localize "STR_EPOCH_PLAYER_187"),_tradeCounter,_total_trades], "PLAIN DOWN"]; // Starting trade, stand still to complete trade %1 of %2.
};

private["_finished","_oldPosition"];
if(isNil "_oldPosition") then { _oldPosition = position player;};
_finished = false;
sleep 2;
if (player distance _oldPosition <= 1) then {
_finished = true;
};
if (!_finished) exitWith {
DZE_ActionInProgress = false;
r_autoTrade = false;
cutText [(localize "str_epoch_player_106") , "PLAIN DOWN"];
};

if (_finished) then {
if (_playerCash >= _price) then {
_playerCash = player getVariable ["cashMoney",0];
player setVariable["cashMoney",(_playerCash - _price),true];
player addMagazine _name;
_abort = false;
cutText [format["Traded %1 %2 for %3",_price,CurrencyName,_textPart], "PLAIN DOWN"];
PVDZE_plr_Save = [player,(magazines player),true,true] ;
publicVariableServer "PVDZE_plr_Save";

// Logging
if (isNil "_name") then { _name = "Unknown Item"; };
if (isNil "inTraderCity") then {
inTraderCity = "Unknown Trader";
} else {
if (inTraderCity == "Any") then {
inTraderCity = "Unknown Trader";
};
};

PVDZE_obj_Trade = [_activatingPlayer,_traderID,0,_name,inTraderCity,CurrencyName,_price];
publicVariableServer "PVDZE_obj_Trade";
} else {
_needed = _price - _playerCash;
cutText [format[(localize "str_epoch_player_184"),_needed,CurrencyName] , "PLAIN DOWN"];
_abort = true;
};
};
sleep 1;

if(_abort) exitWith {};
};
DZE_ActionInProgress = false;

} else {
// SELLING
_finish_trade = {
{player removeAction _x} forEach s_player_parts;s_player_parts = [];
s_player_parts_crtl = -1;
DZE_ActionInProgress = false;
dayzTradeResult = nil;
};

_name = (_this select 3) select 1;
_textPart = (_this select 3) select 5;
_price = (_this select 3) select 2;
_traderID = (_this select 3) select 7;

_qty = {_x == _name} count magazines player;

_removed = 0;
_tradeCounter = 0;

_total_trades = _qty;
if (_total_trades < 1) exitWith {
cutText [format["You do not have a %1", _textPart], "PLAIN DOWN"];
call _finish_trade;
};



_abort = false;

// perform number of total trades
for "_x" from 1 to _total_trades do {
_tradeCounter = _tradeCounter + 1;

// cutText ["Starting trade, stand still to complete.", "PLAIN DOWN"];
if(_total_trades == 1) then {
cutText [(localize "STR_EPOCH_PLAYER_105"), "PLAIN DOWN"]; // Starting trade, stand still to complete trade.
} else {
cutText [format[(localize "STR_EPOCH_PLAYER_187"),_tradeCounter,_total_trades], "PLAIN DOWN"]; // Starting trade, stand still to complete trade %1 of %2.
};

private["_finished","_oldPosition"];
if(isNil "_oldPosition") then { _oldPosition = position player;};
_finished = false;
sleep 2;
if (player distance _oldPosition <= 1) then {
_finished = true;
};
if (!_finished) exitWith {
DZE_ActionInProgress = false;
r_autoTrade = false;
cutText [(localize "str_epoch_player_106") , "PLAIN DOWN"];
};

if (_finished) then {

_removed = ([player,_name,1] call BIS_fnc_invRemove);
if (_removed > 0) then {
_playerCash = player getVariable ["cashMoney",0];
player setVariable["cashMoney",(_playerCash + _price),true];
cutText [format[("Traded %1 for %2 %3"),_textPart,_price,CurrencyName], "PLAIN DOWN"];
PVDZE_plr_Save = [player,(magazines player),true,true] ;
publicVariableServer "PVDZE_plr_Save";

// Logging
if (isNil "_name") then { _name = "Unknown Item"; };
if (isNil "inTraderCity") then {
inTraderCity = "Unknown Trader City";
} else {
if (inTraderCity == "Any") then {
inTraderCity = "Unknown Trader";
};
};

PVDZE_obj_Trade = [_activatingPlayer,_traderID,1,_name,inTraderCity,CurrencyName,_price];
publicVariableServer "PVDZE_obj_Trade";
} else {
cutText [format["Something went wrong. Could not remove %1 from inventory", _name], "PLAIN DOWN"];
_abort = true;
};
};
sleep 1;

if(_abort) exitWith {};
};
DZE_ActionInProgress = false;

};

DZE_ActionInProgress = false;

Link to comment
Share on other sites

  • 3 weeks later...

 

where they are written?

how to incorporate "proper logging"?

 
So instead of these logs:18:44:11 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a Coins in/at trader city Branibor for 1x Coins" You now get something much more readable like:18:44:11 "EPOCH SERVERTRADE: Player: ROCU[] (xx) bought a FoodmuttonCooked in/at trader city Branibor for 120x Coins"
18:45:12 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a FoodmuttonCooked in/at Unknown Trader for 60x Coins"
18:52:33 "EPOCH SERVERTRADE: Player: ROCU[] (xx) bought a DZ_GunBag_EP1 in/at trader city Sabina for 6000x Coins"
19:28:16 "EPOCH SERVERTRADE: Player: ROCU[] (xx) sold a ItemVault in/at trader city Bilgrad for 100000x Coins"
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
  • Discord

×
×
  • Create New...