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
|
||||
|
||||
* `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
|
||||
|
||||
|
|
|
@ -12,3 +12,6 @@ Disables PvP = Désactive le PvP
|
|||
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 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. =
|
||||
You can't hit %s because their 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
|
||||
local pvptable = {}
|
||||
|
||||
|
@ -14,22 +5,36 @@ local pvptable = {}
|
|||
pvpplus = {}
|
||||
|
||||
local S
|
||||
|
||||
if minetest.get_modpath(
|
||||
"intllib"
|
||||
) then
|
||||
S = intllib.Getter(
|
||||
)
|
||||
if minetest.get_modpath("intllib") then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
S = function(
|
||||
translated
|
||||
)
|
||||
S = function(translated)
|
||||
return translated
|
||||
end
|
||||
end
|
||||
|
||||
local function add_pvp_hud(player, state)
|
||||
local player_name = player:get_player_name()
|
||||
minetest.register_privilege("pvp", S("Can change own PvP state"))
|
||||
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
|
||||
pvptable[player_name].pvpenabled = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
|
@ -63,29 +68,6 @@ local function add_pvp_hud(player, state)
|
|||
text = "nopvp.png"
|
||||
})
|
||||
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
|
||||
end
|
||||
|
@ -107,49 +89,13 @@ function pvpplus.pvp_toggle(playername)
|
|||
end
|
||||
|
||||
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
|
||||
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 = "",
|
||||
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
|
||||
})
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/pvp_commands.lua")
|
||||
|
||||
------ Load tournaments ------
|
||||
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)
|
||||
local name = player:get_player_name()
|
||||
local state = mod_storage:get_int(player:get_player_name())
|
||||
if state == 0 then
|
||||
state = minetest.settings:get_bool("pvpplus.default_pvp_state") or false
|
||||
else
|
||||
state = state == 1
|
||||
end
|
||||
pvptable[name] = {state = false}
|
||||
pvptable[name].nopvppic = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = -210, y = 20},
|
||||
scale = {x = 1, y = 1},
|
||||
text = "nopvp.png"
|
||||
})
|
||||
|
||||
pvptable[name] = {state = state}
|
||||
|
||||
add_pvp_hud(player, state)
|
||||
pvptable[name].pvpdisabled = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
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)
|
||||
|
||||
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
|
||||
end
|
||||
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
|
||||
end
|
||||
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