Jump to content

countdown


OrbTanT

Recommended Posts

--ClientSide ,

  
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 
  
addEventHandler("onClientPlayerWasted", 
function ( killer ) 
     local kteam = getPlayerTeam(killer) 
      if(getTeamName(kteam) == "Team1")then 
        Wscore = Wscore + 1 
        elseif(getTeamName(kteam) == "Team2") then 
        Bscore = Bscore + 1 
    end 
  end 
) 
  
function onRender() 
    local team = getPlayerTeam(localPlayer) 
    if(getTeamName(team) == "Team1" or getTeamName(team) == "Team2") then 
    dxDrawText("Team1:"..tostring(Bscore), 0, 500, 319, 426, tocolor(0, 0, 0, 255), 1.00, "pricedown", "center", "center", true, true, true, true, false) 
    dxDrawText("Team2:"..tostring(Wscore), 0, 600, 319, 426, tocolor(255, 255, 255, 255), 1.00, "pricedown", "center", "center", true, true, true, true, false) 
    end 
end 
addEventHandler("onClientRender", root, onRender) 
Link to comment

Now is giving the following error:

Error: pasta/client.lua:54: Bad aegument @ 'addEventHandler' [Expected element at argument 2, got function]

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 
  
addEventHandler("onClientPlayerWasted", 
function ( killer ) 
    local kteam = getPlayerTeam(killer) 
    if(getTeamName(kteam) == "Team1") then 
        Wscore = Wscore + 1 
        elseif(getTeamName(kteam) == "Team2") then 
        Bscore = Bscore + 1 
    end 
end 
) 
  
function onRender() 
    local team = getPlayerTeam(localPlayer) 
    if(getTeamName(team) == "Team1" or getTeamName(team) == "Team2") then 
    dxDrawText("Team1:"..tostring(Bscore), 70, 340, 319, 426, tocolor(255, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
    dxDrawText("Team2:"..tostring(Wscore), 70, 380, 319, 426, tocolor(0, 255, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
    end 
end 
addEventHandler("onClientRender", root, onRender) 

Link to comment

Concerted, is now working very well the script, only had to coordinate the @getplayerteam, the dxdraw in function

addEventHandler("onClientPlayerWasted", 
function ( killer ) 
    local kteam = getPlayerTeam(killer) 
    if(getTeamName(kteam) == "Team1") then 
        Wscore = Wscore + 1 
        elseif(getTeamName(kteam) == "Team2") then 
        Bscore = Bscore + 1 
    end 
end 
) 

to:

addEventHandler("onClientPlayerWasted", getRootElement(), 
    function ( localplayer ) 
        local team = getPlayerTeam(localPlayer) 
        if(getTeamName(team) == "Team1") then 
            Wscore = Wscore + 1 
        elseif(getTeamName(team) == "Team2") then 
            Bscore = Bscore + 1 
        end 
    end 
 ) 

Thank all of you for your help

Link to comment

The script is working normal, but only has a problem, the score only account on the client, when I mato and hill to the other team, account score for the time2, more my friend helping me test was counting for the team1 only on his side.

Link to comment
The script is working normal, but only has a problem, the score only account on the client, when I mato and hill to the other team, account score for the time2, more my friend helping me test was counting for the team1 only on his side.

please be more clear i didn't get what you mean .

Link to comment
Good, i step part of team1, I mato player of team2. have to add score +1for the team1, More add to the team2. And the same thing happens with the team2, Only adds score for the team1

you mean it's add +1 for team 1 only and team 2 dont ?

Link to comment

--ClientSide ,

  
            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 
  
addEventHandler("onClientPlayerWasted",root, 
function ( killer ) 
    if ( killer and killer ~= source ) then 
    if (getTeamName(getPlayerTeam(killer)) == "Team1") then 
        Wscore = Wscore + 1 
        elseif (getTeamName(getPlayerTeam(killer)) == "Team2") then 
        Bscore = Bscore + 1 
    end 
  end 
end 
) 
function onRender() 
    local team = getPlayerTeam(localPlayer) 
    if(getTeamName(team) == "Team1" or getTeamName(team) == "Team2") then 
    dxDrawText("Team1:"..tostring(Bscore), 0, 500, 319, 426, tocolor(0, 0, 0, 255), 1.00, "pricedown", "center", "center", true, true, true, true, false) 
    dxDrawText("Team2:"..tostring(Wscore), 0, 600, 319, 426, tocolor(255, 255, 255, 255), 1.00, "pricedown", "center", "center", true, true, true, true, false) 
    end 
 end 
addEventHandler("onClientRender", root, onRender) 

# Edited

/debugscript 3

Edited by Guest
Link to comment

Presented error em @GetTeamName, More this has no error, and adds the score, more only for the player, for the other player shows only for him, I think that is due to "localplayer" or should give a way to add on the server.

If you could get into my server would understand better just what I'm talking about, explaining is complicated

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