diff --git a/@DayZ_Epoch_Server/addons/dayz_server/compile/server_paintVehicles.sqf b/@DayZ_Epoch_Server/addons/dayz_server/compile/server_paintVehicles.sqf index 3de6aec..2067ced 100644 --- a/@DayZ_Epoch_Server/addons/dayz_server/compile/server_paintVehicles.sqf +++ b/@DayZ_Epoch_Server/addons/dayz_server/compile/server_paintVehicles.sqf @@ -1,7 +1,7 @@ // =========================================================================== // @PAINT VEHICLES // =========================================================================== -private ["_object","_colorArr","_textArr","_pname","_PUID","_name","_pcolor","_pcolor2","_clrinit","_clrinit2","_texture","_texture2","_position","_worldspace","_fuel","_objectID","_key"]; +private ["_object","_colorArr","_textArr","_pname","_PUID","_name","_colour","_colour2","_clrinit","_clrinit2","_texture","_texture2","_position","_worldspace","_fuel","_objectID","_key"]; _object = _this select 0; _colorArr = _this select 1; @@ -12,24 +12,27 @@ _name = getText(configFile >> "cfgVehicles" >> (typeOf _object) >> "displayName" call { if (count _textArr == 0) exitWith { - _pcolor = _colorArr select 0; - _pcolor2 = _colorArr select 1; + _colour = _colorArr select 0; + _colour2 = _colorArr select 1; - _clrinit = format ["#(argb,8,8,3)color(%1)",_pcolor]; - _clrinit2 = format ["#(argb,8,8,3)color(%1)",_pcolor2]; + if (isNil "_colour") then {_colour = "0";}; + if (isNil "_colour2") then {_colour2 = "0";}; + + _clrinit = format ["#(argb,8,8,3)color(%1)",_colour]; + _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2]; _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];"; _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];"; processInitCommands; - _object setVariable["Colour",_pcolor,true]; - _object setVariable["Colour2",_pcolor2,true]; + _object setVariable["Colour",_colour,true]; + _object setVariable["Colour2",_colour2,true]; diag_log format ["VEHICLE PAINT: Player %1 (%2) has painted a %3!",_pname,_PUID,_name]; _position = getPosATL _object; - _worldspace = [getDir _object,_position,_pcolor,_pcolor2] call AN_fnc_formatWorldspace; + _worldspace = [getDir _object,_position,_colour,_colour2] call AN_fnc_formatWorldspace; _fuel = 0; _fuel = fuel _object; @@ -38,7 +41,7 @@ call { _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel]; _key call server_hiveWrite; - // diag_log format ["=== VEHICLE PAINT DEBUG: NORMAL MODE: _pcolor [%1], _pcolor2 [%2]",_pcolor,_pcolor2]; + // diag_log format ["=== VEHICLE PAINT DEBUG: NORMAL MODE: _colour [%1], _colour2 [%2]",_colour,_colour2]; }; if (count _colorArr == 0) exitWith { _texture = _textArr select 0; @@ -49,16 +52,16 @@ call { processInitCommands; - _pcolor = "0"; - _pcolor2 = "0"; + _colour = "0"; + _colour2 = "0"; - _object setVariable["Colour",_pcolor,true]; - _object setVariable["Colour2",_pcolor2,true]; + _object setVariable["Colour",_colour,true]; + _object setVariable["Colour2",_colour2,true]; diag_log format ["VEHICLE PAINT: Player %1 (%2) has reset painting of %3!",_pname,_PUID,_name]; _position = getPosATL _object; - _worldspace = [getDir _object,_position,_pcolor,_pcolor2] call AN_fnc_formatWorldspace; + _worldspace = [getDir _object,_position,_colour,_colour2] call AN_fnc_formatWorldspace; _fuel = 0; _fuel = fuel _object; @@ -67,7 +70,7 @@ call { _key = format["CHILD:305:%1:%2:%3:",_objectID,_worldspace,_fuel]; _key call server_hiveWrite; - // diag_log format ["=== VEHICLE PAINT DEBUG: RESET MODE: _pcolor [%1], _pcolor2 [%2]",_pcolor,_pcolor2]; + // diag_log format ["=== VEHICLE PAINT DEBUG: RESET MODE: _colour [%1], _colour2 [%2]",_colour,_colour2]; }; }; diff --git a/@DayZ_Epoch_Server/addons/dayz_server/compile/server_updateObject.sqf b/@DayZ_Epoch_Server/addons/dayz_server/compile/server_updateObject.sqf index fa18f90..48adc05 100644 --- a/@DayZ_Epoch_Server/addons/dayz_server/compile/server_updateObject.sqf +++ b/@DayZ_Epoch_Server/addons/dayz_server/compile/server_updateObject.sqf @@ -50,15 +50,17 @@ _needUpdate = _object in needUpdate_objects; // TODO ---------------------- // =========================================================================== -// @UPDATED: PAINT VAEHICLES +// @UPDATED: PAINT VEHICLES // =========================================================================== _object_position = { - private ["_position","_worldspace","_fuel","_key","_pcolor","_pcolor2"]; + private ["_position","_worldspace","_fuel","_key","_colour","_colour2"]; _position = getPosATL _object; if (_object isKindOf "AllVehicles") then { - _pcolor = _object getVariable ["Colour","0"]; - _pcolor2 = _object getVariable ["Colour2","0"]; - _worldspace = [getDir _object,_position,_pcolor,_pcolor2] call AN_fnc_formatWorldspace; + _colour = _object getVariable ["Colour","0"]; + _colour2 = _object getVariable ["Colour2","0"]; + if (isNil "_colour") then {_colour = "0";}; + if (isNil "_colour2") then {_colour2 = "0";}; + _worldspace = [getDir _object,_position,_colour,_colour2] call AN_fnc_formatWorldspace; _fuel = fuel _object; } else { _worldspace = [getDir _object, _position] call AN_fnc_formatWorldspace; diff --git a/@DayZ_Epoch_Server/addons/dayz_server/system/server_monitor.sqf b/@DayZ_Epoch_Server/addons/dayz_server/system/server_monitor.sqf index 44116c1..eb92727 100644 --- a/@DayZ_Epoch_Server/addons/dayz_server/system/server_monitor.sqf +++ b/@DayZ_Epoch_Server/addons/dayz_server/system/server_monitor.sqf @@ -220,7 +220,7 @@ if ((playersNumber west + playersNumber civilian) == 0) exitWith { _object setVariable ["lastUpdate",diag_ticktime]; _object setVariable ["ObjectID", _idKey, true]; _object setVariable ["OwnerPUID", _ownerPUID, true]; - if (Z_SingleCurrency && {_type in DZE_MoneyStorageClasses}) then { + if (Z_SingleCurrency && {(_type in DZE_MoneyStorageClasses) || (_object isKindOf "AllVehicles")}) then { _object setVariable [Z_MoneyVariable, _storageMoney, true]; }; @@ -272,7 +272,7 @@ if ((playersNumber west + playersNumber civilian) == 0) exitWith { // ===================================================================== if (_object isKindOf "AllVehicles") then { // ===================================================================== - private ["_pcolor","_pcolor2","_clrinit","_clrinit2"]; + private ["_colour","_colour2","_clrinit","_clrinit2"]; // ===================================================================== _object setVariable ["CharacterID", _ownerID, true]; _isAir = _object isKindOf "Air"; @@ -284,25 +284,25 @@ if ((playersNumber west + playersNumber civilian) == 0) exitWith { _object setVariable [_strH,_dam,true]; } foreach _hitpoints; [_object,"damage"] call server_updateObject; - // ======================================================================= + // ===================================================================== if(count _worldspace >= 4) then { if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then { - _pcolor = _worldspace select 2; - _pcolor2 = _worldspace select 3; - if (_pcolor != "0") then { - _object setVariable ["Colour",_pcolor,true]; - _clrinit = format ["#(argb,8,8,3)color(%1)",_pcolor]; + _colour = _worldspace select 2; + _colour2 = _worldspace select 3; + if (_colour != "0") then { + _object setVariable ["Colour",_colour,true]; + _clrinit = format ["#(argb,8,8,3)color(%1)",_colour]; _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];"; }; - if (_pcolor2 != "0") then { - _object setVariable ["Colour2",_pcolor2,true]; - _clrinit2 = format ["#(argb,8,8,3)color(%1)",_pcolor2]; + if (_colour2 != "0") then { + _object setVariable ["Colour2",_colour2,true]; + _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2]; _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];"; }; processInitCommands; }; }; - // ======================================================================= + // ===================================================================== _object setFuel _fuel; if (!_isSafeObject) then { @@ -478,10 +478,10 @@ if (dayz_townGenerator) then {execVM "\z\addons\dayz_server\system\lit_fireplace _uid = getPlayerUID _player; _treeModel = _tree call fn_getModelName; - if (_dis < 30 && (_treeModel in dayz_trees or (_treeModel in dayz_plant)) && (_uid != "")) then { + if ((_dis < 30) && (_treeModel in dayz_trees) && (_uid != "")) then { _tree setDamage 1; dayz_choppedTrees set [count dayz_choppedTrees,_tree]; - diag_log format["Server setDamage on tree or plant %1 chopped down by %2(%3)",_treeModel,_name,_uid]; + diag_log format["Server setDamage on tree %1 chopped down by %2(%3)",_treeModel,_name,_uid]; }; }; diff --git a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/fnc_SC_uniCoins.sqf b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/fnc_SC_uniCoins.sqf index 872ec27..694abbf 100644 --- a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/fnc_SC_uniCoins.sqf +++ b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/fnc_SC_uniCoins.sqf @@ -1,90 +1,197 @@ // =========================================================================== -// SINGLE CURRENCY (@money: universal dev function: add/remove cache/bank coins) +// FUNCTIONS LIBRARY >> SINGLE CURRENCY >> fnc_SC_uniCoins.sqf // =========================================================================== -// @credits: -// - DayZ Epoch developers, collaborators and contributors +// @Function name: fnc_SC_uniCoins +// =========================================================================== +// @Info: +// - Created by @iben for DayzEpoch 1.0.6.1+ +// - Version: 1.2, Last Update [2017-06-14] +// - Credits: +// * DayZ Epoch developers, collaborators and contributors // (thank you guys for your excellent work!) -// - @Zupa: original SC concept creator and author of Universal Dev functions +// * @Zupa: original SC concept creator and author of Universal Dev functions // for 1.0.5 version. // (see https://epochmod.com/forum/topic/15463-devs-universal-removeadd-coins-function/) -// - @salival for adapting @Zupa's concept to 1.0.6+ version and great community support +// * @salival for adapting @Zupa's concept to 1.0.6+ version and great community support // (see: https://epochmod.com/forum/topic/43331-zsc-for-epoch-106-and-overwatch-025/) +// * ** All great guys from Epoch comunity participating on SC and banking concept ** +// (see: https://epochmod.com/forum/forum/56-gold-coin-based-single-currency-banking-system/) +// @Remarks: +// - It's unified fnc for money proccessing. You can use 4 keywors in combination +// to achieve desired effect +// * Keywords: "add" / "remove", "cache" / "bank" +// - Epoch Forum thread: https://epochmod.com/forum/topic/44006-re-release-v11-fn_sc_unicoins-dev-function-for-single-currency-rewritten-and-updated-for-epoch-1061/ +// @Parameters: +// - '_player': (player, _killer...etc) | object +// '_amount' : (1000, 50000) | number +// '_action' : (Keywords: 'add' / 'remove') | string +// '_target' : (Keywords: 'cache' / 'bank') | string +// @Prerequisities: +// - none +// @Example: +// - #Example01: Remove 5.000 Coins from player's wallet: +// * [player,5000,'remove','cache'] call IBEN_fnc_SC_uniCoins; +// - #Example02: Add 1.000 Coins to player's wallet: +// * [player,1000,'add','cache'] call IBEN_fnc_SC_uniCoins; +// - #Example03: Remove 15.000 Coins from player's bank account: +// * [player,15000,'remove','bank'] call IBEN_fnc_SC_uniCoins; +// - #Example03: Add 50.000 Coins to player's bank account: +// * [player,50000,'add','bank'] call IBEN_fnc_SC_uniCoins; +// @Returns: +// - Boolean // =========================================================================== -// Reworked for DayZ Epoch 1.0.6.1+ by @iben+ -// =========================================================================== -// @parameters: -// [_player,_amount,_action,_target] call fnc_SC_uniCoins; -// '_player' : object : player, _killer...etc -// '_amount' : number : 1000 -// '_action' : string : 'add' / 'remove' -// '_target' : string : 'cache' / 'bank' -// @usage: -// === Example 01: Remove 5.000 Coins from player's wallet: -// [player,5000,'remove','cache'] call fnc_SC_uniCoins; -// === Example 02: Add 1.000 Coins to playe's bank account -// [player,1000,'add','bank'] call fnc_SC_uniCoins; +// @Parameters Legend: +// * _a = _player +// * _b = _amount +// * _c = _action +// * _d = _target +// * _fa = _fnc_SC_uniCoinsDebug +// * _fb = _fnc_playerForceSave +// * _fc = _fnc_previewCoins +// * _fd = _fnc_removeCoins +// * _fe = _fnc_addCoins +// * _g = _gvar +// * _m = _msg +// * _n = _money +// * _p = _wealth +// * _q = _removed +// * _r = _result +// * _s = _added +// * _u = _newWealth +// * _xd = _Tdebug // =========================================================================== // @important: // + DayZ Epoch 'local_eventKill.sqf' with code for testing is available: // https://gist.github.com/infobeny/0fa8ff0f0a50ca7877a26e0951ac358e // =========================================================================== -private ["_player","_amount","_action","_target","_gvar","_result", - "_fnc_previewCoins","_fnc_removeCoins","_fnc_addCoins"]; - -_player = _this select 0; -_amount = _this select 1; -_action = _this select 2; -_target = _this select 3; - -_gvar = [Z_bankVariable, Z_moneyVariable] select (_target == "cache"); -_result = false; - -_fnc_previewCoins = { - private ["_money"]; - _money = 0; - _money = _player getVariable [_gvar, 0]; - _money -}; - -_fnc_removeCoins = { - private ["_wealth","_removed"]; - _wealth = call _fnc_previewCoins; - _removed = false; - if (_amount > 0) then { - if (_wealth < _amount) then { - _removed = false; +// fnc_SC_uniCoins = { + // ========================================================================= + // DEFINE PREPROCESSOR COMMANDS FOR PARSING + // ========================================================================= + // @readme: Uncomment line bellow if you want to use param check and exec timer + // #define __DEBUG__ + // ==================================== + + #ifdef __DEBUG__ + #define MPR "Error! Too many parameters in function" + #define MPN "Error! Player is not recognized" + #define MPS "Error! Player cannot be string" + #define MAS "Error! Amount is not a number" + #define SRC "IBEN_fnc_SC_uniCoins" + #endif + // ========================================================================= + + // === DEBUG =============================================================== + // NOTE: For best results restart your client before conducting tests. + // This function uses diag_tickTime which loses its precision the longer + // the client runs from restart. + #ifdef __DEBUG__ + private "_xd"; + _xd = diag_tickTime; + #endif + // ========================================================================= + + private ["_a","_b","_c","_d"]; + _a = _this select 0; + _b = _this select 1; + _c = _this select 2; + _d = _this select 3; + + // === DEBUG =============================================================== + #ifdef __DEBUG__ + private "_fa"; + _fa = { + private ["_r","_m"]; + _m = "nil"; + _r = false; + call { + if ((count _this) != 4) exitWith {_m = MPR;_r = false}; + if (isNil "_a") exitWith {_m = MPN;_r = false}; + if (typeName _a == "STRING") exitWith {_m = MPS;_r = false}; + if (typeName _b != "SCALAR") exitWith {_m = MAS;_r = false}; + _r = true + }; + + if !(_r) then { + player globalChat format ["%1",_m]; + diag_log format ["=== [%1] %2",SRC,_m]; + _r = false + }; + + _r + }; + if !(call _fa) exitWith {hintSilent "[IBEN_fnc_SC_uniCoins] Error!"}; + #endif + // ========================================================================= + + private ["_g","_r"]; + _g = [Z_bankVariable, Z_moneyVariable] select (_d == "cache"); + _r = false; + + private "_fb"; + _fb = { + PVDZ_plr_Save = [_a, nil]; + publicVariableServer "PVDZ_plr_Save"; + dayz_lastSave = diag_tickTime; + }; + + private "_fc"; + _fc = { + private ["_n"]; + _n = 0; + _n = _a getVariable [_g, 0]; + _n + }; + + private "_fd"; + _fd = { + private ["_p","_q"]; + _p = call _fc; + _q = false; + if (_b > 0) then { + if (_p < _b) then { + _q = false; + } else { + _a setVariable [_g, _p - _b, true]; + _q = true; + call _fb; + }; } else { - _player setVariable [_gvar, _wealth - _amount, true]; - _removed = true; - call player_forceSave; + _q = true; }; - } else { - _removed = true; + _q + }; + + private "_fe"; + _fe = { + private ["_p","_s","_u"]; + _p = call _fc; + _s = false; + _a setVariable [_g, _p + _b, true]; + call _fb; + _u = call _fc; + if (_u >= _p) then {_s = true;}; + _s }; - _removed -}; - -_fnc_addCoins = { - private ["_wealth","_added","_newWealth"]; - _wealth = call _fnc_previewCoins; - _added = false; - _player setVariable [_gvar, _wealth + _amount, true]; - call player_forceSave; - _newWealth = call _fnc_previewCoins; - if (_newWealth >= _wealth) then {_added = true;}; - _added -}; - -if ((!isNil "_action") && (!isNil "_target")) then { + call { - if (_action == "remove") exitWith { - if (call _fnc_removeCoins) then {_result = true;} else {_result = false;}; + if (_c == "remove") exitWith { + _r = [false,true] select (call _fd); }; - if (_action == "add") exitWith { - if (call _fnc_addCoins) then {_result = true;} else {_result = false;}; + if (_c == "add") exitWith { + _r = [false,true] select (call _fe); }; - _result = false; // default + _r = false; // default }; -}; -_result + // === DEBUG =============================================================== + #ifdef __DEBUG__ + [SRC,(diag_tickTime - _xd)] call IBEN_fnc_codePerformace; + #endif + // ========================================================================= + + _r + +// }; + +// === :: FUNCTIONS LIBRARY >> SINGLE CURRENCY >> fnc_SC_uniCoins.sqf :: END diff --git a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/player_paintVehicle.sqf b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/player_paintVehicle.sqf index 3f5e486..9feeebd 100644 --- a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/player_paintVehicle.sqf +++ b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/compile/player_paintVehicle.sqf @@ -2,14 +2,14 @@ // @PAINT VEHICLES // =========================================================================== VehicleColorPaint = { - private ["_pcolor","_pcolor2"]; - _pcolor = ""+str((sliderPosition 5700) / 10)+","+str((sliderPosition 5701) / 10)+","+str((sliderPosition 5702) / 10)+",1"; - _pcolor2 = ""+str((sliderPosition 6700) / 10)+","+str((sliderPosition 6701) / 10)+","+str((sliderPosition 6702) / 10)+",1"; + private ["_colour","_colour2"]; + _colour = ""+str((sliderPosition 5700) / 10)+","+str((sliderPosition 5701) / 10)+","+str((sliderPosition 5702) / 10)+",1"; + _colour2 = ""+str((sliderPosition 6700) / 10)+","+str((sliderPosition 6701) / 10)+","+str((sliderPosition 6702) / 10)+",1"; if !([player,PV_Price,'remove','cache'] call fnc_SC_uniCoins) exitWith { format ["You need %1 %2 to repaint your vehicle!", [PV_Price] call BIS_fnc_numberText, CurrencyName] call dayz_rollingMessages; }; [format ["%1 %2 removed from your wallet! Let's start painting....",[PV_Price] call BIS_fnc_numberText, CurrencyName],1] call dayz_rollingMessages; - PVDZE_veh_Color = [VehicleToPaint,[_pcolor,_pcolor2],[],player]; + PVDZE_veh_Color = [VehicleToPaint,[_colour,_colour2],[],player]; publicVariableServer "PVDZE_veh_Color"; }; diff --git a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/init/compiles.sqf b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/init/compiles.sqf index ed4f634..7e4192b 100644 --- a/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/init/compiles.sqf +++ b/MPMissions/DayZ_Epoch_11.Chernarus/dayz_code/init/compiles.sqf @@ -17,3 +17,13 @@ if (!isDedicated) then { // BOTH // =========================================================================== fnc_SC_uniCoins = compile preprocessFileLineNumbers "dayz_code\compile\fnc_SC_uniCoins.sqf"; + +// =========================================================================== +// BOTH :: [DEBUG ONLY] +// =========================================================================== +IBEN_fnc_codePerformace = { + private ["_a","_b"]; + _a = _this select 0; + _b = _this select 1; + player globalChat format ["src: [%1], Exec time [%2]",_a,_b]; +}; diff --git a/README.md b/README.md index 38f4bde..50dfd34 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Paint Vehicles -**Last update: [2017-08-19], v1.1** ([see changelog](#changelog)) +**Last update: [2017-08-22], v1.2** ([see changelog](#changelog)) --- @@ -39,10 +39,11 @@ + Vehicles can be painted in two different colors + Only vehicles which you own can be painted (vehicles with key) + Only vehicles in `ColourVehicles` array can be painted -+ Script is designed to be used along with **Single currency**. Player will pay for painting vehicles. ++ Script is designed to be used along with **Single currency**. Player will pay for painting vehicles + **UPDATED:** Color values are saved in the worldspace field in database + **NEW:** Vehicles can be unpainted to default state (default textures are loaded) + **UPDATED:** Vehicles can be painted using GUI with visual enhancements. Use PaintVehicles `defines.hpp` for defining custom GUI color scheme ++ **UPDATED:** Script is now fully compatible with **Virtual Garage** and **Vehicle Key Changer (VKC)** script thanks to @salival (**2017-08-22**). All scripts by @salival and this one prior update date should be upgraded to get much better player experience! --- @@ -118,6 +119,7 @@ For **server side** (`dayz_server`) we need to touch these files: | :--- | :--- | :--- | | [2017-05-22] | v1.0 | Initial release | | [2017-05-27] | v1.1 | Optimized compiles: 5 files reduced to 1 main file.
_See changes:_ [[commit ae29c13][update1]] | +| [2017-08-20] | v1.2 | Regular code maintenance.
_See changes:_ [[commit 682f99a][update2]] , [[commit xx][update3]] | --- @@ -126,3 +128,5 @@ For **server side** (`dayz_server`) we need to touch these files: [overheatthread]: https://epochmod.com/forum/topic/18624-release-paint-vehicles/ "Go to source" [raymixthread]: https://epochmod.com/forum/topic/19651-extras-full-list-of-paintable-vehicles-for-paint-vehicles-script/ "Go to source" [update1]: https://github.com/infobeny/PaintVehicles/commit/ae29c1349802095025c6d8296f97d7e594988150 "See changes" +[update2]: https://github.com/infobeny/PaintVehicles/commit/682f99ac5a4432e8b47035d030dede9c5002eb13 "See changes" +[update3]: https://github.com/infobeny/PaintVehicles/commit/682f99ac5a4432e8b47035d030dede9c5002eb13 "See changes"