Jump to content

countdown script


jkub

Recommended Posts

Can someone please give me a countdown script... like one for a race.

and the command to start it would be /count

like

5

4

3

2

1

GO!

count=5 
  
function countdown() 
    if count>0 then 
        outputChatBox(count .. "") 
        count=count-1 
        setTimer(count,1000,1) 
    else 
        outputChatBox("GOOO!!!") 
    end 
end 

(not tested)

Link to comment

try this:

  
function countdownRec(count) 
      if (count > 0) then 
          outputChatBox(tostring(count), getRootElement(), 255, 255, 255) 
          setTimer(countdownRec, 1000, 1, count-1) 
      else 
          outputChatBox("Go Go Go!!!", getRootElement(), 255, 255, 255) 
      end 
end 
  
function countdown() 
      countdownRec(5) 
end 
addCommandHandler("count", countdown) 
  

Link to comment

Or you can try this if you like a cool text display :P . This also makes sure you can't initiate a count down when one is still running.

  
local root = getRootElement() 
local count = 0 
local billboard = false 
local numbers = false 
local timer = false 
  
function isTimer(theTimer) 
  for _, pTimer in ipairs(getTimers(2500)) do 
    if (pTimer == theTimer) then 
      return true 
    end 
  end 
  return false 
end 
  
function countClean() 
  for _, player in ipairs(getElementsByType("player", root)) do 
    textDisplayRemoveObserver(billboard, player) 
  end 
  textDestroyTextItem(numbers) 
  textDestroyDisplay(billboard) 
  billboard, numbers = false, false 
  count = 0 
end 
  
function playSoundForAll(sound) 
  for _, player in ipairs(getElementsByType("player", root)) do 
    playSoundFrontEnd(player, sound) 
  end 
end 
  
function countStart() 
  if (count == 5) then 
    billboard = textCreateDisplay() 
    numbers = textCreateTextItem("", 0.5, 0.5) 
    if (billboard and numbers) then 
      textItemSetScale(numbers, 2.5) 
      textItemSetPriority(numbers, "high") 
      textDisplayAddText(billboard, numbers) 
      for _, player in ipairs(getElementsByType("player", root)) do 
        textDisplayAddObserver(billboard, player) 
      end 
    end 
  end 
  if (billboard and numbers) then 
    if (count == 0) then 
      count = -1 
      textItemSetText(numbers, "GO!") 
      playSoundForAll(45) 
      timer = setTimer(countClean, 2500, 1) 
    end 
    if (count > 0) then 
      textItemSetText(numbers, tostring(count)) 
      playSoundForAll(43) 
      count = count - 1 
      timer = setTimer(countStart, 1000, 1) 
    end 
  end 
end 
  
function checkState(playerSource, commandName) 
  if (string.lower(commandName) == "/count" and count == 0 and not isTimer(timer)) then 
    if (playerSource) then 
      outputChatBox("* Countdown initiated by " .. getClientName(playerSource)) 
    end 
    count = 5 
    countStart() 
  end 
end 
  
addCommandHandler("/count", checkState, false) 
  

Link to comment
  • 3 weeks later...

  } 
  elseif (!count* iswm $3) {  
    mta.text $1 Countdown: 3...  
    .timer 1 2 mta.text $1 Countdown: 2...  
    .timer 1 4 mta.text $1 Countdown: 1...  
    .timer 1 6 mta.text $1 Countdown: Go Go Go!!!  

i have this and it works on my server ;) hope it helps

Link to comment
  } 
  elseif (!count* iswm $3) {  
    mta.text $1 Countdown: 3...  
    .timer 1 2 mta.text $1 Countdown: 2...  
    .timer 1 4 mta.text $1 Countdown: 1...  
    .timer 1 6 mta.text $1 Countdown: Go Go Go!!!  

i have this and it works on my server ;) hope it helps

It looks like IRC script... this section of forum deals with Lua.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...