[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_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()

View File

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