forked from Tunaliz/Repeater
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Repeater.lua
154 lines (132 loc) · 5.93 KB
/
Repeater.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
--Copyright (c) 2016, Selindrile
--All rights reserved.
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of RollTracker nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
--ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
--WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
--DISCLAIMED. IN NO EVENT SHALL THOMAS ROGERS BE LIABLE FOR ANY
--DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
--(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
--LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
--ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
_addon.name = 'Repeater'
_addon.version = '1.1'
_addon.author = 'Selindrile, thanks to: Balloon and Lorand and Mujihina'
_addon.commands = {'repeat','repeater','rp'}
require('luau')
chat = require('chat')
chars = require('chat.chars')
packets = require('packets')
repeatdelay = 10
jitterdelay = 0
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[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..'')
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')
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')
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](\.?[0-9]+?)?)+$") and count > 0)) then
-- seed math.random with current OS time
math.randomseed(os.clock())
windower.send_command(''..line..'')
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
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
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
windower.add_to_chat(7,'Enabling Repeater.')
windower.send_command('repeater rollcall')
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
windower.add_to_chat(7,'Disabling Repeater.')
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
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](\.?[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 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](\.?[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 whole or decimal numerals.')
end
end
end)
windower.register_event('load', function()
autorepeat = false
end)
windower.register_event('zone change', function()
autorepeat = false
end)