]> git.lizzy.rs Git - elidragon.git/blob - pvp.lua
Added PvP XP
[elidragon.git] / pvp.lua
1 local C = minetest.get_color_escape_sequence
2
3 function elidragon.add_xp(player, amount)
4         local xp = elidragon.get_xp(player)
5         player:get_meta():set_int("elidragon:xp", xp + amount)
6 end
7
8 function elidragon.get_xp(player)
9         return player:get_meta():get_int("elidragon:xp")
10 end 
11
12 minetest.register_on_dieplayer(function(player, reason)
13         if reason.type == "punch" then
14                 local killer = reason.object
15                 if killer and killer:is_player() and elidragon.get_area_with_tag(killer:get_player_name(), "pvp") then
16                         minetest.chat_send_all(minetest.colorize("#D3FF2A", killer:get_player_name() .. " has killed " .. player:get_player_name() .. " in the PvP area!"))
17                         local earned_xp = math.floor(5 + math.sqrt(elidragon.get_xp(player)))
18                         elidragon.add_xp(killer, earned_xp)
19                         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")) 
20                 end
21         end
22 end) 
23
24 minetest.register_chatcommand("xp", {
25         desc = "View your's or another player's PvP XP",
26         param = "[<player>]",
27         func = function(name, param)
28                 local target = name
29                 if param ~= "" then
30                         target = param
31                 end
32                 local target_ref = minetest.get_player_by_name(name)
33                 if not target_ref then return false, "Player '" .. target .. "' is not online." end
34                 return true, C("#C00D00") .. "Score of " .. target .. ": " .. C("#9AB3FF") .. elidragon.get_xp(target_ref) .. " XP" .. C("#FFFFFF")
35         end
36 })