-- Define a function to perform a delayed action
function delayed_action(player_name, delay_seconds, action)
minetest.after(delay_seconds, function()
-- Execute the provided action after the specified delay
action(player_name)
end)
end
-- Example of how to use the delayed_action function
minetest.register_chatcommand("delayed_hello", {
params = "<player>",
description = "Say hello to a player after a delay",
func = function(name, param)
-- Parse the player name from the command parameters
local player_name = param:trim()
-- Check if the player exists
if minetest.get_player_by_name(player_name) then
-- Define the delayed action to say hello after 5 seconds
delayed_action(player_name, 5, function(player)
minetest.chat_send_player(player, "Hello, " .. player .. "!")
end)
else
-- Inform the user that the specified player does not exist
minetest.chat_send_player(name, "Player not found: " .. player_name)
end
end,
})