diff --git a/Exile.ini b/Exile.ini new file mode 100644 index 0000000..e749353 --- /dev/null +++ b/Exile.ini @@ -0,0 +1,19 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Tree dammnit +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +[loadTreeIdPage] +SQL1_1 = SELECT id FROM tree LIMIT ?,? +Number Of Inputs = 2 +SQL1_INPUTS = 1,2 +OUTPUT = 1 + +[loadTree] +SQL1_1 = SELECT position_x, position_y, position_z FROM tree WHERE id = ? +Number Of Inputs = 1 +SQL1_INPUTS = 1 +OUTPUT = 1,2,3 + +[insertTree] +SQL1_1 = INSERT INTO tree SET position_x = ?, position_y = ?, position_z = ? +Number of Inputs = 3 +SQL1_INPUTS = 1,2,3 \ No newline at end of file diff --git a/MpMission/overwrites/ExileServer_object_tree_network_chopTreeRequest.sqf b/MpMission/overwrites/ExileServer_object_tree_network_chopTreeRequest.sqf new file mode 100644 index 0000000..f633438 --- /dev/null +++ b/MpMission/overwrites/ExileServer_object_tree_network_chopTreeRequest.sqf @@ -0,0 +1,87 @@ +/** + * ExileServer_object_tree_network_chopTreeRequest + * + * Exile Mod + * www.exilemod.com + * © 2015 Exile Mod Team + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + */ + +private["_sessionId", "_parameters", "_treeNetId", "_tree", "_isTree", "_player", "_treeHeight", "_newDamage", "_treePosition", "_spawnRadius", "_weaponHolders", "_weaponHolder", "_health", "_weaponHolderPosition"]; +_sessionId = _this select 0; +_parameters = _this select 1; +_treeNetId = _parameters select 0; +try +{ + _tree = objectFromNetId _treeNetId; + if (isNull _tree) then + { + throw format ["Cannot chop unknown tree! %1", _treeNetId]; + }; + if !(alive _tree) then + { + throw "Cannot chop already chopped tree!"; + }; + _isTree = [_tree, "WoodSource"] call ExileClient_util_model_isInteraction; + if !(_isTree) then + { + throw "Can only chop down trees, you twat!"; + }; + _player = _sessionId call ExileServer_system_session_getPlayerObject; + if (isNull _player) then + { + throw "Unknown players cannot chop trees!"; + }; + if !(alive _player) then + { + throw "The dead cannot chop down trees!"; + }; + if ((_player distance _tree) > 30) then + { + throw "No long distance tree chopping! Nope!"; + }; + _treeHeight = _tree call ExileClient_util_model_getHeight; + _treeHeight = _treeHeight max 1; + _newDamage = ((damage _tree) + (1 / (floor _treeHeight) )) min 1; + _tree setDamage _newDamage; + if (_newDamage isEqualTo 1) then + { + _tree setDamage 999; + }; + _treePosition = getPosATL _tree; + _treePosition set[2, 0]; + _spawnRadius = 3; + _weaponHolders = nearestObjects[_treePosition, ["GroundWeaponHolder"], _spawnRadius]; + _weaponHolder = objNull; + + + // Persistent Tree Logging Edits + _health = getDammage _tree; + _data = [_treePosition select 0, _treePosition select 1, _treePosition select 2]; + if (_health isEqualTo 1) then + { + _extDB2Message = ["insertTree", _data] call ExileServer_util_extDB2_createMessage; + _extDB2Message call ExileServer_system_database_query_fireAndForget; + }; + // Persistent Tree Logging Edits + + + if (_weaponHolders isEqualTo []) then + { + _weaponHolderPosition = getPosATL _player; + _weaponHolder = createVehicle ["GroundWeaponHolder", _weaponHolderPosition, [], 0, "CAN_COLLIDE"]; + _weaponHolder setPosATL _weaponHolderPosition; + } + else + { + _weaponHolder = _weaponHolders select 0; + }; + _weaponHolder addMagazineCargoGlobal ["Exile_Item_WoodLog", 1]; +} +catch +{ + _exception call ExileServer_util_log; +}; +true \ No newline at end of file diff --git a/README.md b/README.md index be4fef5..d159e6e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ # PersistentTreeLogging -Persistent Tree logging on Exile. +Tree Logging Persistent for Exile. + +## Configuration + +Add inside your mission config.cpp at the cfgcustomcode ExileServer_object_tree_network_chopTreeRequest and use the file provided inside MpMission/overwrites. + +Drag the Server Addon to your ExileServer Addons folder and profit. + +Oyeeh, don't forget to read the Sql Instructions.txt + + +## Donations + +Fuck you and you're donations, send them to Exile. + +http://www.exilemod.com/donate/make-donation/ + +## Credits + +Original code base by CoftSock. + +## License +Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) diff --git a/Server Addon/TreeLogging.pbo b/Server Addon/TreeLogging.pbo new file mode 100644 index 0000000..c4cd7dc Binary files /dev/null and b/Server Addon/TreeLogging.pbo differ diff --git a/Server Addon/TreeLogging/bootstrap/fn_postInit.sqf b/Server Addon/TreeLogging/bootstrap/fn_postInit.sqf new file mode 100644 index 0000000..c13c403 --- /dev/null +++ b/Server Addon/TreeLogging/bootstrap/fn_postInit.sqf @@ -0,0 +1,5 @@ +"TreeLogging PostInit started..." call ExileServer_TreeLogging_log; + +[] call ExileServer_world_loadAllDatabaseTrees; + +"TreeLogging PostInit finished..." call ExileServer_TreeLogging_log; diff --git a/Server Addon/TreeLogging/bootstrap/fn_preInit.sqf b/Server Addon/TreeLogging/bootstrap/fn_preInit.sqf new file mode 100644 index 0000000..936ac68 --- /dev/null +++ b/Server Addon/TreeLogging/bootstrap/fn_preInit.sqf @@ -0,0 +1,14 @@ +private["_code"]; + +{ + _code = compileFinal (preprocessFileLineNumbers (_x select 1)); + missionNamespace setVariable [(_x select 0), _code]; +} +forEach +[ + ['ExileServer_world_loadAllDatabaseTrees', 'TreeLogging\functions\ExileServer_world_loadAllDatabaseTrees.sqf'], + ['ExileServer_object_tree_database_load', 'TreeLogging\functions\ExileServer_object_tree_database_load.sqf'], + ['ExileServer_TreeLogging_log', 'TreeLogging\functions\ExileServer_TreeLogging_log.sqf'] +]; + +"TreeLogging PreInit finished" call ExileServer_TreeLogging_log; diff --git a/Server Addon/TreeLogging/config.cpp b/Server Addon/TreeLogging/config.cpp new file mode 100644 index 0000000..ee9ae6a --- /dev/null +++ b/Server Addon/TreeLogging/config.cpp @@ -0,0 +1,25 @@ +class CfgPatches { + class TreeLogging { + requiredVersion = 0.1; + requiredAddons[] = { + "exile_server" + }; + units[] = {}; + weapons[] = {}; + }; +}; +class CfgFunctions { + class TreeLogging { + class main { + file="TreeLogging\bootstrap"; + class preInit + { + preInit = 1; + }; + class postInit + { + postInit = 1; + }; + }; + }; +}; diff --git a/Server Addon/TreeLogging/functions/ExileServer_TreeLogging_log.sqf b/Server Addon/TreeLogging/functions/ExileServer_TreeLogging_log.sqf new file mode 100644 index 0000000..8867137 --- /dev/null +++ b/Server Addon/TreeLogging/functions/ExileServer_TreeLogging_log.sqf @@ -0,0 +1,4 @@ +private["_msg"]; + +_msg = format["Exile TreeLogging log: %1",_this]; +diag_log _msg; \ No newline at end of file diff --git a/Server Addon/TreeLogging/functions/ExileServer_object_tree_database_load.sqf b/Server Addon/TreeLogging/functions/ExileServer_object_tree_database_load.sqf new file mode 100644 index 0000000..b63efe4 --- /dev/null +++ b/Server Addon/TreeLogging/functions/ExileServer_object_tree_database_load.sqf @@ -0,0 +1,20 @@ +/** + * ExileServer_object_tree_database_load + * + * Exile Mod + * www.exilemod.com + * © 2015 Exile Mod Team + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + */ + +private["_treeID", "_data", "_position", "_Tree", "_SelectTree"]; +_treeID = _this; +_data = format ["loadTree:%1", _treeID] call ExileServer_system_database_query_selectSingle; +_position = [_data select 0, _data select 1, _data select 2]; +_Tree = nearestTerrainObjects [_position, ["Tree"], 5]; +_SelectTree = _Tree select 0; +diag_log format ["Hiding Tree @ %1", _SelectTree]; +_SelectTree hideObjectGlobal true; +true \ No newline at end of file diff --git a/Server Addon/TreeLogging/functions/ExileServer_world_loadAllDatabaseTrees.sqf b/Server Addon/TreeLogging/functions/ExileServer_world_loadAllDatabaseTrees.sqf new file mode 100644 index 0000000..7f0993e --- /dev/null +++ b/Server Addon/TreeLogging/functions/ExileServer_world_loadAllDatabaseTrees.sqf @@ -0,0 +1,35 @@ +/** + * ExileServer_world_loadAllDatabaseTrees + * + * Exile Mod + * www.exilemod.com + * © 2015 Exile Mod Team + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + */ + +private["_continueLoading", "_page", "_pageSize", "_TreeIDs", "_numberOfTrees", "_i"]; +"Loading trees from database..." call ExileServer_TreeLogging_log; +_continueLoading = true; +_page = 0; +_pageSize = 100; +while {_continueLoading} do +{ + _TreeIDs = format ["loadTreeIdPage:%1:%2", _page * _pageSize, _pageSize] call ExileServer_system_database_query_selectFull; + _numberOfTrees = count _TreeIDs; + if (_numberOfTrees > 0) then + { + for "_i" from 0 to _numberOfTrees - 1 do + { + ((_TreeIDs select _i) select 0) call ExileServer_object_tree_database_load; + }; + }; + _page = _page + 1; + if (_numberOfTrees < 100) then + { + _continueLoading = false; + }; +}; +"Done loading trees!" call ExileServer_TreeLogging_log; +true \ No newline at end of file diff --git a/Sql Instructions.txt b/Sql Instructions.txt new file mode 100644 index 0000000..723d86e --- /dev/null +++ b/Sql Instructions.txt @@ -0,0 +1,9 @@ +SQL instructions: + +Import the Tree.sql and after that create a "scheduler" inside your MySQL database. + +Import this scheduler task: + +CREATE DEFINER=`root`@`localhost` EVENT `Re-grow tree's` ON SCHEDULE EVERY 1 HOUR STARTS '2017-12-11 11:11:11' ON COMPLETION PRESERVE ENABLE DO Delete FROM `tree` WHERE DATE(added) < DATE(NOW() - INTERVAL 10 DAY) + +And turn the scheduler ON! \ No newline at end of file diff --git a/Tree.sql b/Tree.sql new file mode 100644 index 0000000..285be91 --- /dev/null +++ b/Tree.sql @@ -0,0 +1,40 @@ +SET FOREIGN_KEY_CHECKS=0; +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + + +-- +-- Tabelstructuur `tree` +-- + +CREATE TABLE `tree` ( + `id` int(11) UNSIGNED NOT NULL, + `position_x` double DEFAULT NULL, + `position_y` double DEFAULT NULL, + `position_z` double DEFAULT NULL, + `added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Indexen `tree` +-- +ALTER TABLE `tree` + ADD PRIMARY KEY (`id`); +-- +-- AUTO_INCREMENT `tree` +-- +ALTER TABLE `tree` + MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; +SET FOREIGN_KEY_CHECKS=1; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file