Compare commits

...

5 Commits

Author SHA1 Message Date
fluxionary 4c4836134b
Disable knockback when PVP disabled (#8) 2022-05-14 18:18:40 +02:00
upsilon b84810f6c3 Allow players to hit themselves.
Some mods make players hit themselves when they use certain items.
2020-05-03 11:55:25 +02:00
David Leal 06fd54342e Use mod.conf for optional dependencies (#7)
Deletes deprecated 'depends.txt'.
2019-10-27 22:34:02 +01:00
upsilon b67fe9ea0d
upgrade intllib interfacing 2019-02-11 17:50:31 +01:00
zeuner 46ecf9a42b minetest v5 function deprecation (#5)
replace deprecated function call
2019-02-11 17:43:04 +01:00
8 changed files with 73 additions and 24 deletions

View File

@ -1,3 +0,0 @@
unified_inventory?
bones?
intllib?

View File

@ -1,4 +1,4 @@
if not minetest.setting_getbool("enable_pvp") then
if not minetest.settings:get_bool("enable_pvp") then
minetest.log("error", "[PvP Plus] PvP Plus cannot work if PvP is disabled. Please enable PvP.")
else
dofile(minetest.get_modpath(minetest.get_current_modname()).."/pvp.lua")

45
intllib.lua Normal file
View File

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -1 +1,2 @@
name = pvpplus
optional_depends = unified_inventory, bones, intllib

25
pvp.lua
View File

@ -4,14 +4,11 @@ local pvptable = {}
-- Public table, containing global functions
pvpplus = {}
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(translated)
return translated
end
end
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(
MP .. "/intllib.lua"
)
minetest.register_privilege("pvp", S("Can change own PvP state"))
minetest.register_privilege("pvp_admin", S("Can change others PvP state"))
@ -137,6 +134,10 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
local localname = player:get_player_name()
local hittername = hitter:get_player_name()
if localname == hittername then
return false
end
if not pvptable[localname].state then
minetest.chat_send_player(hittername, string.format(S("You can't hit %s because their PvP is disabled."), localname))
return true
@ -147,3 +148,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
end
return false
end)
local old_calculate_knockback = minetest.calculate_knockback
function minetest.calculate_knockback(player, hitter, ...)
if not pvpplus.is_pvp(player:get_player_name()) or not pvpplus.is_pvp(hitter:get_player_name()) then
return 0
end
return old_calculate_knockback(player, hitter, ...)
end

View File

@ -1,11 +1,8 @@
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(translated)
return translated
end
end
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(
MP .. "/intllib.lua"
)
if minetest.get_modpath("unified_inventory") then
unified_inventory.register_button("pvp", {

View File

@ -1,4 +1,4 @@
local tournament_starting_time = tonumber(minetest.setting_get("pvpplus.tournament_starting_time")) or 60 -- seconds
local tournament_starting_time = tonumber(minetest.settings:get("pvpplus.tournament_starting_time")) or 60 -- seconds
local tournament = pvpplus.tournament -- Shortcut reference
minetest.register_privilege("tournament_mod", "PvP Tournament Moderator")

View File

@ -3,9 +3,9 @@ tournament.hud = {}
tournament.hud_list = {}
-- These values cannot be exact for all clients. Default values should be fine for most of them.
local margin = tonumber(minetest.setting_get("pvpplus.tournament_hud_margin")) or 10 -- pixels
local font_width = tonumber(minetest.setting_get("pvpplus.font_width")) or 5 -- pixels
local separation = tonumber(minetest.setting_get("pvpplus.tournament_hud_separation")) or 18 -- pixels
local margin = tonumber(minetest.settings:get("pvpplus.tournament_hud_margin")) or 10 -- pixels
local font_width = tonumber(minetest.settings:get("pvpplus.font_width")) or 5 -- pixels
local separation = tonumber(minetest.settings:get("pvpplus.tournament_hud_separation")) or 18 -- pixels
function pvpplus.tournament_hud_update_list()
tournament.hud_list = {}