Add chatcommands /pvp_enable and /pvp_disable

master
upsilon 2017-04-16 17:03:12 +02:00
parent 4fbf2a8738
commit 2d98ac9a33
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
3 changed files with 36 additions and 12 deletions

View File

@ -5,7 +5,7 @@ Some code and images are from the PvP-Button Mod by Phiwari123.
## Usage
PvP can be enabled/disabled from the inventory.
PvP can be enabled/disabled from the inventory, or using the commands `/pvp_enable` and `/pvp_disable`.
A new tournament can be initiated by a player by typing /tournament.
Then, each playing wanting to play in the tournament has to type /engage during the next minute (this delay is customizable using the `pvpplus.tournament_starting_time` setting, specified in seconds).
@ -56,7 +56,6 @@ pvpplus.tournament_hud_update_all() -- Update the list and all player HUDs
## TODO
* Add a privilege for changing PvP state
* Make the dependence to unified_inventory optional by adding chat commands to change PvP state
* Add a formspec for managing tournaments, accessible from the inventory
* Testing

View File

@ -1,2 +1,2 @@
unified_inventory
unified_inventory?
bones?

43
pvp.lua
View File

@ -77,16 +77,41 @@ function pvpplus.is_pvp(playername)
return pvptable[playername].state or false
end
unified_inventory.register_button("pvp", {
type = "image",
image = "pvp.png",
action = function(player)
local player_name = player:get_player_name()
if pvpplus.is_playing_tournament(player_name) then
minetest.chat_send_player(player_name, "PvP state cannot be changed while playing a tournament.")
else
pvpplus.pvp_toggle(player_name)
if minetest.get_modpath("unified_inventory") then
unified_inventory.register_button("pvp", {
type = "image",
image = "pvp.png",
action = function(player)
local player_name = player:get_player_name()
if pvpplus.is_playing_tournament(player_name) then
minetest.chat_send_player(player_name, "PvP state cannot be changed while playing a tournament.")
else
pvpplus.pvp_toggle(player_name)
end
end
})
end
minetest.register_chatcommand("pvp_enable", {
params = "",
description = "Enables PvP",
privs = {},
func = function(name, param)
if pvpplus.is_pvp(name) then
return false, "Your PvP is already enabled."
end
return pvpplus.pvp_enable(name)
end
})
minetest.register_chatcommand("pvp_disable", {
params = "",
description = "Disables PvP",
privs = {},
func = function(name, param)
if not pvpplus.is_pvp(name) then
return false, "Your PvP is already disabled."
end
return pvpplus.pvp_disable(name)
end
})