From 7bd310a2819437c495f57a327dbb202eec1b0eff Mon Sep 17 00:00:00 2001 From: Shawn Petros Date: Thu, 4 Nov 2021 09:01:12 -0500 Subject: [PATCH 1/5] feat: implement jitter --- Repeater.lua | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/Repeater.lua b/Repeater.lua index 74b2347..6e711f8 100644 --- a/Repeater.lua +++ b/Repeater.lua @@ -35,51 +35,56 @@ chars = require('chat.chars') packets = require('packets') repeatdelay = 10 +jitter = false line = 'input /echo Command to repeat has not been set.' count = 'Forever' windower.register_event('addon command',function (...) - cmd = {...} - if cmd[1] ~= nil then + cmd = {...} + if cmd[1] ~= nil then cmd[1] = cmd[1]:lower() end - + if cmd[1] == nil or cmd[1] == "status" then if autorepeat == true then windower.add_to_chat(7,'Repeating is ON.') else windower.add_to_chat(7,'Repeating is OFF.') end - windower.add_to_chat(7,'Delay in seconds: '..repeatdelay..'') windower.add_to_chat(7,'Command to repeat: '..line..'') windower.add_to_chat(7,'Repeat count: '..count..'') - - elseif cmd[1] == "help" then + + elseif cmd[1] == "help" then windower.add_to_chat(7,'To start or stop repeating use //repeater repeat') windower.add_to_chat(7,'To set command type the winder command you want to use after //repeater command') windower.add_to_chat(7,'To set your repeat delay //repeater delay') windower.add_to_chat(7,'To set your repeat count //repeater count') - - elseif cmd[1] == "rollcall" then + windower.add_to_chat(7,'To add a 0-3 second jitter to your command //repeater jitter') + elseif cmd[1] == "rollcall" then if autorepeat == true and ((type(count) == 'string' and count == 'Forever') or (windower.regex.match(count, "^[0-9]+$") and count > 0)) then - windower.send_command(''..line..'') + -- seed math.random with current OS time + math.randomseed(os.clock()) + windower.send_command(''..line..'') + repeatdelay = jitter ? repeatdelay + math.random(0, 3) : repeatdelay windower.send_command('@wait '..repeatdelay..';repeater rollcall') if count ~= 'Forever' then count = count -1 windower.add_to_chat(7,'Repeats remaining: '..count..'') end end + elseif cmd[1] == "repeat" then if autorepeat == false then autorepeat = true windower.add_to_chat(7,'Enabling Repeater.') windower.send_command('repeater rollcall') elseif autorepeat == true then - autorepeat = false + autorepeat = false windower.add_to_chat(7,'Disabling Repeater.') end + elseif cmd[1] == "on" or cmd[1] == "start" or cmd[1] == "begin" or cmd[1] == "go" or cmd[1] == "enable" or cmd[1] == "resume" or cmd[1] == "engage" then if autorepeat == false then autorepeat = true @@ -88,6 +93,7 @@ windower.register_event('addon command',function (...) else windower.add_to_chat(7,'Repeater already enabled.') end + elseif cmd[1] == "off" or cmd[1] == "stop" or cmd[1] == "end" or cmd[1] == "quit" or cmd[1] == "pause" or cmd[1] == "disable" or cmd[1] == "disengage" then if autorepeat == true then autorepeat = false @@ -95,17 +101,21 @@ windower.register_event('addon command',function (...) else windower.add_to_chat(7,'Repeater already disabled.') end + elseif cmd[1] == "command" or cmd[1] == "cmd" then table.remove(cmd, 1) line = table.concat(cmd, ' ') windower.add_to_chat(122,'Your command to repeat has been set to: '..line..'.') - + elseif cmd[1] == "reload" then windower.send_command('lua reload repeater') - + elseif cmd[1] == "unload" then windower.send_command('lua unload repeater') + elseif cmd[1] == "jitter" then + jitter = true + elseif cmd[1] == "delay" then if windower.regex.match(cmd[2], "^[0-9]+$") then repeatdelay = cmd[2] @@ -113,6 +123,7 @@ windower.register_event('addon command',function (...) else windower.add_to_chat(122,'Delay must be input in numerals.') end + elseif cmd[1] == "count" then if cmd[2]:ucfirst() == 'Forever' then count = 'Forever' @@ -123,7 +134,7 @@ windower.register_event('addon command',function (...) else windower.add_to_chat(122,'Delay must be input in numerals.') end - end + end end) windower.register_event('load', function() @@ -132,4 +143,4 @@ end) windower.register_event('zone change', function() autorepeat = false -end) \ No newline at end of file +end) From 26ee1f8d7073e3b68ac862ce25937d8c42f3750e Mon Sep 17 00:00:00 2001 From: Shawn Petros Date: Thu, 4 Nov 2021 14:58:42 -0500 Subject: [PATCH 2/5] fix: syntactically correct ternary --- Repeater.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Repeater.lua b/Repeater.lua index 6e711f8..994caad 100644 --- a/Repeater.lua +++ b/Repeater.lua @@ -54,6 +54,7 @@ windower.register_event('addon command',function (...) windower.add_to_chat(7,'Delay in seconds: '..repeatdelay..'') windower.add_to_chat(7,'Command to repeat: '..line..'') windower.add_to_chat(7,'Repeat count: '..count..'') + windower.add_to_chat(7,'Jitter: '..jitter..'') elseif cmd[1] == "help" then windower.add_to_chat(7,'To start or stop repeating use //repeater repeat') @@ -67,7 +68,7 @@ windower.register_event('addon command',function (...) -- seed math.random with current OS time math.randomseed(os.clock()) windower.send_command(''..line..'') - repeatdelay = jitter ? repeatdelay + math.random(0, 3) : repeatdelay + repeatdelay = jitter and repeatdelay + math.random(0, 3) or repeatdelay windower.send_command('@wait '..repeatdelay..';repeater rollcall') if count ~= 'Forever' then count = count -1 From b5149155411a8ac4e78b62524ce510ff38a81e2d Mon Sep 17 00:00:00 2001 From: Shawn Petros Date: Thu, 4 Nov 2021 15:13:09 -0500 Subject: [PATCH 3/5] fix: improve output --- Repeater.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Repeater.lua b/Repeater.lua index 994caad..422812d 100644 --- a/Repeater.lua +++ b/Repeater.lua @@ -115,7 +115,13 @@ windower.register_event('addon command',function (...) windower.send_command('lua unload repeater') elseif cmd[1] == "jitter" then - jitter = true + if jitter then + jitter = false + windower.add_to_chat(122,'Jitter has been turned off.') + else + jitter = true + windower.add_to_chat(122,'Jitter has been turned on.') + end elseif cmd[1] == "delay" then if windower.regex.match(cmd[2], "^[0-9]+$") then From b74e43ef8a0dd48c93d7221c79947b174acbf858 Mon Sep 17 00:00:00 2001 From: Shawn Petros Date: Thu, 4 Nov 2021 15:50:35 -0500 Subject: [PATCH 4/5] feat: add jitterdelay --- Repeater.lua | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Repeater.lua b/Repeater.lua index 422812d..a6be53a 100644 --- a/Repeater.lua +++ b/Repeater.lua @@ -27,7 +27,7 @@ _addon.name = 'Repeater' _addon.version = '1.1' _addon.author = 'Selindrile, thanks to: Balloon and Lorand and Mujihina' -_addon.commands = {'repeat','repeater'} +_addon.commands = {'repeat','repeater','rp'} require('luau') chat = require('chat') @@ -35,7 +35,7 @@ chars = require('chat.chars') packets = require('packets') repeatdelay = 10 -jitter = false +jitterdelay = 0 line = 'input /echo Command to repeat has not been set.' count = 'Forever' @@ -54,7 +54,7 @@ windower.register_event('addon command',function (...) windower.add_to_chat(7,'Delay in seconds: '..repeatdelay..'') windower.add_to_chat(7,'Command to repeat: '..line..'') windower.add_to_chat(7,'Repeat count: '..count..'') - windower.add_to_chat(7,'Jitter: '..jitter..'') + windower.add_to_chat(7,'Jitter in seconds: '..jitterdelay..'') elseif cmd[1] == "help" then windower.add_to_chat(7,'To start or stop repeating use //repeater repeat') @@ -64,11 +64,15 @@ windower.register_event('addon command',function (...) windower.add_to_chat(7,'To add a 0-3 second jitter to your command //repeater jitter') elseif cmd[1] == "rollcall" then - if autorepeat == true and ((type(count) == 'string' and count == 'Forever') or (windower.regex.match(count, "^[0-9]+$") and count > 0)) then + if autorepeat == true and ((type(count) == 'string' and count == 'Forever') or (windower.regex.match(count, "^([0-9](\.?[0-9]+?)?)+$") and count > 0)) then -- seed math.random with current OS time math.randomseed(os.clock()) windower.send_command(''..line..'') - repeatdelay = jitter and repeatdelay + math.random(0, 3) or repeatdelay + if (type(jitterdelay) == 'number' and jitterdelay > 0) then + repeatdelay = repeatdelay + (math.random() * jitterdelay) + windower.add_to_chat(7,'Executing command '..command..' with '..repeatdelay..' delay.') + end + windower.send_command('@wait '..repeatdelay..';repeater rollcall') if count ~= 'Forever' then count = count -1 @@ -115,31 +119,28 @@ windower.register_event('addon command',function (...) windower.send_command('lua unload repeater') elseif cmd[1] == "jitter" then - if jitter then - jitter = false - windower.add_to_chat(122,'Jitter has been turned off.') - else - jitter = true - windower.add_to_chat(122,'Jitter has been turned on.') + if windower.regex.match(cmd[2], "^([0-9](\.?[0-9]+?)?)+$") then + jitterdelay = cmd[2] + windower.add_to_chat(122,'Your jitter delay has been set to: '..jitterdelay..'.') end elseif cmd[1] == "delay" then - if windower.regex.match(cmd[2], "^[0-9]+$") then + if windower.regex.match(cmd[2], "^([0-9](\.?[0-9]+?)?)+$") then repeatdelay = cmd[2] windower.add_to_chat(122,'Your repeat delay has been set to: '..repeatdelay..'.') else - windower.add_to_chat(122,'Delay must be input in numerals.') + windower.add_to_chat(122,'Delay must be input in whole or decimal numerals.') end elseif cmd[1] == "count" then if cmd[2]:ucfirst() == 'Forever' then count = 'Forever' windower.add_to_chat(122,'Your repeat count has been set to: '..count..'.') - elseif windower.regex.match(cmd[2], "^[0-9]+$") then + elseif windower.regex.match(cmd[2], "^([0-9](\.?[0-9]+?)?)+$") then count = tonumber(cmd[2]) windower.add_to_chat(122,'Your repeat count has been set to: '..count..'.') else - windower.add_to_chat(122,'Delay must be input in numerals.') + windower.add_to_chat(122,'Delay must be input in whole or decimal numerals.') end end end) From 014b341f79991893691b9fb4fb438a52fc3afe5b Mon Sep 17 00:00:00 2001 From: troyBORG Date: Sun, 26 Dec 2021 02:33:30 -0600 Subject: [PATCH 5/5] Update Repeater.lua --- Repeater.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Repeater.lua b/Repeater.lua index a6be53a..f804648 100644 --- a/Repeater.lua +++ b/Repeater.lua @@ -124,7 +124,7 @@ windower.register_event('addon command',function (...) windower.add_to_chat(122,'Your jitter delay has been set to: '..jitterdelay..'.') end - elseif cmd[1] == "delay" then + elseif cmd[1] == "delay" or cmd[1] == "cycle" then if windower.regex.match(cmd[2], "^([0-9](\.?[0-9]+?)?)+$") then repeatdelay = cmd[2] windower.add_to_chat(122,'Your repeat delay has been set to: '..repeatdelay..'.')