1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-07-03 07:00:23 +02:00

default.log_player_action supports a list of message parts (thanks appgurueu)

This commit is contained in:
nixnoxus
2022-04-22 18:24:36 +02:00
parent fc6e5944a2
commit c3466dbd18
2 changed files with 21 additions and 8 deletions

View File

@ -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)`

View File

@ -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)