Jump to content

countdown for all


zombienation

Recommended Posts

hello,

i was wondering if there is anybody here who knows how to add a countdown that is visible for all? perhaps in chat..

i found this countdown but its only visible for the one who type the command,

function Countdown ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/10.png",false)

setTimer ( Countdown9, 1000, 1 )

outputChatBox ( "countdown started", getRootElement(), 255, 255, 255, true )

end

function Countdown9 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/9.png",false)

setTimer ( Countdown8, 1000, 1 )

end

function Countdown8 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/8.png",false)

setTimer ( Countdown7, 1000, 1 )

end

function Countdown7 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/7.png",false)

setTimer ( Countdown6, 1000, 1 )

end

function Countdown6 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/6.png",false)

setTimer ( Countdown5, 1000, 1 )

end

function Countdown5 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/5.png",false)

setTimer ( Countdown4, 1000, 1 )

end

function Countdown4 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/4.png",false)

setTimer ( Countdown3, 1000, 1 )

end

function Countdown3 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/3.png",false)

setTimer ( Countdown2, 1000, 1 )

end

function Countdown2 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/2.png",false)

setTimer ( Countdown1, 1000, 1 )

end

function Countdown1 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,110,190,"images/1.png",false)

setTimer ( Countdown0, 1000, 1 )

end

function Countdown0 ( source )

guiSetVisible ( imagecount, false )

imagecount = guiCreateStaticImage(305,119,320,81,"images/go.png",false)

setTimer ( CountdownEnd, 3000, 1 )

end

function CountdownEnd ( source )

guiSetVisible ( imagecount, false )

end

addCommandHandler ( "countdown", Countdown )

Link to comment

try this :

function startCountdown ( source ) 
    c10 = guiCreateStaticImage(305,119,110,190,"images/10.png",true, nil ) 
    guiMoveToBack(c10) 
    guiSetAlpha(c10, 0.9) 
    setTimer(destroyElement, 1000, 1, c10 ) 
    setTimer( Countdown9( source ), 1000, 1 ) 
    outputChatBox ( "countdown started", getRootElement(), 255, 255, 255, true ) 
end 
  
function Countdown9 ( source ) 
    c9 = guiCreateStaticImage(305,119,110,190,"images/9.png",true, nil ) 
    guiMoveToBack(c9) 
    guiSetAlpha(c9, 0.9) 
    setTimer( destroyElement, 1000, 1, c9 ) 
    setTimer( Countdown8( source ), 1000, 1 ) 
end 
  
function Countdown8 ( source ) 
    c8 = guiCreateStaticImage(305,119,110,190,"images/8.png",true, nil ) 
    guiMoveToBack(c8) 
    guiSetAlpha(c8, 0.9) 
    setTimer( destroyElement, 1000, 1, c8 ) 
    setTimer( Countdown7( source ), 1000, 1 ) 
end 
  
function Countdown7 ( source ) 
    c7 = guiCreateStaticImage(305,119,110,190,"images/7.png",true, nil ) 
    guiMoveToBack(c7) 
    guiSetAlpha(c7, 0.9) 
    setTimer( destroyElement, 1000, 1, c7 ) 
    setTimer ( Countdown6( source ), 1000, 1 ) 
end 
  
function Countdown6 ( source ) 
    c6 = guiCreateStaticImage(305,119,110,190,"images/6.png",true, nil ) 
    guiMoveToBack(c6) 
    guiSetAlpha(c6, 0.9) 
    setTimer( destroyElement, 1000, 1, c6 ) 
    setTimer( Countdown5( source ), 1000, 1 ) 
end 
  
function Countdown5 ( source ) 
    c5 = guiCreateStaticImage(305,119,110,190,"images/5.png",true, nil ) 
    guiMoveToBack(c5) 
    guiSetAlpha(c5, 0.9) 
    setTimer( destroyElement, 1000, 1, c5 ) 
    setTimer( Countdown4( source ), 1000, 1 ) 
end 
  
function Countdown4 ( source ) 
    c4 = guiCreateStaticImage(305,119,110,190,"images/4.png",true, nil ) 
    guiMoveToBack(c4) 
    guiSetAlpha(c4, 0.9) 
    setTimer( destroyElement, 1000, 1, c4 ) 
    setTimer( Countdown3( source ), 1000, 1 ) 
end 
  
function Countdown3 ( source ) 
    c3 = guiCreateStaticImage(305,119,110,190,"images/3.png",true, nil ) 
    guiMoveToBack(c3) 
    guiSetAlpha(c3, 0.9) 
    setTimer( destroyElement, 1000, 1, c3 ) 
    setTimer( Countdown2( source ), 1000, 1 ) 
end 
  
function Countdown2 ( source ) 
    c2 = guiCreateStaticImage(305,119,110,190,"images/2.png",true, nil ) 
    guiMoveToBack(c2) 
    guiSetAlpha(c2, 0.9) 
    setTimer( destroyElement, 1000, 1, c2 ) 
    setTimer ( Countdown1( source ), 1000, 1 ) 
end 
  
function Countdown1 ( source ) 
    c1 = guiCreateStaticImage(305,119,110,190,"images/1.png",true, nil ) 
    guiMoveToBack(c1) 
    guiSetAlpha(c1, 0.9) 
    setTimer( destroyElement, 1000, 1, c1 ) 
    setTimer ( goGo ( source ), 1000, 1 ) 
end 
  
function goGo ( source ) 
    go = guiCreateStaticImage(305,119,320,81,"images/go.png",true, nil ) 
    guiMoveToBack(go) 
    guiSetAlpha(go, 0.9) 
    setTimer( destroyElement, 1000, 1, go ) 
end 
  
function startscounting( source ) 
    startCountdown ( source ) 
end 
addCommandHandler ( "countdown", startscounting ) 

Link to comment

what u have posted shows images...

if u just want something simple in the chat, then:

function countdown(player) 
    local name = getPlayerName(player) 
    outputChatBox(name .. ":- Countdown: 3",getRootElement(),0,255,0) 
    setTimer(outputChatBox,1000,1,name .. ":- Countdown: 2",getRootElement(),0,255,0) 
    setTimer(outputChatBox,2000,1,name .. ":- Countdown: 1",getRootElement(),0,255,0) 
    setTimer(outputChatBox,3000,1,name .. ":- GO GO GO!!!!",getRootElement(),0,255,0) 
end 
addCommandHandler("count",countdown) 

if u want something more complex, say so... this is just a basic countdown from 3.

ive added the players name so u can see whos activating it.

also, this is serverside.

Link to comment

-- SERVER SIDE --

  
function onCountdown(player) 
    for i=1, 11 do 
        setTimer(triggerClientEvent, i*1000, 1, getRootElement(), "onSetCountdown", getRootElement(), i) 
    end 
end 
addCommandHandler("countdown", onCountdown) 
  

-- CLIENT SIDE --

  
local screenWidth, screenHeight = guiGetScreenSize() 
local showhide = false 
local countdown = 0 
  
function onRenderCountdown() 
    if showhide then 
        if countdown == 10 then 
            dxDrawImage(screenWidth/2 - 320, screenWidth/2 - 81, 320, 81, "images/go.png") 
        else 
            dxDrawImage(screenWidth/2 - 110, screenWidth/2 - 190, 110, 190, "images/" .. countdown .. ".png") 
        end 
    end 
end 
addEventHandler("onClientRender", getRootElement(), onRenderCountdown) 
  
function onSetCountdown(count) 
    if count < 11 then 
        countdown = count 
        showhide = true 
    else 
        showhide = false 
    end 
end 
addEvent("onSetCountdown", true) 
addEventHandler("onSetCountdown", getRootElement(), onSetCountdown) 
  

I didnt tested yet.

Link to comment

-=I Blaawee I=- you used 9 functions for a simple countdown script, that is retarded

Here is the clientside component:

  
local countdownImage, countdownCount 
function startCountdown() 
    countdownImage = guiCreateStaticImage(305,119,110,190,"images/10.png",false) 
    setTimer(decrementCoundown, 1000, 11) 
    countdownCount = 10 
end 
  
function decrementCoundown() 
    countdownCount = countdownCount - 1 
    if countdown > 0 then 
        guiStaticImageLoadImage (countdownImage, "images/"..countdownCount..".png") 
    elseif countdown == 0 then 
        guiStaticImageLoadImage (countdownImage, "images/go.png") 
    else 
        destroyElement(countdownImage) 
    end 
end 
  

Edited by Guest
Link to comment
try this :
function startCountdown ( source ) 
    c10 = guiCreateStaticImage(305,119,110,190,"images/10.png",true, nil ) 
    guiMoveToBack(c10) 
    guiSetAlpha(c10, 0.9) 
    setTimer(destroyElement, 1000, 1, c10 ) 
    setTimer( Countdown9( source ), 1000, 1 ) 
    outputChatBox ( "countdown started", getRootElement(), 255, 255, 255, true ) 
end 
  
function Countdown9 ( source ) 
    c9 = guiCreateStaticImage(305,119,110,190,"images/9.png",true, nil ) 
    guiMoveToBack(c9) 
    guiSetAlpha(c9, 0.9) 
    setTimer( destroyElement, 1000, 1, c9 ) 
    setTimer( Countdown8( source ), 1000, 1 ) 
end 
  
function Countdown8 ( source ) 
    c8 = guiCreateStaticImage(305,119,110,190,"images/8.png",true, nil ) 
    guiMoveToBack(c8) 
    guiSetAlpha(c8, 0.9) 
    setTimer( destroyElement, 1000, 1, c8 ) 
    setTimer( Countdown7( source ), 1000, 1 ) 
end 
  
function Countdown7 ( source ) 
    c7 = guiCreateStaticImage(305,119,110,190,"images/7.png",true, nil ) 
    guiMoveToBack(c7) 
    guiSetAlpha(c7, 0.9) 
    setTimer( destroyElement, 1000, 1, c7 ) 
    setTimer ( Countdown6( source ), 1000, 1 ) 
end 
  
function Countdown6 ( source ) 
    c6 = guiCreateStaticImage(305,119,110,190,"images/6.png",true, nil ) 
    guiMoveToBack(c6) 
    guiSetAlpha(c6, 0.9) 
    setTimer( destroyElement, 1000, 1, c6 ) 
    setTimer( Countdown5( source ), 1000, 1 ) 
end 
  
function Countdown5 ( source ) 
    c5 = guiCreateStaticImage(305,119,110,190,"images/5.png",true, nil ) 
    guiMoveToBack(c5) 
    guiSetAlpha(c5, 0.9) 
    setTimer( destroyElement, 1000, 1, c5 ) 
    setTimer( Countdown4( source ), 1000, 1 ) 
end 
  
function Countdown4 ( source ) 
    c4 = guiCreateStaticImage(305,119,110,190,"images/4.png",true, nil ) 
    guiMoveToBack(c4) 
    guiSetAlpha(c4, 0.9) 
    setTimer( destroyElement, 1000, 1, c4 ) 
    setTimer( Countdown3( source ), 1000, 1 ) 
end 
  
function Countdown3 ( source ) 
    c3 = guiCreateStaticImage(305,119,110,190,"images/3.png",true, nil ) 
    guiMoveToBack(c3) 
    guiSetAlpha(c3, 0.9) 
    setTimer( destroyElement, 1000, 1, c3 ) 
    setTimer( Countdown2( source ), 1000, 1 ) 
end 
  
function Countdown2 ( source ) 
    c2 = guiCreateStaticImage(305,119,110,190,"images/2.png",true, nil ) 
    guiMoveToBack(c2) 
    guiSetAlpha(c2, 0.9) 
    setTimer( destroyElement, 1000, 1, c2 ) 
    setTimer ( Countdown1( source ), 1000, 1 ) 
end 
  
function Countdown1 ( source ) 
    c1 = guiCreateStaticImage(305,119,110,190,"images/1.png",true, nil ) 
    guiMoveToBack(c1) 
    guiSetAlpha(c1, 0.9) 
    setTimer( destroyElement, 1000, 1, c1 ) 
    setTimer ( goGo ( source ), 1000, 1 ) 
end 
  
function goGo ( source ) 
    go = guiCreateStaticImage(305,119,320,81,"images/go.png",true, nil ) 
    guiMoveToBack(go) 
    guiSetAlpha(go, 0.9) 
    setTimer( destroyElement, 1000, 1, go ) 
end 
  
function startscounting( source ) 
    startCountdown ( source ) 
end 
addCommandHandler ( "countdown", startscounting ) 

hey, when u do /count it just say countdown started in chat but there is no countdown, thanks for trying anyway!! :)

what u have posted shows images...

if u just want something simple in the chat, then:

function countdown(player) 
    local name = getPlayerName(player) 
    outputChatBox(name .. ":- Countdown: 3",getRootElement(),0,255,0) 
    setTimer(outputChatBox,1000,1,name .. ":- Countdown: 2",getRootElement(),0,255,0) 
    setTimer(outputChatBox,2000,1,name .. ":- Countdown: 1",getRootElement(),0,255,0) 
    setTimer(outputChatBox,3000,1,name .. ":- GO GO GO!!!!",getRootElement(),0,255,0) 
end 
addCommandHandler("count",countdown) 

if u want something more complex, say so... this is just a basic countdown from 3.

ive added the players name so u can see whos activating it.

also, this is serverside.

this one works perfectly, thanks man

Link to comment

More better :)

Server

local timer = { } 
local counts = { } 
  
local repeats = 3 
  
addCommandHandler( "countdown", 
    function( source ) 
        if isTimer( timer[ source ] ) then return end 
        counts[ source ] = repeats + 1 
        timer[ source ] = setTimer(  
            function( player ) 
                counts[ player ] = counts[ player ] - 1 
                if counts[ player ] == 0 then 
                    return outputChatBox( "GO!" ) 
                end 
                outputChatBox( "countdown: "..counts[ player ] ) 
            end, 
        1000, 
        repeats+1,source ) 
    end 
)    
  
addEventHandler( "onPlayerQuit",root, 
    function( ) 
        counts[ source ] = nil 
        if isTimer( timer[ source ] ) then  
            killTimer( timer[ source ] )  
        end 
        timer[ source ] = nil 
    end 
)    

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...