Add update for XP displaying on HUD

This commit is contained in:
Austin Shenk 2013-07-01 19:03:51 -04:00
parent 4ca623f4cc
commit 0096ebbd68

18
xp.lua
View File

@ -1,8 +1,8 @@
--File Manipulating --File Manipulating
specialties.writeXP = function(name) specialties.writeXP = function(name)
local file = io.open(minetest.get_worldpath().."/"..name.."_XP", "w") local file = io.open(minetest.get_worldpath().."/"..name.."_XP", "w")
for skill,_ in pairs(specialties.players[name]) do for skill,num in pairs(specialties.players[name].skills) do
file:write(skill.." "..tostring(specialties.players[name][skill]).."\n") file:write(skill.." "..tostring(num).."\n")
end end
file:close() file:close()
end end
@ -29,9 +29,17 @@ end
--Table Modification --Table Modification
specialties.changeXP = function(name, specialty, amount) specialties.changeXP = function(name, specialty, amount)
local current = specialties.players[name][specialty] local newAmount = specialties.players[name].skills[specialty]+amount
if current+amount >= 0 then if newAmount >= 0 then
specialties.players[name][specialty] = current+amount specialties.players[name].skills[specialty] = newAmount
local player = minetest.get_player_by_name(name)
local id = specialties.players[name].menu[specialty]
local hudItem = player:hud_get(id)
hudItem.text = tostring(newAmount)
hudItem.offset = {x=100, y=0}
hudItem.alignment = {x=1, y=0}
player:hud_remove(id)
specialties.players[name].menu[specialty] = player:hud_add(hudItem)
return true return true
else else
return false return false