Skip to content

Commit

Permalink
Add remove_playtime function and save current playtime in array
Browse files Browse the repository at this point in the history
In array instead of mod storage as it is permanent.
  • Loading branch information
Lejo1 committed Aug 9, 2019
1 parent cf8a475 commit 8dd3edd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
playtime = {}

local current = {}

local storage = minetest.get_mod_storage()

function playtime.get_current_playtime(name)
return os.time() - storage:get_int(name.."-join")
return os.time() - current[name]
end

-- Function to get playtime
function playtime.get_total_playtime(name)
return storage:get_int(name) + playtime.get_current_playtime(name)
end

function playtime.remove_playtime(name)
storage:set_string(name, "")
end

minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
storage:set_int(name, storage:get_int(name) + (os.time() - storage:get_int(name.."-join")))
storage:set_int(name, storage:get_int(name) + playtime.get_current_playtime(name))
current[name] = nil
end)

minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
storage:set_int(name.."-join", os.time())
current[name] = os.time()
end)

local function SecondsToClock(seconds)
Expand Down

0 comments on commit 8dd3edd

Please sign in to comment.