2021-07-21 15:10:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Load support for MT game translation.
|
2022-01-25 17:22:45 -04:00
|
|
|
-- 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
|
2021-07-21 15:10:00 +02:00
|
|
|
|
2022-01-25 17:35:45 -04:00
|
|
|
local kill_hitter = core.settings:get_bool("pvpinvul_kill_hitter") or false
|
2021-07-21 15:10:00 +02:00
|
|
|
|
2022-01-25 18:00:46 -04:00
|
|
|
local admin_privs = core.settings:get_bool("pvpinvul_admin_privs") or true
|
|
|
|
|
2022-01-26 09:19:29 -04:00
|
|
|
local send_to_all = core.settings:get_bool("pvpinvul_send_to_all") or true
|
|
|
|
|
2021-07-21 15:10:00 +02:00
|
|
|
-- compat with irc mod fork
|
|
|
|
if core.get_modpath("irc") then
|
|
|
|
if irc.saysec == nil then
|
|
|
|
irc.saysec = irc.say
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-26 09:07:41 -04:00
|
|
|
local privs_give_to_admin = false
|
|
|
|
|
|
|
|
if admin_privs then privs_give_to_admin = true end
|
|
|
|
|
2021-07-21 15:10:00 +02:00
|
|
|
-- priv
|
|
|
|
core.register_privilege("pvpinvul", {
|
|
|
|
description = S("Invulnerable in PVP"),
|
2022-01-26 09:07:41 -04:00
|
|
|
give_to_singleplayer = false,
|
|
|
|
give_to_admin = privs_give_to_admin,
|
2021-07-21 15:10:00 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
2021-07-24 14:24:20 +02:00
|
|
|
local player_invul = core.check_player_privs(player_name, {pvpinvul=true})
|
|
|
|
local hitter_invul = core.check_player_privs(hitter_name, {pvpinvul=true})
|
2021-07-21 15:10:00 +02:00
|
|
|
|
2021-07-24 14:24:20 +02:00
|
|
|
if player_invul then
|
|
|
|
if kill_hitter and not hitter_invul then
|
2021-07-21 15:10:00 +02:00
|
|
|
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
|
2022-01-26 09:19:29 -04:00
|
|
|
if send_to_all then
|
|
|
|
irc.saysec(hitter_name.." try hurt to "..player_name)
|
|
|
|
else
|
|
|
|
irc.saysec(player_name, hitter_name.." try hurt you")
|
|
|
|
end
|
2021-07-21 15:10:00 +02:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
)
|
2022-01-25 18:01:23 -04:00
|
|
|
|
|
|
|
print("[MOD] pvpinvul loaded")
|