Race Countdown Timer

Myself and a friend were doing some community races, but we were having to do the countdown verbally which resulted in many different start times, So I along with the help of my friend have made a Countdown timer for race starts. All you need to do is type in “/start” in the chatbox and it’ll do the countdown for you.

function onInit()
    print("Loading Race Management Done!")
    MP.RegisterEvent("onChatMessage", "onChatMessage")
    MP.RegisterEvent("onCountdown", "countdown")
end



function onChatMessage(senderID, name, message)
    if name == "YOURNAMEHERE" then
        if message == "/start" then
            MP.SendChatMessage(-1, "Race is about to start!")
            MP.TriggerGlobalEvent("onCountdown")
            return 1
        end
    end
end

function countdown()
    
local length = 5
    
    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
end

This is the one for Single person usage, You just change “YOURNAMEHERE” to your BeamMP name.

I also have one that is open for anyone to use, There’s just 2 lines been removed from the above code.

function onInit()
    print("Loading Race Management Done!")
    MP.RegisterEvent("onChatMessage", "onChatMessage")
    MP.RegisterEvent("onCountdown", "countdown")
end



function onChatMessage(senderID, name, message)
    if message == "/start" then
        MP.SendChatMessage(-1, "Race is about to start!")
        MP.TriggerGlobalEvent("onCountdown")
        return 1
    end
end

function countdown()
    
local length = 5
    
    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
end

To use this, You need to create a folder in Resources/Server and call it something like “Countdown” then place the Lua file within that Countdown folder and reload the server.

1 Like

Is it possible to edit this so the flood starts after the timer ends?

Im trying to get the countdown timer to work, but nothning happens?

Ive tried to make this work several times, but i cannot succed. CAn anyone guide a noob how to make the lua file work???

I’m not entirely sure on how to edit it so the flood starts after the timer…

With regards to making it work, You need to upload it to the BeamMP server using FTP, Placing the .lua file in the BeamMP folder /Resources/Server folder, Creating a new folder in there called “Countdown” or something to that extent, Then placing the .lua file in there.

After you’ve done that and restarted the server to load the .lua file, You then have to get people lined up on a starting grid manually, Then anyone can type in the chat box: /start

Which will start the countdown.

It doesent start, its like it doesent recognize the command /start or /countdown
image

Found the error… .lua was missing from the file… Thank you :slight_smile: