/
BTNCountdown.lua
44 lines (37 loc) · 1.3 KB
/
BTNCountdown.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
local countdownStarted = false
function onInit()
print("BTNCountdown Loaded!")
MP.RegisterEvent("onChatMessage", "onChatMessage")
MP.RegisterEvent("onCountdownRequested", "startCountdown")
end
function onChatMessage(senderID, name, message)
if message == "/countdown" then
if not countdownStarted then
MP.SendChatMessage(-1, "Race is about to start!")
MP.TriggerGlobalEvent("onCountdownRequested")
else
MP.SendChatMessage(senderID, "Countdown is already in progress.")
end
return 1
elseif message == "/coords" then
displayCurrentCoordinates()
return 1
end
end
function startCountdown()
-- Ensure countdown is not started multiple times
if not countdownStarted then
countdownStarted = true
local length = 5 --Adjust this to increase the amount of time allowed for countdown
for i = 0, length do
if i < length then
MP.SendChatMessage(-1, "Race Starts in " .. length - i)
end
if i == length then
MP.SendChatMessage(-1, "Go!")
end
MP.Sleep(1000)
end
countdownStarted = false -- Reset countdown flag after countdown finishes
end
end