countdown timer using xpfw mod

master
A. Demant 2019-01-09 17:24:43 +01:00
parent 4d94752ae3
commit bcedf3eac2
5 changed files with 36 additions and 16 deletions

View File

@ -1,19 +1,13 @@
Minetest Game mod: XPFW Minetest Game mod: timer
========================== ==========================
See license.txt for license information. See license.txt for license information.
XPFW provide an API for storing values relevant for experience mechanism into player metadata. It also stores several statistic values during playtime: This mod provides a simple countdown timer for each player. It uses xpfw for storing value, so it is also visible in the xpfw hud.
- Walked distances calculated out of velocity (important: teleporting does not influence this value)
- accumulated distance out of comparing with last known position (important: teleporting is included in this value)
- whole playtime on the server
- amount of dug nodes
- amount of build nodes
- amount of crafted items
- amount of occured deahts
- amount of text messages
- amount of logins
For several amounts also a kind of speed is calculated, like walking speed or crafting speed. chat command:
/cd <value> set countdown with <value> seconds. if not given, start with default value
/cd r/rest give remainign countdown time
Authors of source code Authors of source code
---------------------- ----------------------

View File

@ -8,9 +8,18 @@ minetest.register_chatcommand("cd", {
local xp= string.split(param, " ") local xp= string.split(param, " ")
if #xp == 1 then if #xp == 1 then
countdown=tonumber(xp[1]) countdown=tonumber(xp[1])
print(countdown,xp[1])
if countdown == nil then
if (xp[1] == "rest") or (xp[1] == "r") then
minetest.chat_send_player(name,"countdown remaining: "..math.floor(100*xpfw.player_get_attribute(minetest.get_player_by_name(name),timer.prefix))/100)
end
end
elseif #xp >1 then elseif #xp >1 then
countdown=tonumber(xp[2]) countdown=tonumber(xp[2])
end end
timer.player[name]=countdown if countdown ~=nil then
xpfw.player_set_attribute(minetest.get_player_by_name(name),timer.prefix,countdown)
timer.player[name]=countdown
end
end end
}) })

View File

@ -5,4 +5,4 @@ timer.prefix="timer:countdown"
timer.player={} timer.player={}
timer.dtime=0 timer.dtime=0
--xpfw.register_attribute(timer.prefix,{min=0,max=math.huge,default=timer.countdown_default,hud=1}) xpfw.register_attribute(timer.prefix,{min=0,max=math.huge,default=0,hud=1})

View File

@ -12,5 +12,6 @@ basic_functions.import_settingtype(timer.path .. "/settingtypes.txt")
dofile(timer.path .. "/config.lua") -- API dofile(timer.path .. "/config.lua") -- API
dofile(timer.path .. "/chat_commands.lua") dofile(timer.path .. "/chat_commands.lua")
dofile(timer.path .. "/register.lua")
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded ") minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded ")

View File

@ -1,7 +1,7 @@
local M=timer local M=timer
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
xpfw.player_set_attribute(player,timer.prefix,0) -- xpfw.player_set_attribute(player,timer.prefix,0)
end end
) )
@ -15,8 +15,24 @@ end)
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer.dtime=timer.dtime+dtime timer.dtime=timer.dtime+dtime
if timer.dtime>timer.precision then if timer.dtime>timer.precision then
local ttime=timer.dtime
timer.dtime=0 timer.dtime=0
local players = minetest.get_connected_players()
if #players ~= nil then
if #players > 0 then
for i=1, #players do
local player=players[i]
local name = player:get_player_name()
if xpfw.player_get_attribute(player,timer.prefix)>0 then
xpfw.player_sub_attribute(player,timer.prefix,ttime)
if xpfw.player_get_attribute(player,timer.prefix)<=0 then
minetest.chat_send_player(name,"Countdown finished")
timer.player[name]=nil
end
end
end
end
end
end end
-- print("xpfw_abm: "..1000*(os.clock()-starttime))
end) end)