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.

2 Likes

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.

1 Like

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:

22
“You do not have permission to do this”. gives such an error in the console when entering any command, it is not clear how to give yourself an admin or something else.

You shouldn’t need admin, You just need to load the file to the server, Restart the server so it loads and then it should work.

yes, I did this several times, and even with another timer mod, there seem to be no errors, but what kind of rights it is not clear. Maybe this is due to the fact that I’m running the server on a separate host? and other players have the ability to start a timer? Or only at the host directly?

Anyone should be able to start the countdown timer. As there’s no restrictions on the second code I posted, as I removed the requirements of the name itself. The very top post will need your BeamMP name adding to the file in order for it to work.

1 Like

Have you figured it out?

im working on a fork of this but adding a variable to you do /start then it does a countdown for that amount of time. do you want me to send you the finished version for you to upload. if so where.

Yea you can send it to discord?

never got it to work kept just doing the 5 second countdown no matter what i put in