From 402af59a762335c603257226fd9561c83fe4d25b Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Thu, 28 Apr 2022 17:36:19 +0200 Subject: [PATCH] nopvp --- init.lua | 1 + nopvp.lua | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nopvp.lua diff --git a/init.lua b/init.lua index 9fe1071..a658b48 100644 --- a/init.lua +++ b/init.lua @@ -19,6 +19,7 @@ dofile(creative_regions.modpath.."/chatcommands.lua") dofile(creative_regions.modpath.."/items.lua") dofile(creative_regions.modpath.."/mod_areas.lua") dofile(creative_regions.modpath.."/arena.lua") +dofile(creative_regions.modpath.."/nopvp.lua") dofile(creative_regions.modpath.."/vehicles.lua") diff --git a/nopvp.lua b/nopvp.lua new file mode 100644 index 0000000..e700d0b --- /dev/null +++ b/nopvp.lua @@ -0,0 +1,22 @@ +minetest.register_privilege("pvp", { + description = "Allow PvP", + give_to_singleplayer= false, +}) + +minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) + if not hitter:is_player() then + return false -- if this is a MOB then give Damage + end + + local player_name = player:get_player_name() + if minetest.check_player_privs(player_name, {pvp=false}) then + return true + end + + local hitter_player_name = hitter:get_player_name() + if minetest.check_player_privs(hitter_player_name, {pvp=false}) then + return true + end + + return false +end)