-
Notifications
You must be signed in to change notification settings - Fork 4
/
TimerBotc.ttslua
185 lines (158 loc) · 5.51 KB
/
TimerBotc.ttslua
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
--[[
Timer Tool
Made by Sionar
--]]
------------------Constants
VERSION = '1.1.3'
BUTTON_W = 420
BUTTON_H = 300
BUTTON_SPACING = 0.9
COL = {}
for i = -2,2 do
COL[i+3] = i * BUTTON_SPACING
end
BUTTON_Z = 1
FONT_SIZE = 200
START_POS = {x = -20, y = 1.1, z = 12}
BUTTON_COLOR = {0,0,0,1}
BUTTON_FONT_COLOR = {1,1,1,1}
------------------Variables
time = 0
currentTimerID = 0
tint = {0,0,0}
tintID = nil
------------------Functions
function onLoad(saveString)
refreshButtons()
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
end
function getLabel()
local minutes, seconds, timeLabel
minutes = math.floor((time / 60))
seconds = string.format('%02d',time % 60)
timeLabel = minutes .. ':' .. seconds
return timeLabel
end
function timeRefresh()
local minutes, seconds, timeLabel
time = time - 1
if time <= 30 then
self.editButton({index = 0, font_color = stringColorToRGB('Yellow')})
end
if time <= 10 then
self.editButton({index = 0, font_color = stringColorToRGB('Orange')})
end
self.editButton({index = 0, label = getLabel()})
if time == 0 then
self.editButton({index = 0, font_color = stringColorToRGB('Red')})
changeTint()
return
else
currentTimerID = Wait.time(timeRefresh, 1)
end
end
function time30s()
suspendTint()
self.editButton({index = 0, label = '0:30', font_color = stringColorToRGB('Blue')})
time = 30
startTimer()
end
function time3m()
suspendTint()
self.editButton({index = 0, label = '3:00', font_color = stringColorToRGB('Blue')})
time = 180
startTimer()
end
function time6m()
suspendTint()
self.editButton({index = 0, label = '6:00', font_color = stringColorToRGB('Blue')})
time = 360
startTimer()
end
function timeCustom(obj, player_clicker_color, input_value, selected)
if not selected then
suspendTint()
if input_value == '' then
input_value = 1
end
time = math.floor(tonumber(input_value) * 60)
if time <= 0 then
time = 10
end
self.editButton({index = 0, label = getLabel(), font_color = stringColorToRGB('Blue')})
startTimer()
end
end
function startTimer()
self.setLock(true)
Wait.stop(currentTimerID)
self.editButton({index = 4, label = 'Pause'})
currentTimerID = Wait.time(timeRefresh, 1)
end
function pauseFunc()
local buttonTable = self.getButtons()
local newLabel
suspendTint()
if buttonTable[5].label == 'Start' then
newLabel = 'Pause'
currentTimerID = Wait.time(timeRefresh, 1)
else
newLabel = 'Start'
Wait.stop(currentTimerID)
end
self.editButton({index = 4, label = newLabel})
end
function changeTint()
tint = {0,0,0}
direction = true
tintID = Wait.time(colorTint, 0.01, -1)
end
function colorTint()
if direction then
tint[1] = tint[1] + 0.01
tint[2] = tint[2] + 0.01
tint[3] = tint[3] + 0.01
if tint[1] >= 1 then
direction = not direction
end
else
tint[1] = tint[1] - 0.01
tint[2] = tint[2] - 0.01
tint[3] = tint[3] - 0.01
if tint[1] <= 0 then
direction = not direction
end
end
self.setColorTint(tint)
end
function suspendTint()
if tintID then
Wait.stop(tintID)
self.setColorTint({0,0,0,0})
tintID = nil
end
end
------------------User Interface
function refreshButtons()
self.clearButtons()
self.clearInputs()
local timeLabel
local buttonParam = {click_function = 'nullFunc', function_owner = self, label = '0:00', color = {0,0,0,1}, font_color = stringColorToRGB('Red'),
position = {0,0.2,-0.2}, width = 0, height = 0, font_size = 800}
self.createButton(buttonParam)
local buttonParam = {click_function = 'time30s', function_owner = self, label = '30s', font_color = BUTTON_FONT_COLOR, color = BUTTON_COLOR,
position = {COL[1],0.2,BUTTON_Z}, width = BUTTON_W, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Start the timer at 30 seconds.'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'time3m', function_owner = self, label = '3m', font_color = BUTTON_FONT_COLOR, color = BUTTON_COLOR,
position = {COL[2],0.2,BUTTON_Z}, width = BUTTON_W, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Start the timer at 3 minutes.'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'time6m', function_owner = self, label = '6m', font_color = BUTTON_FONT_COLOR, color = BUTTON_COLOR,
position = {COL[3],0.2,BUTTON_Z}, width = BUTTON_W, height = BUTTON_H, font_size = FONT_SIZE, tooltip = 'Start the timer at 6 minutes.'}
self.createButton(buttonParam)
local inputParam = {input_function = 'timeCustom', function_owner = self, font_color = BUTTON_FONT_COLOR, color = BUTTON_COLOR,
position = {COL[4],0.2,BUTTON_Z}, rotation = {0,0,0}, width = BUTTON_W, height = FONT_SIZE + 23, font_size = FONT_SIZE, value = 0, alignment = 3, validation = 3, tab = 1, tooltip = 'Start the timer at a custom number of minutes.'}
self.createInput(inputParam)
local buttonParam = {click_function = 'pauseFunc', function_owner = self, label = 'Pause', font_color = BUTTON_FONT_COLOR, color = BUTTON_COLOR,
position = {COL[5],0.2,BUTTON_Z}, width = BUTTON_W, height = BUTTON_H, font_size = 150, tooltip = 'Pause or start the timer.'}
self.createButton(buttonParam)
end