fix deprecated functions

extension of 9da14a2 which actually fixes #51 ;)
master
OgelGames 2021-05-31 18:16:59 +10:00
parent f4854282b7
commit 48ec0f186d
4 changed files with 14 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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