From 0ef16edb236d4bb355a5b3d72be027a10e5ddbb8 Mon Sep 17 00:00:00 2001 From: Apelta <54854228+TSafa-23@users.noreply.github.com> Date: Fri, 25 Dec 2020 12:36:32 -0600 Subject: [PATCH] Add antisabotage mod (#725) * Add antisabotage mod Prevents players of the same team from mining under or (somewhat) near others. Even works whilst crouching. * Fix slight issue of infinite items and radius fix Fixed issues dealing with unused variables, item removal and radius of the effect * Add newline so github doesn't die * Various improvements to function and distance Improvements/changes to improve performance and readability suggested by Lone_Wolf. * Create mod description Add readme.txt with description * Update with suggestions from Lone_Wolf Various performance optimizations and other issues suggested by Lone_Wolf * Remove unnecessary dependency * Snowball effect applied to a quick fix * Reword readme * Add license.txt MIT * Rename readme.txt to readme.md Co-authored-by: LoneWolfHT --- mods/pvp/antisabotage/init.lua | 21 +++++++++++++++++++++ mods/pvp/antisabotage/license.txt | 7 +++++++ mods/pvp/antisabotage/mod.conf | 2 ++ mods/pvp/antisabotage/readme.md | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 mods/pvp/antisabotage/init.lua create mode 100644 mods/pvp/antisabotage/license.txt create mode 100644 mods/pvp/antisabotage/mod.conf create mode 100644 mods/pvp/antisabotage/readme.md diff --git a/mods/pvp/antisabotage/init.lua b/mods/pvp/antisabotage/init.lua new file mode 100644 index 0000000..be1d6c8 --- /dev/null +++ b/mods/pvp/antisabotage/init.lua @@ -0,0 +1,21 @@ +-- Code by Apelta. Mutelated by Lone_Wolf + +minetest.register_on_dignode(function(pos, oldnode, digger) + if not digger:is_player() then return end + + local dname = digger:get_player_name() + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + + if name ~= dname and ctf.players[name].team == ctf.players[dname].team then + local player_pos = player:get_pos() + + if math.floor(player_pos.y) == pos.y and vector.distance(player_pos, pos) <= 1.5 then + minetest.set_node(pos, oldnode) + digger:get_inventory():remove_item("main", ItemStack(oldnode)) + minetest.chat_send_player(dname, "You can't mine blocks under your teammates!") + return + end + end + end +end) diff --git a/mods/pvp/antisabotage/license.txt b/mods/pvp/antisabotage/license.txt new file mode 100644 index 0000000..9026f4b --- /dev/null +++ b/mods/pvp/antisabotage/license.txt @@ -0,0 +1,7 @@ +Copyright 2020 Apelta + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/mods/pvp/antisabotage/mod.conf b/mods/pvp/antisabotage/mod.conf new file mode 100644 index 0000000..b810098 --- /dev/null +++ b/mods/pvp/antisabotage/mod.conf @@ -0,0 +1,2 @@ +name = antisabotage +depends = ctf diff --git a/mods/pvp/antisabotage/readme.md b/mods/pvp/antisabotage/readme.md new file mode 100644 index 0000000..7fc21cc --- /dev/null +++ b/mods/pvp/antisabotage/readme.md @@ -0,0 +1,3 @@ +# Anti Sabotage + +A simple mod that prevents players from sabotaging their teammates by digging blocks out from underneath them