-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMasterScript.lua
More file actions
306 lines (275 loc) · 11.8 KB
/
MasterScript.lua
File metadata and controls
306 lines (275 loc) · 11.8 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
master = "Dedax" -- CHANGE NAME HERE
masterpass = "å" -- Password to usurp the master (comma) button on keyboard)
pass = "ø" -- Password to get powers, press P.
-- the rest is just stuff
ui.addTextArea(666, "<ROSE>master:</ROSE> " .. master, nil, 660, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
itemlist = {[0] = "arrow", [1] = "small box", [2] = "large box", [3] = "small plank", [4] = "large plank", [6] = "ball", [7] = "trampoline", [10] = "anvil", [17] = "cannon", [23] = "bomb", [24] = "spirit", [28] = "balloon", [32] = "rune", [33] = "chicken", [34] = "snowball", [35] = "v arrow", [39] = "apple", [40] = "sheep", [45] = "ice plank", [46] = "choco plank", [54] = "frozen mouse", [57] = "cloud", [59] = "bubble", [60] = "tiny plank", [61] = "companion cube", [62] = "stable rune", [65] = "pufferfish", [67] = "giant plank", [68] = "triangle box", [69] = "s plank", [89] = "pumpkin", [90] = "tombstone", [601] = "pokeball"}
player = {}
telelist = ""
itemlimit = 3
powerasker = ""
helpstring = "<b>Keys:</b><br><b> H</b> - Get this window again<br><b> J, K and L</b> - shoot balls left, down and right respectively<br><b> C</b> - clear all objects<br><b> Spacebar</b> - Cycle through click types<br><b> X</b> - clear mouseclick"
for name, player in pairs(tfm.get.room.playerList) do
for keys, k in pairs({80, 188, 189}) do -- P, , (comma), - (hyphen)
tfm.exec.bindKeyboard(name, k, true, true)
end
end
function startBind(name)
for keys, k in pairs({80, 188, 189}) do -- P, , (comma), - (hyphen)
tfm.exec.bindKeyboard(name, k, true, true)
end
end
function unbindMaster()
for keys, k in pairs({66, 70, 71}) do -- B, F, G
tfm.exec.bindKeyboard(master, k, true, false)
end
end
function help(name)
if name == master then
ui.addPopup(1, 0, "<b>WOW! YOU'RE THE <R>MASTER!</R><br>SPECIAL MASTER ABILITIES:</b><br><b> G</b> - give power to someone<br><b> F</b> - remove powers from someone<br><b> B</b> - set item limit<br><br>" .. helpstring, master, 200, 100, 400, true)
else
ui.addPopup(1, 0, "<b>YOU NOW HAVE POWERS!</b><br><br>" .. helpstring, name, 200, 100, 400, true)
end
end
function givePowers(name)
if name == master then
for keys, k in pairs({66, 70, 71}) do -- B, F, G
tfm.exec.bindKeyboard(name, k, true, true)
end
ui.updateTextArea(666, "<a href='event:master'><ROSE>master:</ROSE> " .. master .. "</a>", master)
end
for keys, k in pairs({32, 67, 72, 74, 75, 76, 88}) do -- Space, C, H, K, J, L, X
tfm.exec.bindKeyboard(name, k, true, true)
end
system.bindMouse(name, true)
print(name .. " has powers!")
help(name)
player[name] = {mouse = "clear", target = name, spawntype = "601", spawns = {}, tp = "1", time = os.time()}
ui.addTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> clear</a>", name, 10, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
ui.addTextArea(2, "<a href='event:tplist'><VP>teleporting</VP> yourself</a>", name, 130, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
ui.addTextArea(4, "<a href='event:spawnselect'><VP>spawn:</VP> ball</a>", name, 280, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
end
givePowers(master)
function removePowers(name)
if name == master then
unbindMaster()
end
for keys, k in pairs({32, 67, 72, 74, 75, 76, 88}) do -- Space, C, H, K, J, L, X
tfm.exec.bindKeyboard(name, k, true, false) -- C
end
system.bindMouse(name, false)
print(name .. " got powers removed!")
ui.addPopup(1, 0, "<b>" .. master .. "</b> removed your powers :(", name, 400, 100, 200, true)
for i, o in pairs({1, 2, 3, 4, 5}) do
ui.removeTextArea(o, name)
end
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function finditem(a)
for id, name in pairs(itemlist) do
if a == id then return name
elseif a == name then return id
end
end
end
function shootBall(name, direction, x, y)
if tablelength(player[name]["spawns"]) >= itemlimit then
tfm.exec.removeObject(player[name]["spawns"][itemlimit])
end
if direction == "left" then
table.insert(player[name]["spawns"], 1, tfm.exec.addShamanObject(6, x - 20, y, 0, -25, 0, false))
end
if direction == "right" then
table.insert(player[name]["spawns"], 1, tfm.exec.addShamanObject(6, x + 20, y, 0, 25, 0, false))
end
if direction == "down" then
table.insert(player[name]["spawns"], 1, tfm.exec.addShamanObject(6, x, y + 10, 0, 0, 25, false))
end
end
function spawnItem(id, name, x, y)
if tablelength(player[name]["spawns"]) >= itemlimit then
tfm.exec.removeObject(player[name]["spawns"][itemlimit])
end
table.insert(player[name]["spawns"], 1, tfm.exec.addShamanObject(id, x, y, 0, 0, 0, false))
end
function cycleMouse(name)
if player[name]["mouse"] == "spawn" then
player[name]["mouse"] = "sp"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> sp</a>", name)
elseif player[name]["mouse"] == "sp" then
player[name]["mouse"] = "clear"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> clear</a>", name)
elseif player[name]["mouse"] == "clear" then
player[name]["mouse"] = "tp"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> tp</a>", name)
elseif player[name]["mouse"] == "tp" then
player[name]["mouse"] = "spawn"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> spawn</a>", name)
end
end
function eventKeyboard(name, key, down, x, y)
if key == 32 then -- Space
cycleMouse(name)
end
if key == 66 then -- B
ui.addPopup(6, 2, "Set item limit:", name, 400, 100, 200, true)
end
if key == 70 then -- F
ui.addPopup(4, 2, "Remove powers:", name, 400, 100, 200, true)
end
if key == 71 then -- G
ui.addPopup(3, 2, "Give powers to:", name, 400, 100, 200, true)
end
if key == 72 then -- H
help(name)
end
if key == 74 then -- J
shootBall(name, "left", x, y)
end
if key == 75 then -- K
shootBall(name, "down", x, y)
end
if key == 76 then -- L
shootBall(name, "right", x, y)
end
if key == 80 then -- P
ui.addPopup(1, 2, "What's the password?", name, 400, 100, 200, true)
end
if key == 88 then -- X
player[name]["mouse"] = "clear"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> clear</a>", name)
end
if key == 67 then -- C
remove = {}
for i, o in pairs(tfm.get.room.objectList) do
table.insert(remove, i)
end
for _, n in pairs(remove) do
tfm.exec.removeObject(n)
end
end
if key == 189 then -- -
ui.addPopup(4, 0, "You asked " .. master .. " for powers!", name, 400, 100, 200, true)
ui.addPopup(5, 1, "Give " .. name .. " powers?", master, 400, 100, 200, true)
powerasker = name
end
if key == 188 then -- ,
ui.addPopup(7, 2, "What's the master password?", name, 400, 100, 200, true)
end
end
function eventTextAreaCallback(textAreaID, playerName, callback)
if textAreaID == 1 then
cycleMouse(playerName)
end
if textAreaID == 2 then
ui.removeTextArea(2, playerName)
playerCount = tablelength(tfm.get.room.playerList)
local areasize = 35 + playerCount * 17
telelist = ""
for name, player in pairs(tfm.get.room.playerList) do
telelist = telelist .. "<a href='event:" .. name .. "'>" .. name .. "</a><br>"
end
ui.addTextArea(3, "Teleport:<br><br><br>" .. telelist, playerName, 130, -17, 110, areasize, 0x000000, 0x222222, 0.6, true)
end
if textAreaID == 3 then
ui.removeTextArea(3, playerName)
player[playerName]["mouse"] = "tp"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> tp</a>", playerName)
player[playerName]["target"] = callback
ui.addTextArea(2, "<a href='event:tplist'><VP>teleporting</VP> " .. callback .. "</a>", playerName, 130, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
end
if textAreaID == 4 then
ui.removeTextArea(4, playerName)
ui.addTextArea(5, "spawn item:<br><br><br><a href='event:601'>ball</a><br><a href='event:10'>anvil</a><br><a href='event:59'>bubble</a><br><a href='event:68'>triangle</a><br><br><a href='event:ask'>enter id/name</a>", playerName, 280, -17, 110, 145, 0x000000, 0x222222, 0.6, true)
end
if textAreaID == 5 then
if callback == "ask" then
ui.addPopup(9, 2, "Set spawn id/name: ", playerName, 400, 100, 200, true)
ui.removeTextArea(5, playerName)
ui.addTextArea(4, "<VP>spawn:</VP>", playerName, 280, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
else
ui.removeTextArea(5, playerName)
player[playerName]["spawntype"] = callback
ui.addTextArea(4, "<a href='event:spawnselect'><VP>spawn:</VP> " .. finditem(tonumber(callback)) .. "</a>", playerName, 280, -17, 0, 0, 0x000000, 0x222222, 0.3, true)
player[playerName]["mouse"] = "spawn"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> spawn</a>", playerName)
end
end
if textAreaID == 666 then
ui.addPopup(8, 2, "Give master to:", master, 400, 100, 200, true)
end
end
function eventMouse(name, x, y)
if player[name]["mouse"] == "tp" then
if player[name]["time"] < os.time() - 5000 then
player[name]["tp"] = 1
end
if player[name]["tp"] == 1 then
tfm.exec.movePlayer(player[name]["target"], x, y, false, 0, 1, false)
player[name]["time"] = os.time()
player[name]["tp"] = 0
end
elseif player[name]["mouse"] == "sp" then
tfm.exec.explosion(x, y, 20, 100, false)
elseif player[name]["mouse"] == "spawn" then
spawnItem(player[name]["spawntype"], name, x, y)
end
end
function eventPopupAnswer(popupID, playerName, answer)
if popupID == 1 and answer == pass then
givePowers(playerName)
elseif popupID == 1 then
print(playerName .. " tried to guess the pass: " .. answer)
end
if popupID == 3 then
givePowers(answer:gsub("^%l", string.upper))
end
if popupID == 4 then
removePowers(answer:gsub("^%l", string.upper))
end
if popupID == 5 and answer == "yes" then
givePowers(powerasker)
ui.addPopup(1, 0, "Wow, you were given powers!!!", powerasker, 400, 100, 200, true)
elseif popupID == 5 and answer == "no" then
ui.addPopup(1, 0, "Sorry :))) noob", powerasker, 400, 100, 200, true)
end
if popupID == 6 then
itemlimit = tonumber(answer)
end
if popupID == 7 and answer == masterpass then
ui.addPopup(1, 0, "Oh wow, " .. playerName .. " usurped you as master!", master, 400, 100, 200, true)
unbindMaster()
master = playerName
ui.updateTextArea(666, "<ROSE>master:</ROSE> " .. master, nil)
givePowers(master)
elseif popupID == 7 then
print(playerName .. " tried to guess the masterpass: " .. answer)
end
if popupID == 8 then
ui.addPopup(1, 0, "You honourably passed on the master status to " .. answer:gsub("^%l", string.upper) .. " :)", master, 400, 100, 200, true)
ui.addPopup(1, 0, "<b>WOW! " .. master .. " gave you master powers!<br>SPECIAL MASTER ABILITIES:</b><br>G - Give power to someone<br>F - Remove powers from someone<br>B - Set item limit<br><br>" .. helpstring, answer:gsub("^%l", string.upper), 200, 100, 400, true)
master = answer:gsub("^%l", string.upper)
ui.updateTextArea(666, "<ROSE>master:</ROSE> " .. master, nil)
givePowers(master)
end
if popupID == 9 and tonumber(answer) == nil then
answer = finditem(string.lower(answer))
player[playerName]["spawntype"] = answer
ui.updateTextArea(4, "<a href='event:spawnselect'><VP>spawn:</VP> " .. finditem(answer) .. "</a>", playerName)
player[playerName]["mouse"] = "spawn"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> spawn</a>", playerName)
elseif popupID == 9 then
answer = finditem(tonumber(answer))
player[playerName]["spawntype"] = finditem(answer)
ui.updateTextArea(4, "<a href='event:spawnselect'><VP>spawn:</VP> " .. answer .. "</a>", playerName)
player[playerName]["mouse"] = "spawn"
ui.updateTextArea(1, "<a href='event:clicktype'><VP>click type:</VP> spawn</a>", playerName)
end
end
function eventNewPlayer(name)
startBind(name)
end