add leaderboard
This commit is contained in:
parent
f0984828e5
commit
8e507f453a
8
init.lua
8
init.lua
@ -1,6 +1,9 @@
|
|||||||
wormball = {}
|
wormball = {}
|
||||||
wormball.HUD = {}
|
wormball.HUD = {}
|
||||||
dofile(minetest.get_modpath("wormball") .. "/globals.lua")
|
dofile(minetest.get_modpath("wormball") .. "/globals.lua")
|
||||||
|
wormball.storage = minetest.get_mod_storage()
|
||||||
|
wormball.arenas = {}
|
||||||
|
|
||||||
|
|
||||||
arena_lib.register_minigame("wormball", {
|
arena_lib.register_minigame("wormball", {
|
||||||
prefix = "[Wormball] ",
|
prefix = "[Wormball] ",
|
||||||
@ -33,6 +36,8 @@ dofile(minetest.get_modpath("wormball") .. "/globals.lua")
|
|||||||
min_food_factor = 2,
|
min_food_factor = 2,
|
||||||
min_food = 20,
|
min_food = 20,
|
||||||
singleplayer_leaderboard = {},
|
singleplayer_leaderboard = {},
|
||||||
|
multi_scores = {},
|
||||||
|
|
||||||
-- highscores = {
|
-- highscores = {
|
||||||
-- {'pl_name_placeholder',0},
|
-- {'pl_name_placeholder',0},
|
||||||
-- {'pl_name_placeholder',0},
|
-- {'pl_name_placeholder',0},
|
||||||
@ -48,11 +53,12 @@ dofile(minetest.get_modpath("wormball") .. "/globals.lua")
|
|||||||
-- },
|
-- },
|
||||||
},
|
},
|
||||||
temp_properties = {
|
temp_properties = {
|
||||||
|
|
||||||
mode = 'singleplayer',
|
mode = 'singleplayer',
|
||||||
dots = {},
|
dots = {},
|
||||||
num_players = 0,
|
num_players = 0,
|
||||||
time_to_next_elim = 60,
|
time_to_next_elim = 60,
|
||||||
multi_scores = {},
|
|
||||||
},
|
},
|
||||||
initial_time = 300,
|
initial_time = 300,
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
-- scoreboards
|
-- scoreboards
|
||||||
local storage = minetest.get_mod_storage()
|
local storage = wormball.storage
|
||||||
|
|
||||||
wormball.show_multi_scores = function( arena , player , scores )
|
wormball.show_multi_scores = function( arena , player , scores )
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ wormball.show_singleplayer_leaderboard = function( arena_name , playername )
|
|||||||
if not arena_lib.get_arena_by_name('wormball', arena_name ) then return false end
|
if not arena_lib.get_arena_by_name('wormball', arena_name ) then return false end
|
||||||
local arena_id, arena = arena_lib.get_arena_by_name('wormball', arena_name )
|
local arena_id, arena = arena_lib.get_arena_by_name('wormball', arena_name )
|
||||||
local leaderboard = arena.singleplayer_leaderboard
|
local leaderboard = arena.singleplayer_leaderboard
|
||||||
--minetest.chat_send_all(dump(arena))
|
--minetest.chat_send_all(dump(arena.singleplayer_leaderboard))
|
||||||
local player_list = ""
|
local player_list = ""
|
||||||
|
|
||||||
if not leaderboard or not leaderboard[1] then return end
|
if not leaderboard or not leaderboard[1] then return end
|
||||||
@ -198,19 +198,14 @@ arena_lib.on_celebration('wormball', function(arena, winner_name)
|
|||||||
|
|
||||||
--arena_lib.change_arena_property(winner_name, 'wormball', arena.name, "singleplayer_leaderboard", leaderboard)
|
--arena_lib.change_arena_property(winner_name, 'wormball', arena.name, "singleplayer_leaderboard", leaderboard)
|
||||||
|
|
||||||
-- arena_lib.change_arena_property('wormball' , 'wormball' , arena.name , "singleplayer_leaderboard" , leaderboard )
|
--arena_lib.change_arena_property('wormball' , 'wormball' , arena.name , "singleplayer_leaderboard" , leaderboard )
|
||||||
|
|
||||||
--save (update) the highscore data to disk
|
--save (update) the highscore data to disk
|
||||||
local wormball_highscores = storage:get_string("wormball_highscores") or {}
|
arena.singleplayer_leaderboard = leaderboard
|
||||||
if wormball_highscores ~= {} then
|
|
||||||
wormball_highscores = minetest.deserialize(wormball_highscores)
|
local serial = minetest.serialize(arena.singleplayer_leaderboard)
|
||||||
end
|
|
||||||
|
|
||||||
wormball_highscores [ arena.name ] = arena.singleplayer_leaderboard
|
|
||||||
|
|
||||||
local serial = minetest.serialize(wormball_highscores)
|
|
||||||
|
|
||||||
storage:set_string("wormball_highscores", serial)
|
storage:set_string(arena.name .. "_highscores", serial )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local storage = minetest.get_mod_storage()
|
local storage = wormball.storage
|
||||||
|
|
||||||
local function send_message(arena,num_str)
|
local function send_message(arena,num_str)
|
||||||
arena_lib.HUD_send_msg_all("title", arena, "Game Begins In "..num_str, 1,nil,0xFF0000)
|
arena_lib.HUD_send_msg_all("title", arena, "Game Begins In "..num_str, 1,nil,0xFF0000)
|
||||||
-- ref: arena_lib.HUD_send_msg_all(HUD_type, arena, msg, <duration>, <sound>, <color>)
|
-- ref: arena_lib.HUD_send_msg_all(HUD_type, arena, msg, <duration>, <sound>, <color>)
|
||||||
@ -8,18 +9,9 @@ arena_lib.on_load("wormball", function(arena)
|
|||||||
|
|
||||||
-- load the saved highscore data from disk
|
-- load the saved highscore data from disk
|
||||||
|
|
||||||
local wormball_highscores = storage:get_string("wormball_highscores") or {}
|
local wormball_highscores = storage:get_string(arena.name .. "_highscores")
|
||||||
local leaderboard = {}
|
local leaderboard = {}
|
||||||
if wormball_highscores ~= {} then
|
if wormball_highscores then leaderboard = minetest.deserialize( wormball_highscores ) end
|
||||||
wormball_highscores = minetest.deserialize(wormball_highscores)
|
|
||||||
|
|
||||||
local leaderboard = wormball_highscores [ arena.name ]
|
|
||||||
|
|
||||||
if not leaderboard then
|
|
||||||
leaderboard = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
arena.singleplayer_leaderboard = leaderboard
|
arena.singleplayer_leaderboard = leaderboard
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ arena_lib.on_time_tick('wormball', function(arena)
|
|||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
local string = ""
|
local string = ""
|
||||||
if arena.mode == 'singleplayer' then
|
if arena.mode == 'singleplayer' and arena.singleplayer_leaderboard and arena.singleplayer_leaderboard [1] then
|
||||||
local leader = arena.singleplayer_leaderboard[1]
|
local leader = arena.singleplayer_leaderboard[1]
|
||||||
if leader then
|
if leader then
|
||||||
string = "highscore: ".. leader[1] .. "\n"
|
string = "highscore: ".. leader[1] .. "\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user