forked from Robotex/transformice-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItalian.lua
More file actions
423 lines (382 loc) · 13.7 KB
/
Italian.lua
File metadata and controls
423 lines (382 loc) · 13.7 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
-- Configuration settings
local g_config = {
admins = {"Junny1992#0000", "Ruka#0823"},
spawn = { x = 0, y = 0 },
spawnAreas = {
SECOND_FLOOR = {x = 855, y = 162},
START = {x = 20, y = 370}
},
toysAreas = {
{x1 = 1458, y1 = 297, x2 = 1590, y2 = 370}
},
packingAreas = {
{x1 = 954, y1 = 315, x2 = 1033, y2 = 345},
{x1 = 1114, y1 = 315, x2 = 1228, y2 = 345}
},
dropOffAreas = {
{x1 = 109, y1 = 285, x2 = 284, y2 = 384}
},
minigameChars = {"q","u","o","p","f","g","h","j","k","l","z","x","c","v","b","n","m"},
map = "@7550816",
doorId = 10
}
-- Local globals
local g_players = {}
local g_lastTick = 0
local g_timers = {}
local g_gameState = 0
local g_textAreaIds = {
countdown = 1,
inventory = 2,
toast = 3,
scoreboard = 4,
hint = 5
}
-- Utilities
local function isAdministrator(playerName)
for _, adminName in ipairs(g_config.admins)
do
if adminName == playerName then
return true
end
end
return false
end
local function addTimer(callback, startDelay, loop, ...)
if callback == nil then
print ("Warning: null callback in addTimer")
return
end
local timer = {
callback = callback,
startDelay = startDelay,
loop = loop,
args = ...,
createdTime = g_lastTick,
expired = false
}
table.insert(g_timers, timer)
return #g_timers
end
local function showToast(text, duration, playerName)
ui.addTextArea(g_textAreaIds.toast, text, playerName, 300, 250, 200, 20, 0x324650, 0x000000, 0.6, true)
addTimer(function()
ui.removeTextArea(g_textAreaIds.toast, playerName)
end, duration, false)
end
-- Script core logic
local function addPlayer(playerName)
local player = g_players[playerName]
if player == nil then
print("Nuovo giocatore: " .. playerName)
player = {
name = playerName,
carrying = 0,
score = 0,
minigame = {
nextKeyCode = 0,
combo = 0
}
}
g_players[playerName] = player
end
tfm.exec.setPlayerScore(playerName, player.score, false)
system.bindKeyboard(playerName, 32, true, true)
system.bindKeyboard(playerName, 1, false, true)
system.bindKeyboard(playerName, 2, false, true)
system.bindKeyboard(playerName, 3, false, true)
system.bindKeyboard(playerName, 4, false, true)
system.bindKeyboard(playerName, 1, true, true)
system.bindKeyboard(playerName, 2, true, true)
system.bindKeyboard(playerName, 3, true, true)
system.bindKeyboard(playerName, 4, true, true)
for _, char in ipairs(g_config.minigameChars) do
local keyCode = string.byte(string.upper(char), 1)
system.bindKeyboard(playerName, keyCode, true, true)
end
end
local function resetPlayer(playerName)
local player = g_players[playerName]
if player ~= nil then
player.nextKeyCode = 0
player.carrying = 0
player.combo = 0
eventNewPlayer(playerName)
tfm.exec.killPlayer(playerName)
end
end
local function removePlayer(playerName)
local player = g_players[playerName]
if player ~= nil then
ui.removeTextArea(g_textAreaIds.inventory, playerName)
system.bindKeyboard(playerName, 32, true, false)
g_players[playerName] = nil
end
end
local function increasePlayerScore(playerName)
local player = g_players[playerName]
if player ~= nil then
g_players[playerName].score = g_players[playerName].score + 1
tfm.exec.setPlayerScore(playerName, g_players[playerName].score, false)
end
end
local function isPlayer(playerName)
return g_players[playerName] ~= nil
end
local function openDoor()
tfm.exec.removePhysicObject(g_config.doorId)
end
local function startGame()
g_gameState = 2
tfm.exec.setGameTime(300)
openDoor()
end
local function resetGame()
for _, id in pairs(g_textAreaIds) do
ui.removeTextArea(id, nil)
end
tfm.exec.newGame(g_config.map)
tfm.exec.setUIMapName("Greenwolves - Natale 2018")
tfm.exec.setGameTime(0)
g_gameState = 0
g_players = {}
g_config.spawn = g_config.spawnAreas.START
for playerName, _ in pairs(tfm.get.room.playerList)
do
eventNewPlayer(playerName)
tfm.exec.setPlayerScore(playerName, 0, false)
tfm.exec.killPlayer(playerName)
end
end
local function endGame()
local highscores = {
[1] = {},
[2] = {},
[3] = {}
}
local scoreboard = {}
g_gameState = 3
g_config.spawn = g_config.spawnAreas.SECOND_FLOOR
for playerName, _ in pairs(tfm.get.room.playerList)
do
tfm.exec.killPlayer(playerName)
end
for playerName, player in pairs(g_players)
do
table.insert(scoreboard, player)
end
table.sort(scoreboard, function(a,b) return a.score>b.score end)
local highscorePosition = 1
for i=1, #scoreboard do
print ("[" .. scoreboard[i].score .. "] " .. scoreboard[i].name)
table.insert(highscores[highscorePosition], scoreboard[i])
if i < #scoreboard then
if scoreboard[i + 1].score ~= scoreboard[i].score then
highscorePosition = highscorePosition + 1
end
end
if highscorePosition > 3 then
break
end
end
local scoreboardText = "1. "
for _, player in ipairs(highscores[1]) do
scoreboardText = scoreboardText .. "[" .. player.name .. "]"
end
scoreboardText = scoreboardText .. "<br>2. "
for _, player in ipairs(highscores[2]) do
scoreboardText = scoreboardText .. "[" .. player.name .. "]"
end
scoreboardText = scoreboardText .. "<br>3. "
for _, player in ipairs(highscores[3]) do
scoreboardText = scoreboardText .. "[" .. player.name .. "]"
end
ui.addTextArea(g_textAreaIds.scoreboard, scoreboardText, nil, 280, 250, 240, 80, 0x324650, 0x000000, 1, true)
end
local function startCountdown()
g_gameState = 1
g_config.spawn = g_config.spawnAreas.START
for playerName, player in pairs(g_players) do
-- tfm.exec.killPlayer(playerName)
end
local headerText = "<VP><p align=\"center\"><B>Siete pronti?</B>\n\n<CH>"
local textAreaId = g_textAreaIds.countdown;
ui.addTextArea(textAreaId, headerText, nil, 300, 270, 200, 60, 0x324650, 0x000000, 1, true)
local function countdown(secondsLeft)
if (secondsLeft > 0) then
ui.updateTextArea(textAreaId, headerText .. secondsLeft, nil)
addTimer(countdown, 1000, false, secondsLeft - 1)
else
ui.updateTextArea(textAreaId, headerText .. "VIA!!!", nil)
addTimer(function()
ui.removeTextArea(textAreaId, nil)
end, 1000, false)
startGame()
end
end
countdown(3)
end
local function isInsideAreas(areas, xPlayerPosition, yPlayerPosition)
for _, area in ipairs(areas) do
if area.x1 < xPlayerPosition and xPlayerPosition < area.x2 and area.y1 < yPlayerPosition and yPlayerPosition < area.y2 then
return true
end
end
return false
end
local function init()
tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAutoScore(true)
tfm.exec.disableAutoTimeLeft(true)
tfm.exec.disableAfkDeath(true)
tfm.exec.disableAllShamanSkills(true)
resetGame()
print("Script inizializzato!")
end
-- Game delegates
local lastColor = 0x00
function eventChatCommand(playerName, message)
if isAdministrator(playerName) then
if message == "start" then
startCountdown(5)
elseif message == "endgame" then
endGame()
elseif message == "resetgame" then
resetGame()
elseif message == "abracadabra" then
openDoor()
elseif message == "respawn" then
tfm.exec.respawnPlayer(playerName)
elseif message == "debug" then
addPlayer(playerName)
increasePlayerScore(playerName)
elseif message == "win" then
tfm.exec.playerVictory(playerName)
elseif message == "exit" then
system.exit()
end
end
if message == "reset" then
resetPlayer(playerName)
end
end
function eventKeyboard(playerName, keyCode, down, xPlayerPosition, yPlayerPosition)
local player = g_players[playerName]
if isInsideAreas(g_config.toysAreas, xPlayerPosition, yPlayerPosition) then
if player and down == true and keyCode == 32 then
if player.carrying == 0 then
player.carrying = 1
ui.addTextArea(g_textAreaIds.inventory, "<p align=\"center\">Trasporti un giocattolo!", playerName, 5, 20, 200, 30, 0x324650, 0x000000, 1, true)
print(playerName .. " ha raccolto un giocattolo")
return
elseif player.carrying == 1 then
showToast("<p align=\"center\">Hai già un giocattolo nell’inventario!", 1000, playerName)
return
end
end
end
if isInsideAreas(g_config.packingAreas, xPlayerPosition, yPlayerPosition) then
if player then
if player.minigame.nextKeyCode > 0 and (keyCode == 1 or keyCode == 2 or keyCode == 3 or keyCode == 4) and player.carrying == 1 then
ui.addTextArea(g_textAreaIds.hint, "<p align=\"center\">Premi " .. string.char(player.minigame.nextKeyCode), playerName, 300, 250, 200, 20, 0x324650, 0x000000, 0.6, true)
elseif down == true and keyCode == 32 then
if player.carrying == 1 and player.minigame.nextKeyCode == 0 then
player.minigame.nextKeyCode = string.byte(string.upper(g_config.minigameChars[math.random(#g_config.minigameChars)]), 1)
ui.addTextArea(g_textAreaIds.hint, "<p align=\"center\">Premi " .. string.char(player.minigame.nextKeyCode), playerName, 300, 250, 200, 20, 0x324650, 0x000000, 0.6, true)
elseif player.carrying == 2 then
showToast("<p align=\"center\">Hai già un regalo nell’inventario!", 1000, playerName)
return
end
elseif down == true and keyCode == player.minigame.nextKeyCode and player.carrying == 1 then
player.minigame.combo = player.minigame.combo + 1
if player.minigame.combo > 5 then
player.minigame.nextKeyCode = 0
player.minigame.combo = 0
player.carrying = 2
tfm.exec.giveCheese(playerName)
ui.removeTextArea(g_textAreaIds.inventory, playerName)
ui.removeTextArea(g_textAreaIds.hint, playerName)
print(playerName .. " ha impacchettato il regalo")
else
player.minigame.nextKeyCode = string.byte(string.upper(g_config.minigameChars[math.random(#g_config.minigameChars)]), 1)
ui.updateTextArea(g_textAreaIds.hint, "<p align=\"center\">Premi " .. string.char(player.minigame.nextKeyCode), playerName)
end
elseif down == true and player.minigame.nextKeyCode > 0 and keyCode ~= player.minigame.nextKeyCode and player.carrying == 1 then
player.minigame.combo = 0
player.carrying = 0
player.minigame.nextKeyCode = 0
ui.removeTextArea(g_textAreaIds.inventory, playerName)
ui.removeTextArea(g_textAreaIds.hint, playerName)
showToast("<p align=\"center\">Peccato! Hai rotto il giocattolo :(", 1000, playerName)
print(playerName .. " ha rovinato il regalo")
end
end
else
if player and player.carrying == 1 and player.minigame.nextKeyCode > 0 then
ui.removeTextArea(g_textAreaIds.hint, playerName)
end
end
if isInsideAreas(g_config.dropOffAreas, xPlayerPosition, yPlayerPosition) then
if player and down == true and keyCode == 32 then
if player.carrying == 2 then
player.carrying = 0
tfm.exec.removeCheese(playerName)
increasePlayerScore(playerName)
print(playerName .. " ha consegnato il regalo")
showToast("<p align=\"center\">Regalo consegnato!", 3000, playerName)
return
end
end
end
end
function eventNewPlayer(playerName)
if isAdministrator(playerName) then
tfm.exec.setNameColor(playerName, 0x009DFF)
if isPlayer(playerName) then
addPlayer(playerName)
end
else
addPlayer(playerName)
end
local player = tfm.get.room.playerList[playerName]
if player and player.isDead then
tfm.exec.respawnPlayer(playerName)
print("eventNewPlayer(\"" .. playerName .."\") - score:" .. player.score)
end
if g_gameState == 2 then
openDoor()
end
end
function eventPlayerDied(playerName)
tfm.exec.respawnPlayer(playerName)
end
function eventPlayerRespawn(playerName)
tfm.exec.movePlayer(playerName, g_config.spawn.x, g_config.spawn.y, false, 0, 0, false)
end
function eventLoop(currentTime, timeRemaining)
g_lastTick = currentTime
--
if g_gameState == 2 and timeRemaining <= 0 then
endGame()
end
-- Timers handling
for i=1, #g_timers
do
local timer = g_timers[i]
timer.expired = (currentTime - timer.createdTime - timer.startDelay >= 0)
if timer.expired then
timer.callback(timer.args)
if timer.loop then
timer.createdTime = currentTime
timer.expired = false
end
end
end
for i=#g_timers,1,-1 do
if g_timers[i].expired then
table.remove(g_timers, i)
end
end
end
init()