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.)

 

  Reveal hidden contents

 

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

 

Find:

Replace it with:

Open trade_backpacks.sqf

 

Find:

Below it, add:

Find:

Replace it with:

Find:

Above it, add:

Find:

Replace it with:

Open trade_items.sqf

 

Find:

Below it, add:

Find:

Below it, add:

Open trade_weapons.sqf
 
Find:

Below it, add:

Find:

Replace it with:

 

 

 

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

 

  On 9/10/2014 at 4:13 PM, PeterBeer said:

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

  On 9/11/2014 at 6:53 PM, PeterBeer said:

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

  On 10/5/2014 at 7:22 PM, Gr8Boi said:

can u update the file to have fast trading? thx

 

 

  On 10/27/2014 at 5:49 PM, Dew said:

a fast trading version would be perfect  :)

 

Will do that later today. Sorry Gr8Boi, missed your post somehow.

Link to comment
Share on other sites

  On 10/28/2014 at 1:02 AM, lordgeorge said:

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

 

  Reveal hidden contents

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...