Allow players possessing the `pvp_admin` priv to change others PvP state
parent
c28580dd1c
commit
5c7c9eaff9
|
@ -21,7 +21,6 @@ Some additional commands are only executable by the players possessing the `tour
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
* `pvpplus.enable_sound_loop = true`: whether to play a looped epic music during the tournament
|
* `pvpplus.enable_sound_loop = true`: whether to play a looped epic music during the tournament
|
||||||
* `pvpplus.default_pvp_state = false`: PvP state given to players when they join the game
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,6 @@ Disables PvP = Désactive le PvP
|
||||||
Your PvP is already disabled. = Votre PvP est déjà désactivé.
|
Your PvP is already disabled. = Votre PvP est déjà désactivé.
|
||||||
You can't hit %s because their PvP is disabled. = Vous ne pouvez pas frapper %s car son PvP est désactivé.
|
You can't hit %s because their PvP is disabled. = Vous ne pouvez pas frapper %s car son PvP est désactivé.
|
||||||
You can't hit %s because your PvP is disabled. = Vous ne pouvez pas frapper %s car votre PvP est désactivé.
|
You can't hit %s because your PvP is disabled. = Vous ne pouvez pas frapper %s car votre PvP est désactivé.
|
||||||
|
Can change own PvP state = Peut changer l'état de son propre PvP
|
||||||
|
Can change others PvP state = Peut changer l'état du PvP des autres joueurs
|
||||||
|
You cannot change other players PvP state unless you have the pvp_admin privilege. = Vous ne pouvez pas changer l'état du PvP des autres joueurs à moins de posséder le privilège pvp_admin.
|
||||||
|
|
|
@ -12,3 +12,6 @@ Disables PvP =
|
||||||
Your PvP is already disabled. =
|
Your PvP is already disabled. =
|
||||||
You can't hit %s because their PvP is disabled. =
|
You can't hit %s because their PvP is disabled. =
|
||||||
You can't hit %s because your PvP is disabled. =
|
You can't hit %s because your PvP is disabled. =
|
||||||
|
Can change own PvP state =
|
||||||
|
Can change others PvP state =
|
||||||
|
You cannot change other players PvP state unless you have the pvp_admin privilege. =
|
||||||
|
|
139
pvp.lua
139
pvp.lua
|
@ -1,12 +1,3 @@
|
||||||
local mod_storage = minetest.get_mod_storage()
|
|
||||||
--[[
|
|
||||||
Mod storage!
|
|
||||||
key = int
|
|
||||||
wher key is the player name, and int is 1 for enabled and 2 for disabled
|
|
||||||
]]
|
|
||||||
|
|
||||||
minetest.register_privilege("pvp", "Can configure own PvP setting")
|
|
||||||
|
|
||||||
-- Private table
|
-- Private table
|
||||||
local pvptable = {}
|
local pvptable = {}
|
||||||
|
|
||||||
|
@ -14,22 +5,36 @@ local pvptable = {}
|
||||||
pvpplus = {}
|
pvpplus = {}
|
||||||
|
|
||||||
local S
|
local S
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
if minetest.get_modpath(
|
S = intllib.Getter()
|
||||||
"intllib"
|
|
||||||
) then
|
|
||||||
S = intllib.Getter(
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
S = function(
|
S = function(translated)
|
||||||
translated
|
|
||||||
)
|
|
||||||
return translated
|
return translated
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_pvp_hud(player, state)
|
minetest.register_privilege("pvp", S("Can change own PvP state"))
|
||||||
local player_name = player:get_player_name()
|
minetest.register_privilege("pvp_admin", S("Can change others PvP state"))
|
||||||
|
|
||||||
|
function pvpplus.pvp_set(player_name, state)
|
||||||
|
if pvpplus.is_playing_tournament(player_name) then
|
||||||
|
return false, S("PvP state cannot be changed while playing a tournament.")
|
||||||
|
end
|
||||||
|
if type(state) ~= "boolean" then
|
||||||
|
return false, S("The state parameter has to be a boolean.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local player = minetest.get_player_by_name(player_name)
|
||||||
|
if not player then
|
||||||
|
return false, string.format(S("Player %s does not exist or is not currently connected."), player_name)
|
||||||
|
end
|
||||||
|
pvptable[player_name].state = state
|
||||||
|
|
||||||
|
minetest.chat_send_player(player_name, ((state and S("Your PvP has been enabled")) or S("Your PvP has been disabled")))
|
||||||
|
|
||||||
|
player:hud_remove((state and pvptable[player_name].pvpdisabled) or pvptable[player_name].pvpenabled)
|
||||||
|
player:hud_remove((state and pvptable[player_name].nopvppic) or pvptable[player_name].pvppic)
|
||||||
|
|
||||||
if state then
|
if state then
|
||||||
pvptable[player_name].pvpenabled = player:hud_add({
|
pvptable[player_name].pvpenabled = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
|
@ -63,29 +68,6 @@ local function add_pvp_hud(player, state)
|
||||||
text = "nopvp.png"
|
text = "nopvp.png"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function pvpplus.pvp_set(player_name, state)
|
|
||||||
if pvpplus.is_playing_tournament(player_name) then
|
|
||||||
return false, S("PvP state cannot be changed while playing a tournament.")
|
|
||||||
end
|
|
||||||
if type(state) ~= "boolean" then
|
|
||||||
return false, S("The state parameter has to be a boolean.")
|
|
||||||
end
|
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(player_name)
|
|
||||||
if not player then
|
|
||||||
return false, string.format(S("Player %s does not exist or is not currently connected."), player_name)
|
|
||||||
end
|
|
||||||
pvptable[player_name].state = state
|
|
||||||
mod_storage:set_int(player_name, state and 1 or 2)
|
|
||||||
|
|
||||||
minetest.chat_send_player(player_name, ((state and S("Your PvP has been enabled")) or S("Your PvP has been disabled")))
|
|
||||||
|
|
||||||
player:hud_remove((state and pvptable[player_name].pvpdisabled) or pvptable[player_name].pvpenabled)
|
|
||||||
player:hud_remove((state and pvptable[player_name].nopvppic) or pvptable[player_name].pvppic)
|
|
||||||
|
|
||||||
add_pvp_hud(player, state)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -107,49 +89,13 @@ function pvpplus.pvp_toggle(playername)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pvpplus.is_pvp(playername)
|
function pvpplus.is_pvp(playername)
|
||||||
|
if not pvptable[playername] then
|
||||||
|
return false, string.format(S("Player %s does not exist or is not currently connected."), playername)
|
||||||
|
end
|
||||||
return pvptable[playername].state or false
|
return pvptable[playername].state or false
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_modpath("unified_inventory") then
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/pvp_commands.lua")
|
||||||
unified_inventory.register_button("pvp", {
|
|
||||||
type = "image",
|
|
||||||
image = "pvp.png",
|
|
||||||
tooltip = "PvP",
|
|
||||||
condition = function(player)
|
|
||||||
return minetest.check_player_privs(player, "pvp")
|
|
||||||
end,
|
|
||||||
action = function(player)
|
|
||||||
pvpplus.pvp_toggle(player:get_player_name())
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_chatcommand("pvp_enable", {
|
|
||||||
params = "",
|
|
||||||
description = S("Enables PvP"),
|
|
||||||
privs = {
|
|
||||||
pvp = true
|
|
||||||
},
|
|
||||||
func = function(name, param)
|
|
||||||
if pvpplus.is_pvp(name) then
|
|
||||||
return false, S("Your PvP is already enabled.")
|
|
||||||
end
|
|
||||||
return pvpplus.pvp_enable(name)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
minetest.register_chatcommand("pvp_disable", {
|
|
||||||
params = "",
|
|
||||||
description = S("Disables PvP"),
|
|
||||||
privs = {
|
|
||||||
pvp = true
|
|
||||||
},
|
|
||||||
func = function(name, param)
|
|
||||||
if not pvpplus.is_pvp(name) then
|
|
||||||
return false, S("Your PvP is already disabled.")
|
|
||||||
end
|
|
||||||
return pvpplus.pvp_disable(name)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
------ Load tournaments ------
|
------ Load tournaments ------
|
||||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/tournament.lua")
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/tournament.lua")
|
||||||
|
@ -162,16 +108,23 @@ pvpplus.tournament_on_punchplayer = nil
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local state = mod_storage:get_int(player:get_player_name())
|
pvptable[name] = {state = false}
|
||||||
if state == 0 then
|
pvptable[name].nopvppic = player:hud_add({
|
||||||
state = minetest.settings:get_bool("pvpplus.default_pvp_state") or false
|
hud_elem_type = "image",
|
||||||
else
|
position = {x = 1, y = 0},
|
||||||
state = state == 1
|
offset = {x = -210, y = 20},
|
||||||
end
|
scale = {x = 1, y = 1},
|
||||||
|
text = "nopvp.png"
|
||||||
|
})
|
||||||
|
|
||||||
pvptable[name] = {state = state}
|
pvptable[name].pvpdisabled = player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
add_pvp_hud(player, state)
|
position = {x = 1, y = 0},
|
||||||
|
offset = {x=-125, y = 20},
|
||||||
|
scale = {x = 100, y = 100},
|
||||||
|
text = S("PvP is disabled for you!"),
|
||||||
|
number = 0x7DC435
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
@ -189,7 +142,7 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if not pvptable[hittername].state then
|
if not pvptable[hittername].state then
|
||||||
minetest.chat_send_player(hittername, string.format(S("You can't hit %s because your PvP is disabled."), hittername))
|
minetest.chat_send_player(hittername, string.format(S("You can't hit %s because your PvP is disabled."), localname))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
local S
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
S = intllib.Getter()
|
||||||
|
else
|
||||||
|
S = function(translated)
|
||||||
|
return translated
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.get_modpath("unified_inventory") then
|
||||||
|
unified_inventory.register_button("pvp", {
|
||||||
|
type = "image",
|
||||||
|
image = "pvp.png",
|
||||||
|
tooltip = "PvP",
|
||||||
|
condition = function(player)
|
||||||
|
return minetest.check_player_privs(player, "pvp")
|
||||||
|
end,
|
||||||
|
action = function(player)
|
||||||
|
pvpplus.pvp_toggle(player:get_player_name())
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("pvp_enable", {
|
||||||
|
params = "[<player>]",
|
||||||
|
description = S("Enables PvP"),
|
||||||
|
privs = {
|
||||||
|
pvp = true
|
||||||
|
},
|
||||||
|
func = function(name, param)
|
||||||
|
if param ~= "" then
|
||||||
|
if not minetest.check_player_privs(name, "pvp_admin") then
|
||||||
|
return false, S("You cannot change other players PvP state unless you have the pvp_admin privilege.")
|
||||||
|
end
|
||||||
|
name = param
|
||||||
|
end
|
||||||
|
if pvpplus.is_pvp(name) then
|
||||||
|
return false, S("Your PvP is already enabled.")
|
||||||
|
end
|
||||||
|
return pvpplus.pvp_enable(name)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
minetest.register_chatcommand("pvp_disable", {
|
||||||
|
params = "",
|
||||||
|
description = S("Disables PvP"),
|
||||||
|
privs = {
|
||||||
|
pvp = true
|
||||||
|
},
|
||||||
|
func = function(name, param)
|
||||||
|
if param ~= "" then
|
||||||
|
if not minetest.check_player_privs(name, "pvp_admin") then
|
||||||
|
return false, S("You cannot change other players PvP state unless you have the pvp_admin privilege.")
|
||||||
|
end
|
||||||
|
name = param
|
||||||
|
end
|
||||||
|
if not pvpplus.is_pvp(name) then
|
||||||
|
return false, S("Your PvP is already disabled.")
|
||||||
|
end
|
||||||
|
return pvpplus.pvp_disable(name)
|
||||||
|
end
|
||||||
|
})
|
Loading…
Reference in New Issue