1 local C = minetest.get_color_escape_sequence
3 function elidragon.get_emtpy_highscore_list()
6 list[i] = {name = "<empty>", score = 0}
11 elidragon.savedata.xp_highscore = elidragon.savedata.xp_highscore or elidragon.get_emtpy_highscore_list()
13 function elidragon.check_for_highscore(player)
14 local list = elidragon.savedata.xp_highscore
15 local name = player:get_player_name()
16 local score = elidragon.get_xp(player)
17 local old_rank, new_rank
18 for i, e in pairs(list) do
19 if e.name == name then
22 if not new_rank and score >= e.score then
28 elseif new_rank == old_rank then
29 list[old_rank].score = score
32 table.remove(list, old_rank)
34 table.remove(list, 10)
36 table.insert(list, new_rank, {name = name, score = score})
37 minetest.chat_send_all(C("#ACF317") .. name .. C("#0064E4") .. " is now rank " .. C("#E4E400") .. new_rank .. C("#0064E4") .. " on the PvP highscore list with " .. C("#E4E400") .. score .. C("#0064E4") .. " XP.")
40 function elidragon.add_xp(player, amount)
41 local xp = elidragon.get_xp(player)
42 player:get_meta():set_int("elidragon:xp", xp + amount)
43 elidragon.check_for_highscore(player)
46 function elidragon.get_xp(player)
47 return player:get_meta():get_int("elidragon:xp")
50 minetest.register_on_dieplayer(function(player, reason)
51 local object = reason.object
52 if not object then return end
54 if object:is_player() then
57 local object_name = object:get_luaentity().name
58 if object_name == "bow:arrow" then
59 local owner = minetest.get_player_by_name(object:get_luaentity().owner or "")
60 if owner and owner:is_player() then
65 if killer and elidragon.get_area_with_tag(killer:get_player_name(), "pvp") then
66 minetest.chat_send_all(minetest.colorize("#D3FF2A", killer:get_player_name() .. " has killed " .. player:get_player_name() .. " in the PvP area!"))
67 local earned_xp = math.floor(5 + math.sqrt(elidragon.get_xp(player)))
68 elidragon.add_xp(killer, earned_xp)
69 minetest.chat_send_player(killer:get_player_name(), C("#00F5FF") .. "You earned " .. C("#C000AC") .. earned_xp .. C("#00F5FF") .. " XP. Use /xp to view your total score." .. C("#FFFFFF"))
73 minetest.register_on_joinplayer(elidragon.check_for_highscore)
75 minetest.register_chatcommand("xp", {
76 desc = "View your's or another player's PvP XP",
78 func = function(name, param)
80 if param and param ~= "" then
83 local target_ref = minetest.get_player_by_name(target)
84 if not target_ref then return false, "Player '" .. target .. "' is not online." end
85 return true, C("#C00D00") .. "Score of " .. target .. ": " .. C("#9AB3FF") .. elidragon.get_xp(target_ref) .. " XP" .. C("#FFFFFF")
89 minetest.register_chatcommand("rankings", {
90 description = "View the PvP highscore list",
92 local msg = C("#07E400") .. "PvP Highscore List:"
93 for i, e in pairs(elidragon.savedata.xp_highscore) do
94 msg = msg .. "\n" .. C("#F4F73C") .. i .. ". " .. C("#3CF7EF") .. e.name .. C("#5DF73C") .. " (" .. e.score .. " XP)"