mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
make the timer server (multiplayer) compatible
This commit is contained in:
parent
12e48570c7
commit
4d04eb7b8a
10
init.lua
10
init.lua
@ -8,7 +8,7 @@ end
|
||||
|
||||
|
||||
_xtend.v.xtimer = {
|
||||
startDate = os.time(),
|
||||
startDate = {},
|
||||
interval = _xtend.g('xtimer_update_interval'),
|
||||
placeholder = _xtend.g('xtimer_placeholder'),
|
||||
font_color = _xtend.g('xtimer_font_color'),
|
||||
@ -30,6 +30,7 @@ _xtend.v.xtimer = {
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(1, function(player)
|
||||
local playerName = player:get_player_name()
|
||||
local hud_id = player:hud_add({
|
||||
hud_elem_type = 'text',
|
||||
position = _xtend.v.xtimer.location.position,
|
||||
@ -38,6 +39,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
text = _xtend.v.xtimer.placeholder,
|
||||
number = '0x'.._xtend.v.xtimer.font_color
|
||||
})
|
||||
_xtend.v.xtimer.startDate[playerName] = os.time()
|
||||
minetest.after(5, _xtimer_changeText, player, hud_id)
|
||||
end, player)
|
||||
end)
|
||||
@ -49,18 +51,20 @@ function _xtimer_changeText(player, hud_id)
|
||||
local currentLocale = os.setlocale(nil)
|
||||
os.setlocale(_xtend.v.xtimer.format.locale)
|
||||
|
||||
local playerName = player:get_player_name()
|
||||
local time = 24*60*minetest.get_timeofday()
|
||||
local h = tostring((math.floor(time/60) % 60))
|
||||
local m = tostring((math.floor(time) % 60))
|
||||
|
||||
|
||||
local res = _xtend.v.xtimer.format.output:gsub('(+.)', {
|
||||
['+s'] = os.date(_xtend.v.xtimer.format.start, _xtend.v.xtimer.startDate),
|
||||
['+s'] = os.date(_xtend.v.xtimer.format.start, _xtend.v.xtimer.startDate[playerName]),
|
||||
['+c'] = os.date(_xtend.v.xtimer.format.current),
|
||||
['+r'] = os.date('!'.._xtend.v.xtimer.format.runtime:gsub('(+.)', {
|
||||
['+h'] = '%H',
|
||||
['+m'] = '%M',
|
||||
['+s'] = '%S'
|
||||
}), os.time() - _xtend.v.xtimer.startDate),
|
||||
}), os.time() - _xtend.v.xtimer.startDate[playerName]),
|
||||
['+i'] = _xtend.v.xtimer.format.ingame:gsub('(+.)', {
|
||||
['+h'] = string.rep('0', 2-#h)..h,
|
||||
['+m'] = string.rep('0', 2-#m)..m
|
||||
|
Loading…
Reference in New Issue
Block a user