-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEditionVoter.ttslua
207 lines (181 loc) · 6.32 KB
/
EditionVoter.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
--[[
Edition Voter
Made by Sionar
--]]
------------------Constants
VERSION = '1.1.1'
COLORS_BBC = {Black = '[333333]', White = '[FFFFFF]', Brown = '[703A16]', Red = '[DA1917]', Orange = '[F3631C]', Yellow = '[E6E42B]', Green = '[30B22A]', Teal = '[20B09A]', Blue = '[1E87FF]', Purple = '[9F1FEF]', Pink = '[F46FCD]', Magenta = '[FF007F]', Lavender = '[967BB6]', Navy = '[616BD4]', Cyan = '[49D5FD]', Mint = '[89C381]', Lime = '[B8F161]', Peach = '[F1D4A2]', Coral = '[E29A8A]', Maroon = '[800000]', Silver = '[BEBEBE]'}
X_DIFF = 3.7
START_X = X_DIFF * 1.5 * -1
START_Z = -2
TOOL_BAG_GUID = '232b20'
------------------Variables
objects = {}
time = 0
currentTimerID = 0
enableVotes = false
showVotes = true
voters = {TB = {}, BM = {}, SV = {}, CU = {}}
startButtonLabel = 'Start Vote'
------------------Functions
function onLoad()
TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
assignObjects()
moveBoard()
Wait.time(makeVisible, 2, 1)
refreshUI()
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
end
function assignObjects()
objects.storageBag = getObjectFromGUID(TOOL_BAG_GUID)
end
function moveBoard()
self.setPositionSmooth({0,1.2,0 + TABLE_OFFSET})
self.setRotationSmooth({0,180,0})
self.setLock(true)
end
function makeVisible()
self.setInvisibleTo({})
end
function timeRefresh()
local minutes, seconds
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 = time})
if time == 0 then
self.editButton({index = 0, font_color = stringColorToRGB('Red')})
enableVotes = false
showVotes = true
refreshUI()
return
else
currentTimerID = Wait.time(timeRefresh, 1)
end
end
function startVote(clickedObject, playerColor)
if Player[playerColor].admin or playerColor == 'Black' then
for k,v in pairs(voters) do
voters[k] = {}
end
self.editButton({index = 0, label = '60', font_color = stringColorToRGB('Blue')})
time = 60
enableVotes = true
startTimer()
refreshUI()
end
end
function startTimer()
self.setLock(true)
Wait.stop(currentTimerID)
startButtonLabel = 'Reset Vote'
currentTimerID = Wait.time(timeRefresh, 1)
end
function inTable(table, value)
for k,v in pairs(table) do
if v == value then
return true
end
end
return false
end
function vote(player, value, id)
if enableVotes then
local color = nil
local players = Global.getTable('players')
local found = false
local votedOn = {}
local votedMsg = 'You voted on: '
for k,v in pairs(players) do
if v.steam_id == player.steam_id then
color = k
end
end
if color == nil then
return
end
for k,v in pairs(voters[value]) do
if v == color then
table.remove(voters[value], k)
found = true
end
end
if not found then
table.insert(voters[value], color)
end
if inTable(voters['TB'], color) then
table.insert(votedOn, '[D91A1A]Trouble Brewing[-]')
end
if inTable(voters['BM'], color) then
table.insert(votedOn, '[D9BB1A]Bad Moon Rising[-]')
end
if inTable(voters['SV'], color) then
table.insert(votedOn, '[9E21EF]Sects and Violets[-]')
end
if inTable(voters['CU'], color) then
table.insert(votedOn, '[AAAAAA]Custom[-]')
end
if not showVotes then
if next(votedOn) == nil then
player.print('You are currently voting on nothing.')
else
for k,v in pairs(votedOn) do
votedMsg = votedMsg .. v .. ', '
end
votedMsg = string.sub(votedMsg, 1, -3)
player.print(votedMsg)
end
end
refreshUI()
end
end
function destroySelf(clickedObject, playerColor)
if Player[playerColor].admin or playerColor == 'Black' then
objects.storageBag.putObject(self)
end
end
function toggleVoteVis(clickedObject, playerColor)
if Player[playerColor].admin or playerColor == 'Black' then
showVotes = not showVotes
refreshUI()
end
end
function refreshUI()
self.clearButtons()
local z = START_Z
local params
params = {click_function = 'null', function_owner = self, label = time, position = {0,0.1,7}, scale = {1.5, 1.5, 1.5}, width = 0, height = 0, font_size = 1000, font_color = {1,0,0}}
self.createButton(params)
local showVoteLabel, showVoteTooltip
if showVotes then
showVoteLabel = 'Hide Votes'
showVoteTooltip = 'Make votes hidden for all players'
else
showVoteLabel = 'Show Votes'
showVoteTooltip = 'Make votes shown for all players'
end
params = {click_function = 'toggleVoteVis', function_owner = self, label = showVoteLabel, tooltip = showVoteTooltip, font_color = stringColorToRGB('White'), color = {0,0,0,0.5},
position = {-3,0.1,-7.7}, width = 3500, height = 1500, font_size = 2000, scale = {0.5,0.5,0.5}}
self.createButton(params)
params = {click_function = 'startVote', function_owner = self, label = startButtonLabel, font_color = stringColorToRGB('White'), color = {0,0,0,0.5},
position = {3,0.1,-7.7}, width = 3500, height = 1500, font_size = 2000, scale = {0.5,0.5,0.5}}
self.createButton(params)
params = {click_function = 'destroySelf', function_owner = self, label = '☒', position = {8,0.1,-8}, scale = {1.5, 1.5, 1.5}, width = 600, height = 600, font_size = 400, font_color = {1,0.4,0.4}, color = {0,0,0,0.6}}
self.createButton(params)
x = START_X
if showVotes then
for k,v in pairs(voters) do
z = START_Z
for k1,v1 in pairs(v) do
params = {click_function = 'null', function_owner = self, label = COLORS_BBC[v1]..v1..'[-]', position = {x,0.1,z}, scale = {1, 1, 1}, width = 0, height = 0, font_size = 300,}
self.createButton(params)
z = z + 0.8
end
x = x + X_DIFF
end
end
end