finish leaderboard

master
MisterE123 2022-05-01 01:32:44 -04:00
parent 8471949848
commit cd5e84b3d7
4 changed files with 60 additions and 61 deletions

View File

@ -84,7 +84,7 @@ local balloon = {
return
end
end
if minetest.find_node_near(self.object:get_pos(), 1.5, {"balloon_bop:spike"}) then
-- pop balloon harmlessly
minetest.sound_play("balloon_pop", {

View File

@ -29,36 +29,35 @@ balloon_bop.scores = balloon_bop.get_scores() or {}
function balloon_bop.get_leader_form(arena_name)
function balloon_bop.get_leader_form(arena_name,sel_idx)
local p_names = "<no data>"
local scores = "<no data>"
sel_idx = sel_idx or 1
if balloon_bop.scores[arena_name] then
-- sort the scores
local ordered_names = {}
local data = balloon_bop.scores[arena_name]
-- sort the scores
for p_name,score in pairs(data) do
if ordered_names == {} then
table.insert(ordered_names,p_name)
else
for idx,o_name in ipairs(ordered_names) do
if score >= data[o_name] then
table.insert(ordered_names,idx,p_name)
end
end
end
table.insert(ordered_names,p_name)
end
table.sort(ordered_names,function(a,b)
if balloon_bop.scores[arena_name][a] > balloon_bop.scores[arena_name][b] then return true else return false end
end)
if #ordered_names >=1 then
p_names = ""
scores = ""
for idx,u_name in ipairs(ordered_names) do
for idx,u_name in ipairs(ordered_names) do
local scorestr = tostring(data[u_name])
local scorelen = string.len(scorestr)
p_names = p_names .. scorestr
for i = 1, 20-scorelen do
p_names = p_names .. " "
end
p_names = p_names .. u_name
scores = scores .. tostring(data[u_name])
if idx ~= #ordered_names then
p_names = p_names .. ","
scores = scores .. ","
end
end
end
@ -67,80 +66,78 @@ function balloon_bop.get_leader_form(arena_name)
return "formspec_version[5]"..
"size[10.5,10.5]"..
"background9[-.5,-.5;11.5,11.5;balloon_bop_leader_bg.png;false;125]"..
"style_type[button,textlist;border=false;textcolor=#302C2E;font=normal,bold]"..
"style[hs_title;font_size=+3]"..
"button[0.6,0.6;9.3,0.8;hs_title;Balloon Bop Leaderboard]"..
"button[0.6,1.4;9.3,0.8;arena_name;<arena>]"..
"textlist[0.6,2.5;7.6,7.4;names;"..p_names..";1;false]"..
"textlist[8.3,2.5;1.6,7.4;scores;"..scores..";1;false]"
"button[0.6,1.6;9.3,0.8;arena_name;"..arena_name.."]"..
"textlist[0.6,2.5;9.3,7.4;names;"..p_names..";"..sel_idx..";true]"
end
function balloon_bop.get_leader_form_endgame(arena_name,l_data)
function balloon_bop.get_leader_form_endgame(arena_name,l_data,sel_idx,sel_idx2)
sel_idx = sel_idx or 1
sel_idx2 = sel_idx2 or 1
local p_names = "<no data>"
local scores = "<no data>"
local lp_names = "<no data>"
local lscores = "<no data>"
if balloon_bop.scores[arena_name] then
local ordered_names = {}
local data = balloon_bop.scores[arena_name]
-- sort the scores
for p_name,score in pairs(data) do
if ordered_names == {} then
table.insert(ordered_names,p_name)
else
for idx,o_name in ipairs(ordered_names) do
if score >= data[o_name] then
table.insert(ordered_names,idx,p_name)
end
end
end
table.insert(ordered_names,p_name)
end
table.sort(ordered_names,function(a,b)
if balloon_bop.scores[arena_name][a] > balloon_bop.scores[arena_name][b] then return true else return false end
end)
if #ordered_names >=1 then
p_names = ""
scores = ""
for idx,u_name in ipairs(ordered_names) do
for idx,u_name in ipairs(ordered_names) do
local scorestr = tostring(data[u_name])
local scorelen = string.len(scorestr)
p_names = p_names .. scorestr
for i = 1, 20-scorelen do
p_names = p_names .. " "
end
p_names = p_names .. u_name
scores = scores .. tostring(data[u_name])
if idx ~= #ordered_names then
p_names = p_names .. ","
scores = scores .. ","
end
end
end
end
if l_data then
local ordered_names = {}
local data = l_data
-- sort the scores
for p_name,score in pairs(data) do
if ordered_names == {} then
table.insert(ordered_names,p_name)
else
for idx,o_name in ipairs(ordered_names) do
if score >= data[o_name] then
table.insert(ordered_names,idx,p_name)
end
end
end
table.insert(ordered_names,p_name)
end
table.sort(ordered_names,function(a,b)
if balloon_bop.scores[arena_name][a] > balloon_bop.scores[arena_name][b] then return true else return false end
end)
if #ordered_names >=1 then
lp_names = ""
lscores = ""
for idx,u_name in ipairs(ordered_names) do
for idx,u_name in ipairs(ordered_names) do
local scorestr = tostring(data[u_name])
local scorelen = string.len(scorestr)
lp_names = lp_names .. scorestr
for i = 1, 20-scorelen do
lp_names = lp_names .. " "
end
lp_names = lp_names .. u_name
scores = scores .. tostring(data[u_name])
if idx ~= #ordered_names then
lp_names = lp_names .. ","
lscores = lscores .. ","
end
end
end
@ -149,13 +146,14 @@ function balloon_bop.get_leader_form_endgame(arena_name,l_data)
return "formspec_version[5]"..
"size[10.5,10.5]"..
"background9[-.5,-.5;11.5,11.5;balloon_bop_leader_bg.png;false;125]"..
"style_type[button,textlist;border=false;textcolor=#302C2E;font=normal,bold]"..
"style[hs_title;font_size=+3]"..
"button[0.6,0.6;9.3,0.8;hs_title;Balloon Bop Leaderboard]"..
"button[0.6,1.4;9.3,0.8;arena_name;<arena>]"..
"button[0.6,1.4;9.3,0.8;arena_name;<arena>]"..
"textlist[0.6,6.1;7.3,3.8;g_names;"..p_names..";1;false]"..
"textlist[8,6.1;1.9,3.8;g_scores;"..scores..";1;false]"..
"textlist[0.6,3.3;7.3,2;l_names;"..lp_names..";1;false]"..
"textlist[8,3.3;1.9,2;l_scores;"..lscores..";1;false]"..
"button[0.6,1.6;9.3,0.8;arena_name;"..arena_name.."]"..
"style_type[button,textlist;border=false;textcolor=#CFC6B8;font=normal,bold]"..
"textlist[0.6,6.1;9.3,3.8;g_names;"..p_names..";"..sel_idx..";true]"..
"textlist[0.6,3.3;9.3,2;l_names;"..lp_names..";"..sel_idx2..";true]"..
"button[0.6,2.7;9.3,0.6;this;This Game]"..
"button[0.6,5.5;9.3,0.6;high;LeaderBoard]"
end
@ -170,7 +168,7 @@ minetest.register_chatcommand("balloonbopscores", {
func = function(name, param)
if param then
if balloon_bop.scores[param] then
minetest.show_formspec(name, "bb_scores", balloon_bop.get_leader_form(balloon_bop.scores[param]))
minetest.show_formspec(name, "bb_scores", balloon_bop.get_leader_form(param))
else
return false, "[!] No data for that arena or that arena does not exist!"
end

View File

@ -14,12 +14,12 @@ arena_lib.on_time_tick("balloon_bop", function(arena)
arena_lib.HUD_send_msg_all("broadcast", arena, arena.num_balloons .. " balloons!", 1, nil, "0xB6D53C")
end
for pl_name,stats in pairs(arena.players) do -- it is a good convention to use "pl_name" in for loops and "p_name" elsewhere
local player = minetest.get_player_by_name( pl_name )
if player then
-- handle player "fall death"
local pos = player:get_pos()
local pos = player:get_pos()
if pos.y < arena.player_die_level then
player:set_pos(arena_lib.get_random_spawner(arena))
end
@ -52,7 +52,7 @@ arena_lib.on_time_tick("balloon_bop", function(arena)
obj:remove()
-- deduct 20 points from everyone for letting a balloon touch!
for pl_name,stats in pairs(arena.players) do
arena.players[pl_name].score = arena.players[pl_name].score+1
arena.players[pl_name].score = arena.players[pl_name].score-20
if arena.players[pl_name].score < 0 then arena.players[pl_name].score = 0 end
end
arena.arena_lives = arena.arena_lives - 1
@ -116,7 +116,8 @@ arena_lib.on_time_tick("balloon_bop", function(arena)
end
balloon_bop.store_scores(balloon_bop.scores)
for pl_name,stats in pairs(arena.players) do
minetest.show_formspec(pl_name, "bb_scores", balloon_bop.get_leader_form_endgame(balloon_bop.scores[arena.name],l_data))
minetest.show_formspec(pl_name, "bb_scores_mp", balloon_bop.get_leader_form_endgame(arena.name,l_data))
-- minetest.debug(dump(l_data))
end
if count > 1 then -- we cannot have more than one winner

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB