Jump to content

countdown


OrbTanT

Recommended Posts

Posted

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"

Posted

I don't understand very well, I was trying to do something as soon as you open the dxdrawtectangle, start to count down from 3 minutes(3:00).

Posted
I don't understand very well, I was trying to do something as soon as you open the dxdrawtectangle, start to count down from 3 minutes(3:00).

segundos = 30 

replace it with 30000 = 3 min ,

Posted
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 ) 
Posted

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

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

Posted

Counter only appears when I type /counter, I'd like to leave in format of minutes. How to leave only for the counter start as soon as you open the dxdrawrectagle

Posted

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 
) 

Posted

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) 

Posted (edited)

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

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.

Posted
Not going to have the server side?

nope , becuase its all client Events ..

remove the serverSide scripts , and /debugscript 3 to see if there is any erros ?

Posted
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 ?

Posted

WARNING:pasta/client.lua:67:Bad 'team"pointer @ 'getTeamName'(1)

WARNING:pasta/client.lua:67:Bad argument @ 'getPlayerTeam' [Expected player at argument 1, got boolean]

Posted
WARNING:pasta/client.lua:67:Bad 'team"pointer @ 'getTeamName'(1)

WARNING:pasta/client.lua:67:Bad argument @ 'getPlayerTeam' [Expected player at argument 1, got boolean]

Edited my post copy it again ..

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