Jump to content

Show ping on screen script


downight

Recommended Posts

Hi, I want to show ping on screen. I've made code but doesn't work since I'm learning how to script :S Please help me :)

function DXdraw() 
--Variables 
        local screenWidth, screenHeight = guiGetScreenSize ( ) 
setTimer(function() 
triggerServerEvent("online",getLocalPlayer())  
end, 10000, 1, true) 
  
                 local ping = getPlayerPing ( getLocalPlayer(), "ping") 
  g_dxGUI = { 
  ping = dxText:create("PING: ", screenWidth - 202,screenHeight - 86, false, 'bankgothic', 0.7), 
  pingNumber = dxText:create(..ping, screenWidth - 150,screenHeight - 86, false, 'bankgothic', 0.7) 
  } 
  g_dxGUI.ping:color(255, 255, 255, 255) 
  g_dxGUI.pingNumber:color(128,255,0,255) 
  g_dxGUI.ping:type("shadow", 1, 0, 0, 0, 255) 
  g_dxGUI.pingNumber:type("shadow", 1, 0, 0, 0, 255) 
  
end 
  
addEventHandler("onClientRender", getRootElement(), DXdraw) 
  
local pingEnabled = true 
function ping() 
    if pingEnabled then 
        g_dxGUI.ping:visible(false) 
        g_dxGUI.pingNumber:visible(false) 
        pingEnabled = false 
    else 
        g_dxGUI.pingEnabled = true 
        g_dxGUI.ping:visible(true) 
        g_dxGUI.pingNumber:visible(true)         
    end 
end 
addCommandHandler("ping", ping, false, false) 

Link to comment
local screenWidth, screenHeight = guiGetScreenSize ( ) 
setTimer (  
    function ( ) triggerServerEvent("online", localPlayer) end 
, 10000, 0) 
function DXdraw() 
     
     
  
    local ping = getPlayerPing ( localPlayer ) 
    g_dxGUI = { 
    ping = dxText:create("PING: ", screenWidth - 202,screenHeight - 86, false, 'bankgothic', 0.7), 
    pingNumber = dxText:create(ping, screenWidth - 150,screenHeight - 86, false, 'bankgothic', 0.7) 
    } 
    g_dxGUI.ping:color(255, 255, 255, 255) 
    g_dxGUI.pingNumber:color(128,255,0,255) 
    g_dxGUI.ping:type("shadow", 1, 0, 0, 0, 255) 
    g_dxGUI.pingNumber:type("shadow", 1, 0, 0, 0, 255) 
  
end 

Check this out. But are you sure that you want trigger server event every frame? This function is turning on 30-60 times per second. I put this timer before the function.

Link to comment

Nvm for now. This ping code works good but I want "ping" text white and "ping number" 128,255,0

function DXdraw() 
--Variables 
        local screenWidth, screenHeight = guiGetScreenSize ( ) 
setTimer(function() 
triggerServerEvent("online",getLocalPlayer())  
end, 10000, 1, true) 
  
                 local ping = getPlayerPing ( getLocalPlayer(), "ping2") 
  ping2= ' Ping:' ..ping 
dxDrawText(tostring(ping2),0, screenHeight - 190, screenWidth, screenHeight,tocolor(128,255,0),0.7,"bankgothic")  
  
end 
  
addEventHandler("onClientRender", getRootElement(), DXdraw) 

Link to comment
function DXdraw() 
    --Variables 
    local screenWidth, screenHeight = guiGetScreenSize ( ) 
    setTimer(function() 
    triggerServerEvent("online",getLocalPlayer()) 
    end, 10000, 1, true) 
      
    local ping = getPlayerPing ( localPlayer ) 
    dxDrawText(tostring(ping), 0, screenHeight - 190, screenWidth, screenHeight,tocolor(128, 255, 0, 255),0.7,"bankgothic") 
    dxDrawText("Ping:", 0, screenHeight - 190, screenWidth, screenHeight,tocolor(255, 255, 255, 255),0.7,"bankgothic") 
     
end 
addEventHandler("onClientRender", getRootElement(), DXdraw) 

You just need to change position in 2nd text.

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