From f7d741b2e7cafec231c6624b3111ea1c2e136c9d Mon Sep 17 00:00:00 2001 From: whosit Date: Thu, 15 Feb 2024 17:25:59 +0300 Subject: [PATCH] add logging --- init.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index f00a815..6f6f459 100644 --- a/init.lua +++ b/init.lua @@ -77,6 +77,8 @@ local function roll_dice(pos, node) pitch = 1.0 + 0.1*math.random(), } minetest.sound_play(spec, parameters, true) + + return val end minetest.register_node("yl_dice:dice", { @@ -99,10 +101,16 @@ minetest.register_node("yl_dice:dice", { palette = "yl_dice_6_palette.png", on_construct = function(pos) - roll_dice(pos) + local val = roll_dice(pos) + minetest.log("action", ("[yl_dice] placed d6 has rolled %s at %s"):format(val, minetest.pos_to_string(pos))) end, - on_rightclick = function(pos, node, puncher, itemstack, pointed_thing) - roll_dice(pos, node) + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local val = roll_dice(pos, node) + if val then + -- `val` is nil when cooldown has not ended yet + local name = clicker and clicker:is_player() and clicker:get_player_name() or "UNKNOWN" + minetest.log("action", ("[yl_dice] %s has rolled %s by using d6 at %s"):format(name, val, minetest.pos_to_string(pos))) + end end, })