Bugfix: timers didn't work

This commit is contained in:
Zughy 2020-09-19 17:06:56 +02:00
parent 2b6230ce34
commit aaeb616135
3 changed files with 37 additions and 21 deletions

13
DOCS.md
View File

@ -8,11 +8,12 @@ An arena is a table having as a key an ID and as a value its parameters. They ar
* `name`: (string) the name of the arena, declared when creating it
* `sign`: (pos) the position of the sign associated with the arena.
* `players`: (table) where to store players
* `teams`: (table) where to store teams. If there are none, is {-1}
* `teams`: (table) where to store teams. If there are none, it's {-1}
* `teams_enabled`: (boolean) whether teams are enabled in the arena. Requires teams
* `players_amount`: (int) separately stores how many players are inside the arena/queue
* `max_players`: (string) default is 4. When this value is reached, queue time decreases to 5 if it's not lower already
* `min_players`: (string) default is 2. When this value is reached, a queue starts
* `timer`: (int) default is nil, but it can be changed as we'll see in a moment
* `in_queue`: (bool) about phases, look at "Arena phases" down below
* `in_loading`: (bool)
* `in_game`: (bool)
@ -66,11 +67,14 @@ If you don't want to rely on the hotbar, or you want both the editor and the com
##### 1.2.2.2 Enabling/Disabling teams
`arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable)` enables/disables teams per single arena. `enable` is an int, where 0 disables teams and 1 enables them.
##### 1.2.2.3 Arenas properties
##### 1.2.2.3 Timer
`arena_lib.set_timer(sender, mod, arena_name, timer)` changes the timer of the arena. If `timer` is -1, it'll be disabled and set to `nil`.
##### 1.2.2.4 Arenas properties
Properties are explained down below, but essentially they allow you to create additional attributes specifically suited for what you have in mind (e.g. a score to reach to win the game).
`arena_lib.change_arena_property(sender, mod, arena_name, property, new_value)` changes the specified arena property with `new_value`. Keep in mind you can't change a property type (a number must remain a number, a string a string etc), and strings need quotes surrounding them - so `false` is a boolean, but `"false"` is a string. Also, this works for *arena* properties only. Not for temporary, players, nor team ones.
##### 1.2.2.4 Spawners
##### 1.2.2.5 Spawners
`arena_lib.set_spawner(sender, mod, arena_name, <teamID_or_name>, <param>, <ID>)` creates a spawner where the sender is standing, so be sure to stand where you want the spawn point to be.
* `teamID_or_name` can be both a string and a number. It must be specified if your arena uses teams
* `param` is a string, specifically "overwrite", "delete" or "deleteall". "deleteall" aside, the other ones need an ID after them. Also, if a team is specified with deleteall, it will only delete the spawners belonging to that team
@ -161,8 +165,7 @@ The second field, on the contrary, is a table of parameters: they define the ver
* `keep_inventory`: whether to keep players inventories when joining an arena. Default is false
* `show_nametags`: whether to show the players nametags while in game. Default is false
* `show_minimap`: whether to allow players to use the builtin minimap function. Default is false
* `timer`: an eventual timer, in seconds. Default is -1, meaning it's disabled
* `is_timer_incrementing`: whether the timer decreases as in a countdown or increases as in a stopwatch. It doesn't work if timer is -1. Default is false
* `is_timer_incrementing`: whether arenas' timers decrease as in a countdown or increase as in a stopwatch. Default is false
* `queue_waiting_time`: the time to wait before the loading phase starts. It gets triggered when the minimium amount of players has been reached to start the queue. Default is 10
* `load_time`: the time between the loading state and the start of the match. Default is 3
* `celebration_time`: the time between the celebration state and the end of the match. Default is 3

41
api.lua
View File

@ -82,7 +82,6 @@ function arena_lib.register_minigame(mod, def)
mod_ref.keep_inventory = false
mod_ref.show_nametags = false
mod_ref.show_minimap = false
mod_ref.timer = -1
mod_ref.is_timer_incrementing = false
mod_ref.queue_waiting_time = 10
mod_ref.load_time = 3 -- time in the loading phase (the pre-match)
@ -150,11 +149,8 @@ function arena_lib.register_minigame(mod, def)
mod_ref.show_minimap = def.show_minimap
end
if def.timer then
mod_ref.timer = def.timer
if def.is_timer_incrementing == true then
mod_ref.is_timer_incrementing = true
end
if def.is_timer_incrementing == true then
mod_ref.is_timer_incrementing = true
end
if def.queue_waiting_time then
@ -727,6 +723,28 @@ end
function arena_lib.set_timer(sender, mod, arena_name, timer, in_editor)
local arena_ID, arena = arena_lib.get_arena_by_name(mod, arena_name)
if not in_editor then
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
end
local mod_ref = arena_lib.mods[mod]
-- se è da disabilitare
if timer == -1 then
arena.timer = nil
minetest.chat_send_player(sender, mod_ref.prefix .. S("Arena @1's timer successfully disabled", arena_name))
else
arena.timer = timer
minetest.chat_send_player(sender, mod_ref.prefix .. S("Arena @1's timer is now @2s", arena_name, timer))
end
end
function arena_lib.enable_arena(sender, mod, arena_name, in_editor)
local arena_ID, arena = arena_lib.get_arena_by_name(mod, arena_name)
@ -963,7 +981,7 @@ function arena_lib.start_arena(mod_ref, arena)
end
-- parte l'eventuale timer
if mod_ref.timer ~= -1 then
if arena.timer then
arena.timer_current = arena.timer
minetest.after(1, function()
timer_start(mod_ref, arena)
@ -1714,13 +1732,6 @@ function init_storage(mod, mod_ref)
" has been reset due to not coinciding with the maximum amount of players (" .. arena_max_players .. ")")
end
-- gestione timer
if mod_ref.timer == -1 and arena.timer then -- se avevo abilitato i timer e ora li ho rimossi, li tolgo dalle arene
arena.timer = nil
elseif mod_ref.timer ~= -1 and not arena.timer then -- se li ho abilitati ora e le arene non ce li hanno, glieli aggiungo
arena.timer = mod_ref.timer
end
arena_lib.mods[mod].arenas[i] = arena
if to_update then
@ -1902,6 +1913,8 @@ function timer_start(mod_ref, arena)
if arena.on_celebration then return end
minetest.chat_send_player("singleplayer", arena.timer_current)
if mod_ref.is_timer_incrementing then
arena.timer_current = arena.timer_current + 1
else

View File

@ -109,9 +109,9 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
local timer = ""
if arena.timer then
if arena.timer_current then
timer = S("Timer: ") .. arena.timer .. " (" .. S("current: ") .. arena.timer_current .. ")\n"
timer = minetest.colorize("#eea160", S("Timer: ")) .. minetest.colorize("#cfc6b8", arena.timer .. " (" .. S("current: ") .. arena.timer_current .. ")") .. "\n"
else
timer = S("Timer: ") .. arena.timer .. " (" .. S("current: ") .. "--- )\n"
timer = minetest.colorize("#eea160", S("Timer: ")) .. minetest.colorize("#cfc6b8", arena.timer .. " (" .. S("current: ") .. " --- )") .. "\n"
end
end