From c3466dbd18a3eb8ef4a4c6ac2020d64bd5f41fcd Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Fri, 22 Apr 2022 18:24:36 +0200 Subject: [PATCH] default.log_player_action supports a list of message parts (thanks appgurueu) --- game_api.txt | 10 ++++++---- mods/default/functions.lua | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/game_api.txt b/game_api.txt index 78c9cbfb..77b390b2 100644 --- a/game_api.txt +++ b/game_api.txt @@ -1131,11 +1131,13 @@ These non-players are marked by the content of `is_fake_player` (if it is a string) or a "*" in brackets after the player name in the log. -`default.log_player_action(player, message, pos)` +`default.log_player_action(player, ...)` - * `player` The player who performed the action - * `message` A message describing the action in 3rd person singular present tense. - * `pos` Position of the node at which the action was performed + * `player` The player who performed the action + * `message_parts` Any mumber of message parts describing the action + in 3rd person singular present tense. It can also + contain a `position` / `vector` which is logged as + " at (X,Y,Z)" `default.set_inventory_action_loggers(def, name)` diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 3219b6e2..eda75809 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -721,16 +721,27 @@ end local log_non_player_actions = minetest.settings:get_bool("log_non_player_actions", false) -function default.log_player_action(player, message, pos) - local who = player:get_player_name() +-- `vector.check` is available since minetest >= 5.5.0 +local is_vector = vector.check or function(v) + return v and type(v) == "table" and + v.x or type(v.x) == "number" and + v.y or type(v.y) == "number" and + v.z or type(v.z) == "number" +end + +function default.log_player_action(player, ...) + local msg = player:get_player_name() if player.is_fake_player or not player:is_player() then if not log_non_player_actions then return end - who = who .. "(" .. (type(player.is_fake_player) == "string" + msg = msg .. "(" .. (type(player.is_fake_player) == "string" and player.is_fake_player or "*").. ")" end - minetest.log("action", who .. " " .. message .. " at " .. minetest.pos_to_string(pos)) + for _, v in ipairs({...}) do + msg = msg .. " " .. (is_vector(v) and ("at " .. minetest.pos_to_string(v)) or v) + end + minetest.log("action", msg) end function default.set_inventory_action_loggers(def, name)