· 6 years ago · Feb 24, 2020, 06:02 PM
1--[[
2 Based on "Twitch Plays Pokemon" event and the "Haunted Doll" script.
3
4 The mice must control the shaman using the WASD / Arrow keys to bring her to the cheese and the hole.
5]]
6
7local sham, shamList = "", {}
8local moveFactor = 10
9
10local leaders = {["Tomstoms#0000"] = true, ["Onkei#0000"] = true, ["Santaishcool#0000"] = true, ["Ninjafood#0000"] = true, ["Pie#0000"] = true}
11
12local KEYS = {
13 ["0"] = "влево",
14 ["1"] = "вверх",
15 ["2"] = "вправо",
16 ["3"] = "вниз"
17}
18
19-- Aliases
20
21local changeTime = tfm.exec.setGameTime
22local teleport = tfm.exec.movePlayer
23
24-- Custom Functions
25
26function bindKeys(n, bool)
27 --[[
28 Binds the required keyboard keys to the selected player.
29 ]]
30 bool = bool or true
31
32 for key in next, KEYS do
33 system.bindKeyboard(n, tonumber(key), true, bool)
34 end
35end
36
37function disableEffects()
38 tfm.exec.disableAfkDeath(true)
39 tfm.exec.disableAllShamanSkills(true)
40 tfm.exec.disableAutoNewGame(true)
41 tfm.exec.disableAutoScore(false)
42 tfm.exec.disableAutoShaman(true)
43 tfm.exec.disableAutoTimeLeft(true)
44 tfm.exec.disableDebugCommand(true)
45 tfm.exec.disableMinimalistMode(false)
46 tfm.exec.disableMortCommand(true)
47 tfm.exec.disablePhysicalConsumables(true)
48 tfm.exec.disablePrespawnPreview(true)
49 tfm.exec.disableWatchCommand(false)
50end
51
52function globalMessage(message, target)
53 tfm.exec.chatMessage(message, target)
54 soupbot(message, target)
55end
56
57function main()
58 --[[
59 Initialization function when the script starts.
60 ]]
61 disableEffects()
62 loadMap()
63end
64
65local mapRotations = {7, 17}
66function loadMap()
67 tfm.exec.newGame("#" .. mapRotations[math.random(#mapRotations)], math.random() <= 0.5)
68end
69
70function onkOrderingSystem(onkList, playerList, playerToFilter)
71
72 if #onkList == 0 then
73
74 local newPlayerList = {}
75
76 for name in next, playerList do
77 newPlayerList[#newPlayerList + 1] = name
78 end
79
80 for i = 1, #newPlayerList, 1 do
81 local index = math.random(#newPlayerList)
82 local name = newPlayerList[index]
83
84 onkList[#onkList + 1] = name
85 table.remove(newPlayerList, index)
86 end
87 end
88
89 local onkSelected = onkList[1]
90
91 if onkSelected == playerToFilter then
92 onkSelected = onkList[2]
93 table.remove(onkList, 2)
94
95 onkList[#onkList + 1] = onkSelected
96 else
97 table.remove(onkList, 1)
98
99 onkList[#onkList + 1] = onkSelected
100 end
101
102 return onkSelected
103end
104
105local player = {
106 --[[
107 Set of functions to un/blind a player.
108 ]]
109 blind = function(n)
110 ui.addTextArea(1, "", n, -2500, -2500, 5000, 5000, 0x0A0A0A, 0x0A0A0A, 1, true)
111 end,
112
113 unblind = function(n)
114 ui.removeTextArea(1, n)
115 end
116}
117
118function table.copy(t1)
119 local t2 = {}
120
121 for k, v in next, t1 do
122 t2[k] = v
123 end
124
125 return t2
126end
127
128local trackerData = ""
129local tracker = {
130 --[[
131 Set of functions to track who pressed what key.
132 ]]
133 add = function(n, pressed)
134 --[[
135 Adds the player's key pressed data to the trackerData table.
136 ]]
137 trackerData = n .. " нажал(а) " .. KEYS[tostring(pressed)] .. ".<br>" .. trackerData
138 end,
139
140 popup = function()
141 --[[
142 Shows all the tracker data into a textArea popup (top right).
143 ]]
144 ui.addTextArea(2, "<p align='center'>Трекер</p>" .. trackerData, nil, 520, 20, 260, 200, 0x324650, 0x89A7F5, 0.4, true)
145 end,
146}
147
148function soupbot(message, target)
149 ui.addTextArea(0, "<v>[Soupbot] <n>" .. message, target, 7, 380, nil, 20, 0x324650, 0x000000, 0.7, true)
150end
151
152-- TFM API Functions
153
154function eventNewGame()
155 -- Clearing the tracker data.
156 trackerData = ""
157
158 -- Don't blind the old shaman.
159 player.unblind(sham)
160
161 -- Select a new shaman.
162 sham = onkOrderingSystem(shamList, tfm.get.room.playerList)
163 bindKeys(sham, false)
164 player.blind(sham)
165 tfm.exec.setShaman(sham)
166 ui.setShamanName(sham)
167
168 globalMessage("Вместе с другими мышами Вы должны управлять шаманом, нажимая на стрелки или WASD!")
169 globalMessage("Вы - шаман! Вы были ослеплены, поэтому другие мыши должны провести вас к сыру!", sham)
170 local numOfPlayers = 0
171
172 -- Binding keys for other players.
173 for n in next, tfm.get.room.playerList do
174 if n ~= sham then
175 bindKeys(n)
176 tfm.exec.killPlayer(n)
177
178 numOfPlayers = numOfPlayers + 1
179 end
180 end
181
182 -- Setting the move factor for controlling the shaman.
183 if numOfPlayers <= 2 then moveFactor = 30 elseif numOfPlayers <= 5 then moveFactor = 20 else moveFactor = 10 end
184end
185
186function eventChatCommand(n, cmd)
187 if (n == sham or leaders[n]) and cmd == "skip" then
188 changeTime(3)
189 end
190end
191
192function eventKeyboard(n, key, down, x, y)
193 if n == sham then
194 return
195 end
196
197 tracker.add(n, key)
198
199 if key == 0 then
200 teleport(sham, 0, 0, true, -moveFactor, 0, true)
201 elseif key == 2 then
202 teleport(sham, 0, 0, true, moveFactor, 0, true)
203 elseif key == 3 then
204 teleport(sham, 0, 0, true, 0, moveFactor, true)
205 elseif key == 1 then
206 teleport(sham, 0, 0, true, 0, -moveFactor, true)
207 end
208end
209
210function eventLoop(passed, left)
211 -- Constantly updating and showing the tracker popup.
212 tracker.popup()
213
214 if left <= 0 then
215 loadMap()
216 end
217end
218
219function eventPlayerDied(n)
220 if n == sham then
221 player.unblind(n)
222 changeTime(5)
223 globalMessage("Шаман умер! Что с вами не так, народ?")
224 globalMessage("Мыши смогли привести вас только к смерти!", n)
225 end
226end
227
228function eventPlayerGetCheese(n)
229 if n == sham then
230 globalMessage("Шаман получил сыр! Теперь вы должны проводить его к норе!")
231 globalMessage("Мыши помогли Вам взять сыр!", n)
232 end
233end
234
235function eventPlayerLeft(n)
236 if n == sham then
237 changeTime(5)
238 globalMessage("Шаман покинул комнату! [F]")
239 end
240
241 local listCopy = table.copy(shamList)
242
243 for index, name in next, listCopy do
244 if name == n then
245 table.remove(shamList, index)
246 end
247 end
248end
249
250function eventNewPlayer(n)
251 shamList[#shamList + 1] = n
252end
253
254function eventPlayerWon(n)
255 if n == sham then
256 player.unblind(n)
257 changeTime(5)
258 globalMessage("Вы успешно провели шамана к норе! Так держать!")
259 globalMessage("Вас успешно привели к норе!", n)
260 end
261end
262
263function eventSummoningEnd(n, object, x, y, angle, velx, vely, other)
264 -- Making sure the shaman can't spawn any objects.
265 tfm.exec.removeObject(other.id)
266end
267
268main()