yl_translate/api.lua
2024-06-06 18:53:08 +00:00

35 lines
1.4 KiB
Lua

-- Use this file for functions that can be called from other mods
-- Make sure the functions are well defended against wrong input and
-- document them on the readme, what they do, what types and values
-- they expect as parameters and what types and values they return.
-- If you ever change those, consider adding backwards compatibility,
-- since other mods may rely on them.
function yl_template.some_api_call(target, message, color)
if (type(target) ~= "string") then
return false, yl_template.t("error_not_a_string", "target")
end
if (minetest.get_player_by_name(target) == nil) then
return false, yl_template.t("error_player_not_online", target)
end
if (type(message) ~= "string") then
return false, yl_template.t("error_not_a_string", "message")
end
-- is_color(color) does not exist, you need to implement it if you want to use it
if (is_color(color) == false) then
return false, yl_template.t("error_not_a_colorspec", "color")
end
if (minetest.colorize == nil) then
return false, yl_template.t("error_function_not_available",
"minetest.colorize")
end
local message_with_color = minetest.colorize(color, message)
minetest.chat_send_player(target, message_with_color)
return true, yl_template.t("api_sent_x_to_y", message_with_color, target)
end