2013-01-04 04:18:42 +01:00
|
|
|
--File Manipulating
|
2013-06-30 05:45:28 +02:00
|
|
|
specialties.writeXP = function(name)
|
|
|
|
local file = io.open(minetest.get_worldpath().."/"..name.."_XP", "w")
|
|
|
|
for skill,_ in pairs(specialties.players[name]) do
|
|
|
|
file:write(skill.." "..tostring(specialties.players[name][skill]).."\n")
|
|
|
|
end
|
2013-01-04 04:18:42 +01:00
|
|
|
file:close()
|
|
|
|
end
|
2013-06-30 05:45:28 +02:00
|
|
|
specialties.readXP = function(name, specialty)
|
|
|
|
local file = io.open(minetest.get_worldpath().."/"..name.."_XP", "r")
|
2013-01-04 04:18:42 +01:00
|
|
|
if file == nil then
|
2013-06-30 05:45:28 +02:00
|
|
|
specialties.writeXP(name)
|
|
|
|
local empty = {}
|
|
|
|
for skill,_ in pairs(specialties.skills) do
|
|
|
|
empty[skill] = 0
|
|
|
|
end
|
|
|
|
return empty
|
|
|
|
end
|
|
|
|
local xp = {}
|
|
|
|
local line = file:read("*l")
|
|
|
|
while line ~= nil do
|
|
|
|
local params = line:split(" ")
|
|
|
|
xp[params[1]] = tonumber(params[2])
|
|
|
|
line = file:read("*l")
|
2013-01-04 04:18:42 +01:00
|
|
|
end
|
|
|
|
file:close()
|
|
|
|
return xp
|
|
|
|
end
|
|
|
|
|
|
|
|
--Table Modification
|
2013-06-30 05:45:28 +02:00
|
|
|
specialties.changeXP = function(name, specialty, amount)
|
|
|
|
local current = specialties.players[name][specialty]
|
2013-01-04 04:18:42 +01:00
|
|
|
if current+amount >= 0 then
|
2013-06-30 05:45:28 +02:00
|
|
|
specialties.players[name][specialty] = current+amount
|
2013-01-04 04:18:42 +01:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|