diff --git a/functions.lua b/functions.lua index 0dfa78d..6f37b4a 100644 --- a/functions.lua +++ b/functions.lua @@ -97,7 +97,7 @@ xp_redo.add_xp = function(playername, xp) -- level up xp_redo.run_hook("rank_change", { playername, sumXp, currentRank }) - local state = player:get_attribute(xp_redo.HUD_DISPLAY_STATE_NAME) + local state = player:get_meta():get(xp_redo.HUD_DISPLAY_STATE_NAME) if state and state == "on" then level_up(player, currentRank) end diff --git a/highscore.lua b/highscore.lua index fa3088e..5685adc 100644 --- a/highscore.lua +++ b/highscore.lua @@ -28,18 +28,18 @@ local update_highscore = function() for _,player in pairs(players) do local name = player:get_player_name() + local xp = player:get_meta():get_int("xp") local found = false for _,entry in pairs(xp_redo.highscore) do if entry.name == name then -- connected player already exists in highscore, update value - entry.xp = tonumber(player:get_attribute("xp")) or 0 + entry.xp = xp found = true end end if not found then -- create new entry - local xp = tonumber(player:get_attribute("xp") or "0") table.insert(xp_redo.highscore, { name=name, xp=xp }) end end diff --git a/hud.lua b/hud.lua index 7793a05..dc45026 100644 --- a/hud.lua +++ b/hud.lua @@ -21,7 +21,7 @@ local setup_hud = function(player) local data = {} - player:set_attribute(xp_redo.HUD_DISPLAY_STATE_NAME, "on") + player:get_meta():set_string(xp_redo.HUD_DISPLAY_STATE_NAME, "on") data.info = player:hud_add({ hud_elem_type = "text", @@ -91,7 +91,7 @@ local remove_hud = function(player) local playername = player:get_player_name() local data = hud[playername] - player:set_attribute(xp_redo.HUD_DISPLAY_STATE_NAME, "off") + player:get_meta():set_string(xp_redo.HUD_DISPLAY_STATE_NAME, "off") if not data then @@ -203,7 +203,7 @@ xp_redo.update_hud = function(player, xp, rank, next_rank) end minetest.register_on_joinplayer(function(player) - local state = player:get_attribute(xp_redo.HUD_DISPLAY_STATE_NAME) + local state = player:get_meta():get(xp_redo.HUD_DISPLAY_STATE_NAME) if not state or state == "on" then setup_hud(player) end diff --git a/mobs.lua b/mobs.lua index da87033..09cd46b 100644 --- a/mobs.lua +++ b/mobs.lua @@ -1,30 +1,26 @@ local increment_punch_count = function(player) - if player == nil or player.get_attribute == nil then + if player == nil or player.is_fake_player then -- fake player return end - local count = player:get_attribute("punch_count") - if not count then - count = 0 - end + local meta = player:get_meta() + local count = meta:get_int("punch_count") - player:set_attribute("punch_count", count + 1) + meta:set_int("punch_count", count + 1) end local increase_inflicted_damage = function(player, value) - if player == nil or player.get_attribute == nil then + if player == nil or player.is_fake_player then -- fake player return end - local count = player:get_attribute("inflicted_damage") - if not count then - count = 0 - end + local meta = player:get_meta() + local count = meta:get_int("inflicted_damage") - player:set_attribute("inflicted_damage", count + value) + meta:set_int("inflicted_damage", count + value) end