Skip to content

Commit

Permalink
fix deprecated functions
Browse files Browse the repository at this point in the history
extension of 9da14a2 which actually fixes #51 ;)
  • Loading branch information
OgelGames committed May 31, 2021
1 parent f485428 commit 48ec0f1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions highscore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions mobs.lua
Original file line number Diff line number Diff line change
@@ -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


Expand Down

0 comments on commit 48ec0f1

Please sign in to comment.