diff --git a/custom notifications.lua b/custom notifications.lua index 5d1636f..c3d5f97 100644 --- a/custom notifications.lua +++ b/custom notifications.lua @@ -1,26 +1,40 @@ debug = true -function debug_print(message) +local function debug_print(message) if debug == true then Printf(tostring(message)) end end -function main(display_handle, args) + +local function split_first(inputstr, sep) + local sep = sep or ";" + local sep_pos = string.find(inputstr, sep) + if not sep_pos then + return inputstr, nil + end + local first = string.sub(inputstr, 1, sep_pos - 1) + local rest = string.sub(inputstr, sep_pos + 1) + return first, rest +end + +local function main(display_handle, args) if args then timeout = 5 - timeout, seperator, message = args.partition(";") + local timeoutStr, message = split_first(args, ";") + timeout = tonumber(timeoutStr) or timeout + local messageTable = { title = "Notification!", message = tostring(message), - timeout = tonumber(timeout*1000), + timeout = timeout * 1000, -- convert seconds to milliseconds timeoutResultCancel = false, timeoutResultID = 99, } local returnTable = MessageBox(messageTable) else - Printf('You must atleast specify your notification message. You can do this by running the following command: Plugin "custom notifications" "5;Hello this is a notification!"\nThis will create a message with a duration of 5 seconds.') + Printf('You must at least specify your notification message. Example:\nPlugin "custom notifications" "5;Hello this is a notification!"\nThis will create a message with a duration of 5 seconds.') end end