summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2018-05-13 13:04:24 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2018-05-13 13:04:24 +0200
commit34ce286360a4f1e412e889213bb7c9315dda6c8b (patch)
treea584a5c68b7e2b2ec94b68d6e184defc20744331 /init.lua
parenteebe0fbce3a9869835de47ddebacb9a01be29f4b (diff)
downloadsmartshop-34ce286360a4f1e412e889213bb7c9315dda6c8b.tar.gz
smartshop-34ce286360a4f1e412e889213bb7c9315dda6c8b.tar.bz2
smartshop-34ce286360a4f1e412e889213bb7c9315dda6c8b.zip
added report on globalstep, add sample munin plugin
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua52
1 files changed, 33 insertions, 19 deletions
diff --git a/init.lua b/init.lua
index c1b79ef..2c3fc8d 100644
--- a/init.lua
+++ b/init.lua
@@ -567,31 +567,45 @@ minetest.register_chatcommand("smstats", {
end,
})
+smartshop.report = function ()
+ local file = io.open(minetest.get_worldpath().."/smartshop_report.txt", "w")
+ if not file then
+ return false, "could not write to file"
+ end
+ for i,k in pairs(smartshop.itemstats) do
+ local count = smartshop.get_item_count(i)
+ local price = smartshop.get_item_price(i)
+ file:write(i.." "..count.." "..string.format("%.3f", price).." "..smartshop.get_shop_count(i).."\n")
+ end
+ file:close()
+end
+
minetest.register_chatcommand("smreport", {
description = "Get number of items sold",
func = function(plname, params)
- local file = io.open(minetest.get_worldpath().."/smartshop_report.txt", "w")
- if not file then
- return false, "could not write to file"
- end
- for i,k in pairs(smartshop.itemstats) do
- local count = smartshop.get_item_count(i)
- local price = smartshop.get_item_price(i)
- file:write(i.." "..count.." "..string.format("%.3f", price).." "..smartshop.get_shop_count(i).."\n")
- end
- file:close()
+ smartshop.report()
end,
})
-
-
-minetest.register_lbm({
- name = "smartshop:update",
- nodenames = {"smartshop:shop"},
- action = function(pos, node)
- smartshop.update_info(pos)
- end,
-})
+local timer = 0
+minetest.register_globalstep(function(dtime)
+ timer = timer + dtime;
+ if timer >= 100 then
+ smartshop.report()
+ timer = 0
+ end
+end)
+
+
+if false then -- This lbm is used to add pre-update smartshops to the price database. Activate with care! Warning: very slow.
+ minetest.register_lbm({
+ name = "smartshop:update",
+ nodenames = {"smartshop:shop"},
+ action = function(pos, node)
+ smartshop.update_info(pos)
+ end,
+ })
+end
-- load itemstats
local file = io.open(minetest.get_worldpath().."/smartshop_itemcounts.txt", "r")