-- Copyright (C) 2021 Sandro Del Toro De Ana -- This file is part of Pvpinvul Minetest Mod. -- Pvpinvul is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- any later version. -- Pvpinvul is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with Pvpinvul. If not, see . -- Load support for MT game translation. -- Check for translation method local S if minetest.get_translator ~= nil then S = minetest.get_translator(core.get_current_modname()) -- 5.x translation function else if minetest.get_modpath("intllib") then dofile(minetest.get_modpath("intllib") .. "/init.lua") if intllib.make_gettext_pair then gettext, ngettext = intllib.make_gettext_pair() -- new gettext method else gettext = intllib.Getter() -- old text file method end S = gettext else -- boilerplate function S = function(str, ...) local args = {...} return str:gsub("@%d+", function(match) return args[tonumber(match:sub(2))] end) end end end local kill_hitter = core.settings:get_bool("pvpinvul_kill_hitter") or false local admin_privs = core.settings:get_bool("pvpinvul_admin_privs") or true -- compat with irc mod fork if core.get_modpath("irc") then if irc.saysec == nil then irc.saysec = irc.say end end -- priv core.register_privilege("pvpinvul", { description = S("Invulnerable in PVP"), give_to_singleplayer = false if admin_privs then give_to_admin = true end }) core.register_on_punchplayer( function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) -- only in pvp if not hitter:is_player() or not player:is_player() then return end local player_name = player:get_player_name() local hitter_name = hitter:get_player_name() local player_invul = core.check_player_privs(player_name, {pvpinvul=true}) local hitter_invul = core.check_player_privs(hitter_name, {pvpinvul=true}) if player_invul then if kill_hitter and not hitter_invul then hitter:set_hp(0) end core.chat_send_player(hitter_name, S("You can not hurt a God") ) core.chat_send_player(player_name, S("@1 try hurt you", hitter_name) ) if core.get_modpath("irc") then irc.saysec(player_name, hitter_name.." try hurt to "..player_name) end return true end end )