]> git.lizzy.rs Git - elidragon.git/commitdiff
Added PvP XP
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 23 Jun 2020 10:08:25 +0000 (12:08 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 23 Jun 2020 10:08:25 +0000 (12:08 +0200)
init.lua
pvp.lua [new file with mode: 0644]
tags.lua

index 6bda637e0f772770ad067eab169950c861e31b4e..f6dd430a1881cb76b1d05127c40e5bf19c71f1b6 100755 (executable)
--- a/init.lua
+++ b/init.lua
@@ -1,6 +1,6 @@
 elidragon = {}
 
-local modules = {"functions", "nodes", "commands", "ranks", "tags", "warps", "misc", "birthday", "skyblock", "playerlist", "quests"}
+local modules = {"functions", "nodes", "commands", "ranks", "tags", "warps", "misc", "birthday", "skyblock", "playerlist", "quests", "pvp"}
 
 local modpath = minetest.get_modpath("elidragon")
 
diff --git a/pvp.lua b/pvp.lua
new file mode 100644 (file)
index 0000000..759271b
--- /dev/null
+++ b/pvp.lua
@@ -0,0 +1,36 @@
+local C = minetest.get_color_escape_sequence
+
+function elidragon.add_xp(player, amount)
+       local xp = elidragon.get_xp(player)
+       player:get_meta():set_int("elidragon:xp", xp + amount)
+end
+
+function elidragon.get_xp(player)
+       return player:get_meta():get_int("elidragon:xp")
+end 
+
+minetest.register_on_dieplayer(function(player, reason)
+       if reason.type == "punch" then
+               local killer = reason.object
+               if killer and killer:is_player() and elidragon.get_area_with_tag(killer:get_player_name(), "pvp") then
+                       minetest.chat_send_all(minetest.colorize("#D3FF2A", killer:get_player_name() .. " has killed " .. player:get_player_name() .. " in the PvP area!"))
+                       local earned_xp = math.floor(5 + math.sqrt(elidragon.get_xp(player)))
+                       elidragon.add_xp(killer, earned_xp)
+                       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")) 
+               end
+       end
+end) 
+
+minetest.register_chatcommand("xp", {
+       desc = "View your's or another player's PvP XP",
+       param = "[<player>]",
+       func = function(name, param)
+               local target = name
+               if param ~= "" then
+                       target = param
+               end
+               local target_ref = minetest.get_player_by_name(name)
+               if not target_ref then return false, "Player '" .. target .. "' is not online." end
+               return true, C("#C00D00") .. "Score of " .. target .. ": " .. C("#9AB3FF") .. elidragon.get_xp(target_ref) .. " XP" .. C("#FFFFFF")
+       end
+})
index b2d57af4ee8a041c2cff15a844a86c09be3ebe9b..19db90d8ba5ef23aa704b0fed9e26edd8503faae 100755 (executable)
--- a/tags.lua
+++ b/tags.lua
@@ -108,13 +108,6 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
                return true
        end
 end)
-minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
-       if elidragon.get_area_with_tag(player:get_player_name(), "pvp") then
-               if player:get_hp() - damage < 0 and player:get_hp() <= 0 then
-            minetest.chat_send_all(minetest.colorize("#D3FF2A", hitter:get_player_name() .. " has killed " .. player:get_player_name() .. " in the PvP area!"))
-        end
-       end
-end)
 minetest.register_on_player_hpchange(function(player, hp_change)
     local name = player:get_player_name()
        if elidragon.get_area_with_tag(name, "no_damage") and hp_change < 0 then