Better error handling
parent
ed9a328f45
commit
021092dcb2
|
@ -34,6 +34,7 @@ pvpplus.is_pvp(player_name)
|
|||
-- PvP tournaments:
|
||||
pvpplus.engage_player(player_name) -- Engage a player for the next tournament
|
||||
pvpplus.is_engaged(player_name) -- Is this player engaged for the next tournament ?
|
||||
pvpplus.is_engaging_players() -- Is there an open tournament ?
|
||||
pvpplus.start_tournament(starter_name) -- Start a tournament (at least 2 players have to be engaged)
|
||||
pvpplus.start_global_tournament(starter_name) -- Start a tournament engaging every connected players
|
||||
pvpplus.stop_tournament() -- Stop the current tournament
|
||||
|
|
|
@ -17,6 +17,9 @@ local tournament = {
|
|||
}
|
||||
|
||||
function pvpplus.engage_player(player_name)
|
||||
if not tournament.engaging_players then
|
||||
return false, "There is no open tournament."
|
||||
end
|
||||
tournament.engaged_players[player_name] = true
|
||||
minetest.chat_send_player(player_name, "You have been engaged for a PvP tournament!")
|
||||
|
||||
|
@ -45,6 +48,10 @@ function pvpplus.is_engaged(player_name)
|
|||
end
|
||||
end
|
||||
|
||||
function pvpplus.is_engaging_players()
|
||||
return tournament.engaging_players
|
||||
end
|
||||
|
||||
function pvpplus.start_tournament(starter_name)
|
||||
if tournament.running_tournament then
|
||||
minetest.chat_send_player(starter_name, "There is already a running tournament.")
|
||||
|
@ -218,6 +225,12 @@ function pvpplus.stop_tournament()
|
|||
end
|
||||
|
||||
function pvpplus.allow_engaging(starter_name, teleport)
|
||||
if tournament.engaging_players then
|
||||
return false, "There is already an open tournament."
|
||||
end
|
||||
if tournament.is_running_tournament then
|
||||
return false, "There is already a running tournament."
|
||||
end
|
||||
tournament.engaging_players = true
|
||||
minetest.chat_send_all(starter_name .. " opened a tournament! Type /engage to engage yourself in the tournament!")
|
||||
if teleport then
|
||||
|
@ -226,6 +239,7 @@ function pvpplus.allow_engaging(starter_name, teleport)
|
|||
minetest.sound_play("pvpplus_tournament_start", {
|
||||
gain = 1.0,
|
||||
})
|
||||
return true
|
||||
end
|
||||
|
||||
function pvpplus.teleport_engaged_players()
|
||||
|
@ -426,16 +440,15 @@ minetest.register_chatcommand("tournament", {
|
|||
end
|
||||
end
|
||||
|
||||
if pvpplus.is_running_tournament() then
|
||||
return false, "There is already a running tournament."
|
||||
end
|
||||
|
||||
if starting_time < 10 or starting_time > 600 then
|
||||
return false, "Please set a starting time between 10s and 600s."
|
||||
end
|
||||
|
||||
-- Allow engaging
|
||||
pvpplus.allow_engaging(name, teleport)
|
||||
local e, m = pvpplus.allow_engaging(name, teleport)
|
||||
if e == false then
|
||||
return false, m
|
||||
end
|
||||
|
||||
-- Engage starter
|
||||
pvpplus.engage_player(name)
|
||||
|
|
Loading…
Reference in New Issue