Jump to content

[ PERGUNTA ]"Tela de loading" ou Barra carregando


Recommended Posts

Posted

Por exemplo, uma barra que acredito que seja um DxDrawRectangle, que carrega como por exemplo uma tela de loading de jogos ou a barra de quando você está fazendo download do servidor, Tem Alguma função ou executar DxDrawRectangle com cada tempo?

Posted

Use, dentro do evento "onClientRender" a função getTickCount mais a dxDrawRectangle que você disse e acrescente um valor à largura do retângulo DX para aumentar o tal 'progresso'.

Posted

tendi. usei o exemplo da wiki , eu tentei quero que ela execute em uma função que esta no server, ai eu pensei que um addEvent e addEventHandler e TriggerServerEvent executaria, porem deu bad argument [Expected Element At Argument 2, got Function, tem algum problema ? OBS:Não estou colocando a função completa pra nao houver roubo só o que esta dando erro

Server:

  
local rootElement = getRootElement() 
function revistar_jogador ( thePlayer, comando, nick ) 
end 
addCommandHandler ( "revistar", revistar_jogador ) 
addEvent("revistar", true) 
addEventHandler("revistar", rootElement, revistar_jogador)  

Client:

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
  
function getCount() 
    dxDrawRectangle(354, 312, 376, 38, tocolor(0, 0, 0, 255), false) 
    if not systemUpTime then 
    systemUpTime = getTickCount () 
    currentCount = getTickCount () 
    dxDrawRectangle(x*358, y*316, x*368, y*29, tocolor(189, 0, 0, 255), false) 
    dxDrawText ( currentCount - systemUpTime, x * .48, y * .1, x, y, tocolor(255,255,255), 2) 
    triggerServerEvent("revistar", thePlayer)    
end 
end 
addEventHandler("onClientRender", thePlayer, getCount) 

Posted
tendi. usei o exemplo da wiki , eu tentei quero que ela execute em uma função que esta no server, ai eu pensei que um addEvent e addEventHandler e TriggerServerEvent executaria, porem deu bad argument [Expected Element At Argument 2, got Function, tem algum problema ? OBS:Não estou colocando a função completa pra nao houver roubo só o que esta dando erro

Server:

  
local rootElement = getRootElement() 
function revistar_jogador ( thePlayer, comando, nick ) 
end 
addCommandHandler ( "revistar", revistar_jogador ) 
addEvent("revistar", true) 
addEventHandler("revistar", rootElement, revistar_jogador)  

Client:

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
  
function getCount() 
    dxDrawRectangle(354, 312, 376, 38, tocolor(0, 0, 0, 255), false) 
    if not systemUpTime then 
    systemUpTime = getTickCount () 
    currentCount = getTickCount () 
    dxDrawRectangle(x*358, y*316, x*368, y*29, tocolor(189, 0, 0, 255), false) 
    dxDrawText ( currentCount - systemUpTime, x * .48, y * .1, x, y, tocolor(255,255,255), 2) 
    triggerServerEvent("revistar", thePlayer)    
end 
end 
addEventHandler("onClientRender", thePlayer, getCount) 

como o erro ja ta falandor argumento 2

triggerServerEvent("revistar", thePlayer)  

theplayer eo erro.

Posted

DanteTV, o seu código têm muitos erros.

Faça um teste com este código que eu fiz (e não cheguei a testá-lo):

  
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
local tempo, valor = 1000, 60 
local startTick 
local pBarCurWidth, pBarWidth = 0, 368 
  
addEvent("doShowDXProgressBar", true) 
addEventHandler("doShowDXProgressBar", root, 
    function() 
        startTick = getTickCount() 
        addEventHandler("onClientRender", renderDXProgressBar) 
    end 
) 
  
function renderDXProgressBar() 
    dxDrawRectangle(x*354, y*312, 376, 38, tocolor(0, 0, 0, 255), false) 
    local now = getTickCount() 
    if (now - startTick) >= tempo then -- Aumentar a largura da barra 
        pBarCurWidth = pBarCurWidth + valor 
        startTick = getTickCount() 
        if pBarCurWidth > pBarWidth then -- Barra de progresso cheia 
            pBarCurWidth = pBarWidth 
            removeEventHandler("onClientRender", renderDXProgressBar) 
            startTick = nil 
        end 
    end 
    dxDrawRectangle(x*358, y*316, pBarCurWidth, 29, tocolor(189, 0, 0, 255), false) 
    dxDrawText( tostring( math.ceil((pBarCurWidth * 100) / pBarWidth) ).." %", x*358, y*316, (x*358) + pBarWidth, (y*316) + 29, tocolor(255,255,255), 2) 
end 

Chame o evento doShowDXProgressBar desta forma:

triggerClientEvent(player, "doShowDXProgressBar", player) -- 'player' é o jogador para quem o evento será chamado 

Nas variáveis tempo e valor você pode mudar o tempo do progresso e, o valor da largura do retângulo quando aumentar, respectivamente.

Posted

bom oque nao deu foi o triggerClientEvent, de começo deu bad argument 1, porem troquei de player pra thePlayer, só que nao adiantou em nada. o comando executa, mas a "tela de loading" não.

Posted
Mostre o seu código.

Inteiro? se precisar eu atualizo essa mensagem, por enquanto vou deixar o principal

Client:

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
local tempo, valor = 1000, 60 
local startTick 
local pBarCurWidth, pBarWidth = 0, 368 
  
addEvent("doShowDXProgressBar", true) 
addEventHandler("doShowDXProgressBar", root, 
    function() 
        startTick = getTickCount() 
        addEventHandler("onClientRender", renderDXProgressBar) 
    end 
) 
  
function renderDXProgressBar() 
    dxDrawRectangle(x*354, y*312, 376, 38, tocolor(0, 0, 0, 255), false) 
    local now = getTickCount() 
    if (now - startTick) >= tempo then -- Aumentar a largura da barra 
        pBarCurWidth = pBarCurWidth + valor 
        startTick = getTickCount() 
        if pBarCurWidth > pBarWidth then -- Barra de progresso cheia 
            pBarCurWidth = pBarWidth 
            removeEventHandler("onClientRender", renderDXProgressBar) 
            startTick = nil 
        end 
    end 
    dxDrawRectangle(x*358, y*316, pBarCurWidth, 29, tocolor(189, 0, 0, 255), false) 
    dxDrawText( tostring( math.ceil((pBarCurWidth * 100) / pBarWidth) ).." %", x*358, y*316, (x*358) + pBarWidth, (y*316) + 29, tocolor(255,255,255), 2) 
end 

Server:

function revistar_jogador ( thePlayer, comando, nick )   
if nick then 
        if getPlayerFromPartialName ( nick ) then 
            local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
            if isObjectInACLGroup ("user."..accName, aclGetGroup ( "ComandosPolicia") ) then 
                triggerClientEvent(thePlayer, "doShowDXProgressBar", thePlayer)  
                 end 
       end 
     end 
 end 
  

Posted

Faça uma depuração no código, teste este código e diga o que mostra no chat quando for executado o comando:

client

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
local tempo, valor = 1000, 60 
local startTick 
local pBarCurWidth, pBarWidth = 0, 368 
  
addEvent("doShowDXProgressBar", true) 
addEventHandler("doShowDXProgressBar", root, 
    function() 
        startTick = getTickCount() 
        if addEventHandler("onClientRender", renderDXProgressBar) then 
        outputChatBox("[teste debug] renderDXProgressBar sendo chamada") 
        end 
    end 
) 
  
function renderDXProgressBar() 
    dxDrawRectangle(x*354, y*312, 376, 38, tocolor(0, 0, 0, 255), false) 
    local now = getTickCount() 
    if (now - startTick) >= tempo then -- Aumentar a largura da barra 
        outputChatBox("[teste debug] Aumentar a barra") 
        pBarCurWidth = pBarCurWidth + valor 
        startTick = getTickCount() 
        if pBarCurWidth > pBarWidth then -- Barra de progresso cheia 
            outputChatBox("[teste debug] A barra está cheia") 
            pBarCurWidth = pBarWidth 
            removeEventHandler("onClientRender", renderDXProgressBar) 
            startTick = nil 
        end 
    end 
    dxDrawRectangle(x*358, y*316, pBarCurWidth, 29, tocolor(189, 0, 0, 255), false) 
    dxDrawText( tostring( math.ceil((pBarCurWidth * 100) / pBarWidth) ).." %", x*358, y*316, (x*358) + pBarWidth, (y*316) + 29, tocolor(255,255,255), 2) 
end 

server

function revistar_jogador ( thePlayer, comando, nick )  
    if nick then 
        if getPlayerFromPartialName ( nick ) then 
            local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
            if isObjectInACLGroup ("user."..accName, aclGetGroup ( "ComandosPolicia") ) then 
            outputChatBox("[teste debug] Você é policial") 
                if triggerClientEvent(thePlayer, "doShowDXProgressBar", thePlayer) then 
            outputChatBox("[teste debug] chamada ao client bem-sucedida") 
        end 
            end 
       end 
     end 
 end 

Se nada estiver errado, pode ser que o evento tenha sido chamado para o jogador errado (?). Se é mesmo pro policial então está certo.

Posted
Faça uma depuração no código, teste este código e diga o que mostra no chat quando for executado o comando:

client

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
local tempo, valor = 1000, 60 
local startTick 
local pBarCurWidth, pBarWidth = 0, 368 
  
addEvent("doShowDXProgressBar", true) 
addEventHandler("doShowDXProgressBar", root, 
    function() 
        startTick = getTickCount() 
        if addEventHandler("onClientRender", renderDXProgressBar) then 
        outputChatBox("[teste debug] renderDXProgressBar sendo chamada") 
        end 
    end 
) 
  
function renderDXProgressBar() 
    dxDrawRectangle(x*354, y*312, 376, 38, tocolor(0, 0, 0, 255), false) 
    local now = getTickCount() 
    if (now - startTick) >= tempo then -- Aumentar a largura da barra 
        outputChatBox("[teste debug] Aumentar a barra") 
        pBarCurWidth = pBarCurWidth + valor 
        startTick = getTickCount() 
        if pBarCurWidth > pBarWidth then -- Barra de progresso cheia 
            outputChatBox("[teste debug] A barra está cheia") 
            pBarCurWidth = pBarWidth 
            removeEventHandler("onClientRender", renderDXProgressBar) 
            startTick = nil 
        end 
    end 
    dxDrawRectangle(x*358, y*316, pBarCurWidth, 29, tocolor(189, 0, 0, 255), false) 
    dxDrawText( tostring( math.ceil((pBarCurWidth * 100) / pBarWidth) ).." %", x*358, y*316, (x*358) + pBarWidth, (y*316) + 29, tocolor(255,255,255), 2) 
end 

server

function revistar_jogador ( thePlayer, comando, nick )  
    if nick then 
        if getPlayerFromPartialName ( nick ) then 
            local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
            if isObjectInACLGroup ("user."..accName, aclGetGroup ( "ComandosPolicia") ) then 
            outputChatBox("[teste debug] Você é policial") 
                if triggerClientEvent(thePlayer, "doShowDXProgressBar", thePlayer) then 
            outputChatBox("[teste debug] chamada ao client bem-sucedida") 
        end 
            end 
       end 
     end 
 end 

Se nada estiver errado, pode ser que o evento tenha sido chamado para o jogador errado (?). Se é mesmo pro policial então está certo.

Agora deu bad argument na linha 12, problema no argumento 2 got function, porem ja resolvi o problema coloquei mais um argumento só que esse argumento é root , entao aparecera para todos, e quero que só apareça pra quem executar, só que a função thePlayer não funciona, existe outra?

local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y = (resW/screenW),(resH/screenH) 
local tempo, valor = 1000, 60 
local startTick 
local pBarCurWidth, pBarWidth = 0, 368 
  
addEvent("doShowDXProgressBar", true) 
addEventHandler("doShowDXProgressBar", root, 
    function() 
        startTick = getTickCount() 
        if addEventHandler("onClientRender", renderDXProgressBar) then 
        outputChatBox("[teste debug] renderDXProgressBar sendo chamada") 
        end 
    end 
) 
  
function renderDXProgressBar() 
    dxDrawRectangle(x*354, y*312, 376, 38, tocolor(0, 0, 0, 255), false) 
    local now = getTickCount() 
    if (now - startTick) >= tempo then -- Aumentar a largura da barra 
        outputChatBox("[teste debug] Aumentar a barra") 
        pBarCurWidth = pBarCurWidth + valor 
        startTick = getTickCount() 
        if pBarCurWidth > pBarWidth then -- Barra de progresso cheia 
            outputChatBox("[teste debug] A barra está cheia") 
            pBarCurWidth = pBarWidth 
            removeEventHandler("onClientRender", renderDXProgressBar) 
            startTick = nil 
        end 
    end 
    dxDrawRectangle(x*358, y*316, pBarCurWidth, 29, tocolor(189, 0, 0, 255), false) 
    dxDrawText( tostring( math.ceil((pBarCurWidth * 100) / pBarWidth) ).." %", x*358, y*316, (x*358) + pBarWidth, (y*316) + 29, tocolor(255,255,255), 2) 
end 

Posted

Foi um erro meu, faltou colocar root, no segundo argumento em:

addEventHandler("onClientRender", renderDXProgressBar) 

E na parte que remove também.

Se deve ser executado só pro policial então já está certo, porque chama o evento só para o policial na função triggerClientEvent.

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