Jump to content

countdown


OrbTanT

Recommended Posts

How to create a countdown within a dxdrawrectagle

  
addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawRectangle(60, 320, 250, 175, tocolor(0, 0, 0, 175), true) 
        dxDrawText("Score", 200, 325, 112, 356, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 365, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 405, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("TEMPO:", 70, 450, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
) 

To operate in front of dxtext "Time"

Link to comment
More on the timer will be showing 3:00?

function drawDX ()       
    X,Y = guiGetScreenSize () 
    X = X * (2.5/3) 
    Y = Y * (1/4) 
    dxDrawText ( getElementData(getLocalPlayer(),"secondsRemaining"), X, Y, X, Y, tocolor(255, 255, 255, 255), 5) 
end 
  
function showDX () 
  addEventHandler ( "onClientRender", getRootElement(), drawDX ) 
end 
addEvent ( "showDX", true ) 
addEventHandler ( "showDX", getRootElement(), showDX ) 
  
function hideDX () 
  removeEventHandler ( "onClientRender", getRootElement(), drawDX ) 
end 
addEvent ( "hideDX", true ) 
addEventHandler ( "hideDX", getRootElement(), hideDX ) 

segundos = 30000 
timerEnabled = false 
  
function onS () 
if timerEnabled then 
setElementData(source,"secondsRemaining",tostring(segundos)) 
triggerClientEvent ( source, "showDX", source) 
  end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), onS ) 
  
function escreve () 
timerEnabled = true 
for i,v in pairs(getElementsByType("player")) do 
setElementData(v,"secondsRemaining",tostring(segundos)) 
triggerClientEvent ( v, "showDX", v ) 
end 
setTimer(countDown,1000,30) 
end 
addCommandHandler("inciarcontador",escreve) 
  
function countDown() 
segundos = segundos -1 
for i,v in pairs(getElementsByType("player")) do 
setElementData(v,"secondsRemaining",tostring(segundos)) 
end 
if segundos == 0 then 
triggerClientEvent ( "hideDX", getRootElement() ) 
timerEnabled = false 
  end 
end 
  
function onStart () 
  timerEnabled = false 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart ) 
Link to comment

I can to use this script with the dxdrawrectangle I created?

  
addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawRectangle(60, 320, 250, 175, tocolor(0, 0, 0, 175), true) 
        dxDrawText("Score", 200, 325, 112, 356, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 365, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 405, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("TEMPO:", 70, 450, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
) 

I put the script but does not start the counter

Link to comment
I can to use this script with the dxdrawrectangle I created?
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawRectangle(60, 320, 250, 175, tocolor(0, 0, 0, 175), true) 
        dxDrawText("Score", 200, 325, 112, 356, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 365, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 405, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("TEMPO:", 70, 450, 73, 340, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
) 

I put the script but does not start the counter

well , iam not very good at dx , becuase i use labels easy ,

but what i post will do the job without your code , it will change auto ..

Link to comment

Incase if you would like to change the format to minutes and seconds like this

3:00 . I think this usefull function will do the job

function msToTimeStr( ms ) 
    if not ms then 
        return '' 
    end 
     
    local s = math.floor( ms / 1000 ) 
     
    local seconds = tostring( math.fmod( s, 60 ) ) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
     
    local minutes = tostring( math.floor( s / 60 ) ) 
    if #minutes == 1 then 
        minutes = '0' .. minutes 
    end 
    return minutes .. ':' .. seconds 
  
end 

Example:

function justForTest() end 
  
function msToTimeStr( ms ) 
  
    if not ms then 
        return '' 
    end 
     
    local s = math.floor( ms / 1000 ) 
     
    local seconds = tostring( math.fmod( s, 60 ) ) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
     
    local minutes = tostring( math.floor( s / 60 ) ) 
    if #minutes == 1 then 
        minutes = '0' .. minutes 
    end 
    return minutes .. ':' .. seconds 
  
end 
  
myTimer = setTimer( justForTest, 180*1000, 1 ) 
  
addEventHandler( "onClientRender", root, 
    function( ) 
     
        if isTimer( myTimer ) then 
            remaining, _, _  = getTimerDetails(myTimer) 
         
            remaining = msToTimeStr( remaining ) 
         
            if remaining then 
                dxDrawText( remaining, 100, 350, 300, 350, tocolor( 255, 255, 0 ), 1, 'arial' ) 
            end 
        end 
    end 
) 

Link to comment

Help me on something, I tried to add a score, when a team kills the player from the other team, adds +1 at score, more does not operate.

client:

addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawRectangle(60, 320, 250, 175, tocolor(0, 0, 0, 175), true) 
        dxDrawText("Score", 225, 325, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 365, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 405, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("TEMPO:", 70, 450, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
    end 
) 
  
function justForTest() end 
  
function msToTimeStr( ms ) 
  
    if not ms then 
        return '' 
    end 
    
    local s = math.floor( ms / 1000 ) 
    
    local seconds = tostring( math.fmod( s, 60 ) ) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
    
    local minutes = tostring( math.floor( s / 60 ) ) 
    if #minutes == 1 then 
        minutes = '0' .. minutes 
    end 
    return minutes .. ':' .. seconds 
  
end 
  
myTimer = setTimer( justForTest, 180*1000, 1 ) 
  
addEventHandler( "onClientRender", root, 
    function( ) 
    
        if isTimer( myTimer ) then 
            remaining, _, _  = getTimerDetails(myTimer) 
        
            remaining = msToTimeStr( remaining ) 
        
            if remaining then 
                dxDrawText( remaining, 120, 442, 350, 300, tocolor(255, 255, 255, 255), 1.0, "pricedown", "left", "top", false, false, true, false, false) 
            end 
        end 
    end 
) 
  
    local Bscore = 0 
    local Wscore = 0 
  
 function onRender() 
    local team = getPlayerTeam(localPlayer) 
  
    if(getTeamName(team) == "Team1" or getTeampame(team) == "Team2") then 
        dxDrawText("Team2", 70, 340, 319, 426, tocolor(0, 255, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText("Team1", 70, 380, 319, 426, tocolor(255, 0, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText(tostring(Bscore), 240, 340, 319, 426, tocolor(0, 255, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText(tostring(Wscore), 240, 380, 319, 426, tocolor(255, 0, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
    end 
end 
  
addEventHandler("onClientRender", root, onRender) 

server:

function onWasted(killer, weapon, bodypart) 
    local kteam = getPlayerTeam(killer) 
    
    if(getTeamName(kteam) == "Team1")then 
        Wscore = Wscore + 1 
    elseif(getTeamName(kteam) == "Team2")then 
        Bscore = Bscore + 1 
    end 
end 
addEventHandler("onClientPedWasted", getRootElement(), onWasted) 

Link to comment

--- ClientSide all of it ,

addEventHandler('onClientPlayerWasted', root, 
function ( attacker ) 
    if ( attacker  and attacker ~= source ) and getPlayerTeam(getTeamName( attacker ) == 'Team1' ) then 
    setElementData ( attacker, Wscore +1 ) 
    elseif ( attacker  and attacker ~= source ) and getPlayerTeam(getTeamName( attacker ) == 'Team2' ) then 
    setElementData ( attacker, Bscore + 1 ) 
   end 
end 
) 
  
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawRectangle(60, 320, 250, 175, tocolor(0, 0, 0, 175), true) 
        dxDrawText("Score", 225, 325, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 365, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("Mortes:", 70, 405, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
        dxDrawText("TEMPO:", 70, 450, 73, 340, tocolor(255, 255, 255, 255), 1.1, "default", "left", "top", false, false, true, false, false) 
    end 
) 
  
function justForTest() end 
  
function msToTimeStr( ms ) 
  
    if not ms then 
        return '' 
    end 
    
    local s = math.floor( ms / 1000 ) 
    
    local seconds = tostring( math.fmod( s, 60 ) ) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
    
    local minutes = tostring( math.floor( s / 60 ) ) 
    if #minutes == 1 then 
        minutes = '0' .. minutes 
    end 
    return minutes .. ':' .. seconds 
  
end 
  
myTimer = setTimer( justForTest, 180*1000, 1 ) 
  
addEventHandler( "onClientRender", root, 
    function( ) 
    
        if isTimer( myTimer ) then 
            remaining, _, _  = getTimerDetails(myTimer) 
        
            remaining = msToTimeStr( remaining ) 
        
            if remaining then 
                dxDrawText( remaining, 120, 442, 350, 300, tocolor(255, 255, 255, 255), 1.0, "pricedown", "left", "top", false, false, true, false, false) 
            end 
        end 
    end 
) 
  
    local Bscore = 0 
    local Wscore = 0 
  
 function onRender() 
  
 if ( getPlayerTeam( localPlayer ) and getPlayerTeam( localPlayer ) == getTeamFromName ( "Team1" ) )  or ( getPlayerTeam( localPlayer ) and getPlayerTeam( localPlayer ) == getTeamFromName ( "Team2" ) ) then 
        dxDrawText("Team2", 70, 340, 319, 426, tocolor(0, 255, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText("Team1", 70, 380, 319, 426, tocolor(255, 0, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText(tostring(Bscore), 240, 340, 319, 426, tocolor(0, 255, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
        dxDrawText(tostring(Wscore), 240, 380, 319, 426, tocolor(255, 0, 0, 255), 1.4, "default-bold", "left", "top", false, false, true, false, false) 
    end 
end 
addEventHandler("onClientRender", root, onRender) 

Edited #

Edited by Guest
Link to comment
I would put it serverside Max+, not clientside...

onPlayerWasted

Look who killed who and etc, set the score and trigger the score to the client's.

why do it very hard with triggers and etc ?

while you can use it all in ClientSide ?

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