Jump to content

Funções para HUD/DX-INFO


Recommended Posts

5yY1ySD.png

Olá gente, com o tempo irei atualizar esse post com novas informações e funções para a criação de uma HUD/DX-INFO

  
-- Oxygenio 
local oxgen = getPedOxygenLevel(getLocalPlayer()) 
  
-- Ninel de procura 
local wanted = getPlayerWantedLevel(getLocalPlayer()) 
  
-- Serial do Jogador 
local serial = getPlayerSerial(getLocalPlayer()) 
  
-- Skin 
local skin = getElementModel(getLocalPlayer()) 
  
--vida 
local health = math.floor (getElementHealth (getLocalPlayer())) 
  
--colete 
local armor = math.floor (getPedArmor ( getLocalPlayer())) 
  
--ping do jogador 
local ping = getPlayerPing(getLocalPlayer()) 
  
--posição do jogador no mapa 
local playerX, playerY, playerZ = getElementPosition (getLocalPlayer())  
local ZonaNome = getZoneName ( playerX, playerY, playerZ ) 
  
--monição no pente da arma 
local ammo = getPedAmmoInClip (localPlayer,getPedWeaponSlot(localPlayer)) 
  
--total de monição 
local ammo1 = getPedTotalAmmo(localPlayer)-getPedAmmoInClip(localPlayer) 
  
--nome da arma 
local weaponName = getWeaponNameFromID (getPedWeapon(getLocalPlayer())) 
  
--ID da arma 
local weaponID = getWeaponNameFromID(getPedWeapon(getLocalPlayer())) 
  
-- Tempo do jogo(12:00) 
local hour, mins = getTime () 
local Time = hour .. ":" .. (((mins < 10) and "0"..mins) or mins) 
  
--dinheiro 
local money = getPlayerMoney ( getLocalPlayer() ) 

Dinheiro no formato [ $ 0 ]

 --função 
local money = math.floor (getPlayerMoney(getLocalPlayer())) 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
function HUD( ) 
local money = math.floor (getPlayerMoney(getLocalPlayer())) 
dxDrawText("$"..money,x*1120, y*50, x*1358, y*40,tocolor(73,208,141,255),1.0,"pricedown","left","top",false,false,false) 
end 
  
local hudTable = { "money" } 
addEventHandler("onClientRender", root, HUD) -- render da hud 
addEventHandler("onClientResourceStart", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, false) 
    end 
    end) 
  
addEventHandler("onClientResourceStop", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, true) 
    end 
end) 

Dinheiro no formato [ $ 00000000 ]

 --função 
local money = string.format("%08d", getPlayerMoney(getLocalPlayer())) 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
function HUD( ) 
local money = string.format("%08d", getPlayerMoney(getLocalPlayer())) 
dxDrawText("$"..money,x*1120, y*50, x*1358, y*40,tocolor(73,208,141,255),1.0,"pricedown","left","top",false,false,false) 
end 
  
local hudTable = { "money" } 
addEventHandler("onClientRender", root, HUD) -- render da hud 
addEventHandler("onClientResourceStart", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, false) 
    end 
    end) 
  
addEventHandler("onClientResourceStop", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, true) 
    end 
end) 

Dinheiro no formato [ $ 1,000,000 ]

 --função 
function convertNumber ( number )   
    local formatted = number   
    while true do       
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')     
        if ( k==0 ) then       
            break   
        end   
    end   
    return formatted 
end 
  
local money = convertNumber(getPlayerMoney(getLocalPlayer())) 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
function HUD( ) 
local money = convertNumber(getPlayerMoney(getLocalPlayer())) 
dxDrawText("$"..money,x*1120, y*50, x*1358, y*40,tocolor(73,208,141,255),1.0,"pricedown","left","top",false,false,false) 
end 
  
--função convertNumber fora da render 
function convertNumber ( number )   
    local formatted = number   
    while true do       
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')     
        if ( k==0 ) then       
            break   
        end   
    end   
    return formatted 
end 
  
local hudTable = { "money" } 
addEventHandler("onClientRender", root, HUD) -- render da hud 
addEventHandler("onClientResourceStart", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, false) 
    end 
    end) 
  
addEventHandler("onClientResourceStop", resourceRoot, function() 
    for id, hudComponents in ipairs(hudTable) do 
        showPlayerHudComponent(hudComponents, true) 
    end 
end) 

Hora Real [ 5 : 9 : 2 ]

 --função 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
        local seconds = getRealTime().second 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
addEventHandler("onClientRender",root, 
    function() 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
        local seconds = getRealTime().second 
   
dxDrawText(hours..":"..minutes..":"..seconds,x*1120, y*50, x*1358, y*40,tocolor(255,255,0,255),0.6,"bankgothic") 
end) 

Hora Real [ 05 : 09 : 02 ]

 --função 
function  getTimeS() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    local seconds = time.second 
    if (hours >= 0 and hours < 10) then 
        hours = "0"..time.hour 
    end 
    if (minutes >= 0 and minutes < 10) then 
        minutes = "0"..time.minute 
    end 
    if (seconds >= 0 and seconds < 10) then 
        seconds = "0"..time.second 
    end 
    return hours..":"..minutes..":"..seconds 
end 
local tempo = getTimeS() 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
function  getTimeS() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    local seconds = time.second 
    if (hours >= 0 and hours < 10) then 
        hours = "0"..time.hour 
    end 
    if (minutes >= 0 and minutes < 10) then 
        minutes = "0"..time.minute 
    end 
    if (seconds >= 0 and seconds < 10) then 
        seconds = "0"..time.second 
    end 
    return hours..":"..minutes..":"..seconds 
end 
  
addEventHandler("onClientRender",root, 
    function() 
local tempo = getTimeS() 
dxDrawText(tempo,x*1120, y*50, x*1358, y*40,tocolor(255,255,0,255),0.6,"bankgothic") 
end) 

FPS do jogador [FPS: 10]

--função 
local fps = false 
function getCurrentFPS() -- Setup the useful function 
    return fps 
end 
  
local function updateFPS(msSinceLastFrame) 
    -- FPS are the frames per second, so count the frames rendered per milisecond using frame delta time and then convert that to frames per second. 
    fps = (1 / msSinceLastFrame) * 1000 
end 
addEventHandler("onClientPreRender", root, updateFPS) 
  
  
--exemplo 
local sx = guiGetScreenSize() 
local function drawFPS() 
    if not getCurrentFPS() then 
        return 
    end 
    local roundedFPS = math.floor(getCurrentFPS()) 
    dxDrawText(roundedFPS, sx - dxGetTextWidth(roundedFPS), 0) 
end 
addEventHandler("onClientHUDRender", root, drawFPS) 

Edited by Guest
Link to comment
  • 3 weeks later...
  • 3 weeks later...
Hora Real [ 16:02:00 ] -- Novo
  
--função 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
        local seconds = getRealTime().second 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
addEventHandler("onClientRender",root, 
    function() 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
        local seconds = getRealTime().second 
   
dxDrawText(hours..":"..minutes..":"..seconds,x*1120, y*50, x*1358, y*40,tocolor(255,255,0,255),0.6,"bankgothic") 
    end 
) 
  

isso não vai mostrar a hora no formato 16:02:00, vai mostrar nesse: 16:2:0

Você pode usar essa função para mostrar a hora no formato que você pretendia

function getTimeS() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    local seconds = time.second 
    if (hours >= 0 and hours < 10) then 
        hours = "0"..time.hour 
    end 
    if (minutes >= 0 and minutes < 10) then 
        minutes = "0"..time.minute 
    end 
    if (seconds >= 0 and seconds < 10) then 
        seconds = "0"..time.second 
    end 
    return hours..":"..minutes..":"..seconds 
end 
  

Ficaria assim no seu codigo:

dxDrawText(getTimeS(),x*1120, y*50, x*1358, y*40,tocolor(255,255,0,255),0.6,"bankgothic") 

Link to comment
Hora Real [ 05 : 09 : 02 ]
 --função 
function  getTimeS() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    local seconds = time.second 
    if (hours >= 0 and hours < 10) then 
        hours = "0"..time.hour 
    end 
    if (minutes >= 0 and minutes < 10) then 
        minutes = "0"..time.minute 
    end 
    if (seconds >= 0 and seconds < 10) then 
        seconds = "0"..time.second 
    end 
    return hours..":"..minutes..":"..seconds 
end 
local time = getTimeS() 
  
  
--exemplo 
local screenW,screenH = guiGetScreenSize() 
local resW, resH = 1280, 720 
local x, y =  (screenW/resW), (screenH/resH) 
  
function  getTimeS() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    local seconds = time.second 
    if (hours >= 0 and hours < 10) then 
        hours = "0"..time.hour 
    end 
    if (minutes >= 0 and minutes < 10) then 
        minutes = "0"..time.minute 
    end 
    if (seconds >= 0 and seconds < 10) then 
        seconds = "0"..time.second 
    end 
    return hours..":"..minutes..":"..seconds 
end 
local time = getTimeS() 
  
addEventHandler("onClientRender",root, 
    function() 
   
dxDrawText(time,x*1120, y*50, x*1358, y*40,tocolor(255,255,0,255),0.6,"bankgothic") 
end) 

Isso não vai funcionar corretamente, você esta definindo a variável time quando o resource for iniciado, então ela vai retornar o valor do mesmo. Para corrigir isso você pode definir a variável dentro da função onde você desenha o texto, porque o evento onClientRender vai ser executado sempre quando o jogador estiver renderizando o GTA, então o valor da variavel sempre vai mudar por rasões obvias..., ou você pode usar o exemplo que eu te dei antes

Link to comment
Eu acho que estudar lua um pouco iria ser mais vantajoso para você do que testar se oque eu disse esta correto ou não. Porque alem de você aprender mais, você iria entender melhor :)

está me parecendo com o Xeon, mais de qualquer maneira todos nós sabemos que testar é a melhor maneira de ver algum bug ou erro, se nem você estava dando conta de ajudar o ~#Pedro, agora vem aqui tentar me corrigir ? kkk não falo mais nada

Porfavor não saia do assunto do Tópico :wink:

Link to comment

Eu só te dei um conselho... me desculpe se eu fui rude. É claro que testar é a melhor maneira de encontrar bugs e erros, eu não disse o contrario :wink: E eu não entendi porque você acha que eu não dei conta de ajudar ele lol.

Me desculpe se eu sai fora do assunto do tópico, mas eu só quis esclarecer, porque você não entendeu que eu só te dei um conselho...

Link to comment

@MaligNos, Também pode ser usado a string.format. más estou fazendo de um jeito mais fácil para "iniciantes" também entender :wink:

#Testado!

é só manter a variável dentro da render que não irá ter problemas

local tempo = getTimeS() 

Link to comment
  • Moderators
@MaligNos, Também pode ser usado a string.format. más estou fazendo de um jeito mais fácil para "iniciantes" também entender :wink:

Acho que usando string.format seria, na verdade, mais fácil tanto quanto o outro método, e ocupa apenas uma linha.

Link to comment
  • 2 weeks later...
  • 2 weeks later...
  • Moderators

A função do FPS tem erros.

Código:

local fps = false 
function getCurrentFPS() -- Setup the useful function 
    return fps 
end 
  
local function updateFPS(msSinceLastFrame) 
    -- FPS are the frames per second, so count the frames rendered per milisecond using frame delta time and then convert that to frames per second. 
    fps = (1 / msSinceLastFrame) * 1000 
end 
addEventHandler("onClientPreRender", root, updateFPS) 

Exemplo:

local sx = guiGetScreenSize() 
local function drawFPS() 
    if not getCurrentFPS() then 
        return 
    end 
    local roundedFPS = math.floor(getCurrentFPS()) 
    dxDrawText(roundedFPS, sx - dxGetTextWidth(roundedFPS), 0) 
end 
addEventHandler("onClientHUDRender", root, drawFPS) 

https://wiki.multitheftauto.com/wiki/GetCurrentFPS

Link to comment
  • Moderators

O código que você postou da função getCurrentFPS tá errado:

--função 
local function drawFPS() 
    if not getCurrentFPS() then 
        return 
    end 
    local roundedFPS = math.floor(getCurrentFPS()) 
  
  
--exemplo 
local sx = guiGetScreenSize() 
local function drawFPS() 
    if not getCurrentFPS() then 
        return 
    end 
    local roundedFPS = math.floor(getCurrentFPS()) 
    dxDrawText(roundedFPS, sx - dxGetTextWidth(roundedFPS), 0) 
end 
addEventHandler("onClientHUDRender", root, drawFPS) 

Link to comment
  • 2 months later...
  • 1 month later...

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