[bug fix] xp system fix

This commit is contained in:
cale 2016-01-08 16:39:13 +01:00
parent 8ce447e6ca
commit 6fe74e6f8c
2 changed files with 72 additions and 34 deletions

View File

@ -19,7 +19,7 @@ function xp.add_xp(player, num)
if xp.player_levels[player:get_player_name()] then 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 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) xp.add_lvl(player)
end end
else else
@ -42,22 +42,41 @@ function xp.add_lvl(player)
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
xp.xp_hud[player:get_player_name()] = player:hud_add({ if xp.player_xp[player:get_player_name()] then
hud_elem_type = "statbar", xp.xp_hud[player:get_player_name()] = player:hud_add({
position = {x=0.5,y=1.0}, hud_elem_type = "statbar",
size = {x=16, y=16}, position = {x=0.5,y=1.0},
offset = {x=-(32*8+16), y=-(48*2+16)}, size = {x=16, y=16},
text = "xp_xp.png", offset = {x=-(32*8+16), y=-(48*2+16)},
number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), 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", xp.level_hud[player:get_player_name()] = player:hud_add({
position = {x=0.5,y=1}, hud_elem_type = "text",
text = xp.player_levels[player:get_player_name()], position = {x=0.5,y=1},
number = 0xFFFFFF, text = xp.player_levels[player:get_player_name()],
alignment = {x=0.5,y=1}, number = 0xFFFFFF,
offset = {x=0, y=-(48*2+16)}, 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) end)
function xp.load_xp() function xp.load_xp()

View File

@ -19,7 +19,7 @@ function xp.add_xp(player, num)
if xp.player_levels[player:get_player_name()] then 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 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) xp.add_lvl(player)
end end
else else
@ -42,22 +42,41 @@ function xp.add_lvl(player)
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
xp.xp_hud[player:get_player_name()] = player:hud_add({ if xp.player_xp[player:get_player_name()] then
hud_elem_type = "statbar", xp.xp_hud[player:get_player_name()] = player:hud_add({
position = {x=0.5,y=1.0}, hud_elem_type = "statbar",
size = {x=16, y=16}, position = {x=0.5,y=1.0},
offset = {x=-(32*8+16), y=-(48*2+16)}, size = {x=16, y=16},
text = "xp_xp.png", offset = {x=-(32*8+16), y=-(48*2+16)},
number = 20*((xp.player_xp[player:get_player_name()])/(xp.lvl*xp.player_levels[player:get_player_name()])), 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", xp.level_hud[player:get_player_name()] = player:hud_add({
position = {x=0.5,y=1}, hud_elem_type = "text",
text = xp.player_levels[player:get_player_name()], position = {x=0.5,y=1},
number = 0xFFFFFF, text = xp.player_levels[player:get_player_name()],
alignment = {x=0.5,y=1}, number = 0xFFFFFF,
offset = {x=0, y=-(48*2+16)}, 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) end)
function xp.load_xp() function xp.load_xp()