From 6fe74e6f8c9b4d74db973b21554814e8e851d23d Mon Sep 17 00:00:00 2001 From: cale Date: Fri, 8 Jan 2016 16:39:13 +0100 Subject: [PATCH] [bug fix] xp system fix --- mods/xp/init.lua | 53 ++++++++++++++++++++++++++++++++--------------- mods/xp/init.lua~ | 53 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/mods/xp/init.lua b/mods/xp/init.lua index 6b1255c..2845c38 100644 --- a/mods/xp/init.lua +++ b/mods/xp/init.lua @@ -19,7 +19,7 @@ function xp.add_xp(player, num) if xp.player_levels[player:get_player_name()] then if xp.player_xp[player:get_player_name()] > xp.lvl*xp.player_levels[player:get_player_name()] then - xp.player_xp[player:get_player_name()] = 0 + xp.player_xp[player:get_player_name()] = xp.player_xp[player:get_player_name()] - xp.lvl*xp.player_levels[player:get_player_name()] xp.add_lvl(player) end else @@ -42,22 +42,41 @@ function xp.add_lvl(player) end minetest.register_on_joinplayer(function(player) - xp.xp_hud[player:get_player_name()] = player:hud_add({ - hud_elem_type = "statbar", - position = {x=0.5,y=1.0}, - size = {x=16, y=16}, - offset = {x=-(32*8+16), y=-(48*2+16)}, - text = "xp_xp.png", - number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), - }) - xp.level_hud[player:get_player_name()] = player:hud_add({ - hud_elem_type = "text", - position = {x=0.5,y=1}, - text = xp.player_levels[player:get_player_name()], - number = 0xFFFFFF, - alignment = {x=0.5,y=1}, - offset = {x=0, y=-(48*2+16)}, - }) + if xp.player_xp[player:get_player_name()] then + xp.xp_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1.0}, + size = {x=16, y=16}, + offset = {x=-(32*8+16), y=-(48*2+16)}, + text = "xp_xp.png", + number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), + }) + xp.level_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5,y=1}, + text = xp.player_levels[player:get_player_name()], + number = 0xFFFFFF, + alignment = {x=0.5,y=1}, + offset = {x=0, y=-(48*2+16)}, + }) + else + xp.xp_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1.0}, + size = {x=16, y=16}, + offset = {x=-(32*8+16), y=-(48*2+16)}, + text = "xp_xp.png", + number = 0, + }) + xp.level_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5,y=1}, + text = "1", + number = 0xFFFFFF, + alignment = {x=0.5,y=1}, + offset = {x=0, y=-(48*2+16)}, + }) + end end) function xp.load_xp() diff --git a/mods/xp/init.lua~ b/mods/xp/init.lua~ index 6b1255c..2845c38 100644 --- a/mods/xp/init.lua~ +++ b/mods/xp/init.lua~ @@ -19,7 +19,7 @@ function xp.add_xp(player, num) if xp.player_levels[player:get_player_name()] then if xp.player_xp[player:get_player_name()] > xp.lvl*xp.player_levels[player:get_player_name()] then - xp.player_xp[player:get_player_name()] = 0 + xp.player_xp[player:get_player_name()] = xp.player_xp[player:get_player_name()] - xp.lvl*xp.player_levels[player:get_player_name()] xp.add_lvl(player) end else @@ -42,22 +42,41 @@ function xp.add_lvl(player) end minetest.register_on_joinplayer(function(player) - xp.xp_hud[player:get_player_name()] = player:hud_add({ - hud_elem_type = "statbar", - position = {x=0.5,y=1.0}, - size = {x=16, y=16}, - offset = {x=-(32*8+16), y=-(48*2+16)}, - text = "xp_xp.png", - number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), - }) - xp.level_hud[player:get_player_name()] = player:hud_add({ - hud_elem_type = "text", - position = {x=0.5,y=1}, - text = xp.player_levels[player:get_player_name()], - number = 0xFFFFFF, - alignment = {x=0.5,y=1}, - offset = {x=0, y=-(48*2+16)}, - }) + if xp.player_xp[player:get_player_name()] then + xp.xp_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1.0}, + size = {x=16, y=16}, + offset = {x=-(32*8+16), y=-(48*2+16)}, + text = "xp_xp.png", + number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), + }) + xp.level_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5,y=1}, + text = xp.player_levels[player:get_player_name()], + number = 0xFFFFFF, + alignment = {x=0.5,y=1}, + offset = {x=0, y=-(48*2+16)}, + }) + else + xp.xp_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = {x=0.5,y=1.0}, + size = {x=16, y=16}, + offset = {x=-(32*8+16), y=-(48*2+16)}, + text = "xp_xp.png", + number = 0, + }) + xp.level_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5,y=1}, + text = "1", + number = 0xFFFFFF, + alignment = {x=0.5,y=1}, + offset = {x=0, y=-(48*2+16)}, + }) + end end) function xp.load_xp()