1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00
kawari/resources/scripts/Global.lua
The Dax 0f7e068ba3 Further reduce boilerplate in various scripts
-Introduce a printf helper command which can print the sending command's name for you,
and treats the message as a format string if additional params follow
2025-06-26 07:47:05 -04:00

50 lines
1.2 KiB
Lua

-- This file should only be used for globally useful constants and functions.
-- Please put new events, actions, items, etc. in their respective 'main' Lua files.
function split(input, separator)
if separator == nil then
separator = '%s'
end
local t = {}
for str in string.gmatch(input, '([^'..separator..']+)') do
table.insert(t, str)
end
return t
end
function getTableSize(tbl)
local count = 0
for _, _ in pairs(tbl) do
count = count + 1
end
return count
end
function printf(player, fmt_str, ...)
-- Sender would be defined elsewhere, if at all
if sender == nil then
sender = ""
end
if ... ~= nil then
player:send_message(sender..fmt_str:format(...))
else
player:send_message(sender..fmt_str)
end
sender = nil -- Reset the sender, it's not required to have for printf to work, and not all users of printf will be commands, most likely.
end
-- Constants
GM_RANK_NORMALUSER = 0
GM_RANK_GAMEMASTER = 1
GM_RANK_EVENTJUNIOR = 3
GM_RANK_EVENTSENIOR = 4
GM_RANK_SUPPORT = 5
GM_RANK_SENIOR = 7
GM_RANK_DEBUG = 90
GM_RANK_MAX = 255 -- Doesn't exist, used for purposes of testing permissions in scripts