-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevents.lua
193 lines (162 loc) · 7.44 KB
/
events.lua
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
--[[
name: events.lua
description: Contains playerRespawn, playerDied, playerWon, playerLeft and playerJoined
]]--
-- PLAYER COLOR SETTER
eventPlayerRespawn = secureWrapper(function(playerName)
local ostime = os.time()
id = playerId(playerName)
setColor(playerName)
playerVars[playerName].hasDiedThisRound = true
playerVars[playerName].hasUsedRewind = false
-- UPDATE COOLDOWNS
cooldowns[playerName].lastJumpTime = ostime - JUMPCOOLDOWN
cooldowns[playerName].lastDashTime = ostime - DASHCOOLDOWN
cooldowns[playerName].lastRewindTime = ostime - 6000
cooldowns[playerName].checkpointTime = 0
cooldowns[playerName].canRewind = false
-- WHEN RESPAWNED, MAKE THE ABILITIES GREEN
removeImage(imgs[playerName].jumpButtonId)
imgs[playerName].jumpButtonId = addImage(JUMP_BTN_ON, "&1", JUMP_BTN_X, JUMP_BTN_Y, playerName)
removeImage(imgs[playerName].dashButtonId)
imgs[playerName].dashButtonId = addImage(DASH_BTN_ON, "&1", DASH_BTN_X, DASH_BTN_Y, playerName)
if playerStats[playerName].timesEnteredInHole < 1 and playerStats[playerName].timesDashed <= 10 and math.random() < 1/5 then
chatMessage("<CEP>> [int] [<O>Sensei</O>] "..translate(playerName, "senseiTip"..math.random(1, 3), playerName), playerName)
end
end, true)
eventPlayerDied = secureWrapper(function(playerName)
local id = playerId(playerName)
playerVars[playerName].rewindPos = {0, 0, false}
playerVars[playerName].hasDiedThisRound = true
playerVars[playerName].deathCount = playerVars[playerName].deathCount + 1
-- Remove rewind Mouse
if imgs[playerName].mouseImgId ~= nil then
removeImage(imgs[playerName].mouseImgId)
end
end, true)
-- PLAYER WIN
eventPlayerWon = secureWrapper(function(playerName, timeElapsed, timeElapsedSinceRespawn)
local id = playerId(playerName)
if imgs[playerName].mouseImgId ~= nil then
removeImage(imgs[playerName].mouseImgId)
end
-- SEND CHAT MESSAGE FOR PLAYER
local finishTime = timeElapsedSinceRespawn
if playerVars[playerName].hasDiedThisRound == false then
-- We don't count the starting 3 seconds
finishTime = finishTime - 3 * 100
end
chatMessage(translate(playerName, "finishedInfo", finishTime/100), playerName)
if playerName:sub(1,1) == "*" or playerStats[playerName].ban > 0 then return end
-- If we're a mod, then we don't count the win or if you rewind
if modRoom[playerName] == true or opList[playerName] == true then
return
elseif playerVars[playerName].hasUsedRewind == true then
tfm.exec.chatMessage(translate(playerName, "dontRewind"), playerName)
return
end
local beforeLevel = calculateLevel(playerName)[1]
if tfm.get.room.uniquePlayers > 2 and customRoom == false then
playerStats[playerName].timesEnteredInHole = playerStats[playerName].timesEnteredInHole + 1
if playerVars[playerName].playerFinished == false then
playerStats[playerName].mapsFinished = playerStats[playerName].mapsFinished + 1
if mapDiff == 6 then
playerStats[playerName].hardcoreMaps = playerStats[playerName].hardcoreMaps + 1
-- Check achievement
checkUnlock(playerName, "dashAcc", 5, "particleUnlock")
end
checkUnlock(playerName, "dashAcc", 2, "particleUnlock")
checkUnlock(playerName, "dashAcc", 4, "particleUnlock")
checkUnlock(playerName, "graffitiCol", 2, "graffitiColorUnlock")
playerWon = playerWon + 1
end
end
setPlayerScore(playerName, 1, true)
-- RESET TIMERS
playerVars[playerName].playerLastTime = finishTime
playerVars[playerName].playerFinished = true
playerVars[playerName].playerBestTime = math.min(playerVars[playerName].playerBestTime, finishTime)
--[[
If the player decides to leave and come back, we need to have his best time saved in a separate array.
This array will be used for stats at the end of the round, so it must work even if the player left,
came back, and had worse best time.
]]--
local foundvalue = false
for i = 1, #playerSortedBestTime do
if playerSortedBestTime[i][1] == playerName then
playerSortedBestTime[i][2] = math.min(playerVars[playerName].playerBestTime, playerSortedBestTime[i][2])
foundvalue = true
end
end
-- If this is the first time the player finishes the map, we take it as a best time.
if foundvalue == false then
playerSortedBestTime[#playerSortedBestTime + 1] = {playerName, playerVars[playerName].playerBestTime}
end
-- UPDATE "YOUR TIME"
ui.updateTextArea(5, "<p align='center'><font face='Lucida console' color='#ffffff'>"..translate(playerName, "lastTime", finishTime/100), playerName)
ui.updateTextArea(4, "<p align='center'><font face='Lucida console' color='#ffffff'>"..translate(playerName, "lastBestTime", playerVars[playerName].playerBestTime/100), playerName)
-- bestTime is a global variable for record
if finishTime <= bestTime then
bestTime = finishTime
if fastestplayer ~= -1 then
local oldFastestPlayer = fastestplayer
fastestplayer = playerName
setColor(oldFastestPlayer)
else
fastestplayer = playerName
end
-- send message to everyone in their language
for index, value in pairs(room.playerList) do
local _id = room.playerList[index].id
local message = translate(index, "newRecord", removeTag(fastestplayer).."<font size='-3'><g>"..fastestplayer:match("#%d+").."</g></font>", bestTime/100)
chatMessage(message, index)
--print(message)
end
if math.random() < 1/2 then
chatMessage("<CEP>> [int] [<O>Sensei</O>] "..translate(playerName, "senseiRecord"..math.random(1, 8), playerName), playerName)
end
end
if finishTime > worstTime then
slowestplayer = playerName
worstTime = finishTime
end
local afterLevel = calculateLevel(playerName)[1]
if afterLevel > beforeLevel then
for index, value in pairs(room.playerList) do
local message = translate(index, "levelUp", removeTag(playerName).."<font size='-3'><g>"..playerName:match("#%d+").."</g></font>", afterLevel)
chatMessage(message, index)
end
end
end, true)
function eventPlayerLeft(playerName)
for key, value in pairs(modList) do
chatMessage("<D><b>Ξ</b> "..playerName.." Left.</d>", key)
end
saveProgress(playerName)
inRoom[playerName] = nil
loaded[playerName] = nil
-- Throws an error if i retrieve playerId from room
local id = playerIds[playerName]
for player, data in pairs(room.playerList) do
removeTextArea(id, player)
end
if room.uniquePlayers == 2 then
for key, value in pairs(room.playerList) do
chatMessage(translate(key, "statsDontCount"), key)
end
end
-- We don't count souris
if string.find(playerName, '*') then
return
end
playerCount = playerCount - 1
end
-- WHEN SOMEBODY JOINS, INIT THE PLAYER
function eventNewPlayer(playerName)
inRoom[playerName] = true
loaded[playerName] = nil
initPlayer(playerName)
for key, value in pairs(modList) do
chatMessage("<D><b>Ξ</b> "..playerName.." Joined.</D>", key)
end
end