summaryrefslogtreecommitdiff
path: root/u_skins/players.lua
diff options
context:
space:
mode:
authorSmallJoker <st.rentsch@hotmail.com>2014-07-23 13:46:42 +0200
committerSmallJoker <st.rentsch@hotmail.com>2014-07-23 13:46:42 +0200
commitdc44a8805fc5e3d5c8a3b4464c377dbdbf4a7e68 (patch)
tree96a443c2e4783eb31af44e181cc4b57b0b2f0310 /u_skins/players.lua
parent597213a67d3e224ef0e5f8aabdb53861d8c4db77 (diff)
Update
Diffstat (limited to 'u_skins/players.lua')
-rw-r--r--u_skins/players.lua42
1 files changed, 27 insertions, 15 deletions
diff --git a/u_skins/players.lua b/u_skins/players.lua
index df999fb..772481e 100644
--- a/u_skins/players.lua
+++ b/u_skins/players.lua
@@ -1,26 +1,38 @@
-u_skins.file = minetest.get_worldpath() .. "/u_skins.mt"
-u_skins.load = function()
- local input = io.open(u_skins.file, "r")
- local data = nil
- if input then
- data = input:read('*all')
- end
- if data and data ~= "" then
- lines = string.split(data,"\n")
- for _, line in ipairs(lines) do
- data = string.split(line, ' ', 2)
+u_skins.load_players = function()
+ local file = io.open(u_skins.file, "r")
+ if file then
+ for line in file:lines() do
+ local data = string.split(line, " ", 2)
u_skins.u_skins[data[1]] = data[2]
end
- io.close(input)
+ io.close(file)
end
end
-u_skins.load()
+u_skins.load_players()
+
+local ttime = 0
+minetest.register_globalstep(function(t)
+ ttime = ttime + t
+ if ttime < 360 then --every 6min'
+ return
+ end
+ ttime = 0
+ u_skins.save()
+end)
+
+minetest.register_on_shutdown(function() u_skins.save() end)
u_skins.save = function()
- local output = io.open(u_skins.file,'w')
+ if not u_skins.file_save then
+ return
+ end
+ u_skins.file_save = false
+ local output = io.open(u_skins.file, "w")
for name, skin in pairs(u_skins.u_skins) do
if name and skin then
- output:write(name .. " " .. skin .. "\n")
+ if skin ~= "character_1" then
+ output:write(name.." "..skin.."\n")
+ end
end
end
io.close(output)