Jump to content

[Question] label


The Killer

Recommended Posts

This is a good example on how to make it work regardless of where you click on your screen.

local updateLabel, updateGridlist -- initialize two nil timers 
local label = guiCreateLabel(500, 100, 100, 50, "nil: nil", false) -- create a gui label at 500,100 
local gridlist = guiCreateGridList(600, 100, 170, 180, false) -- create a gui gridlist at 600,100 
guiGridListAddColumn(gridlist, "vehicle name", 0.7) -- add a column to the gridlist 
guiGridListAddColumn(gridlist, "r", 0.2) -- and another column 
  
for i,v in ipairs(getElementsByType("vehicle")) do -- loop through all vehicles on the server 
    if (i > 10) then break end -- break at ten 
    local row = guiGridListAddRow(gridlist) -- add a new row to the gridlist 
    guiGridListSetItemText(gridlist, row, 1, getVehicleName(v), false, false) -- give the name column a value 
    guiGridListSetItemText(gridlist, row, 2, math.random(100,999), false, false) -- and the r column as well 
end 
  
updateGridlist = setTimer(function() -- execute a new timer to update the r columns 
    if (isElement(gridlist)) then killTimer(updateGridlist) return end -- if the gridlist is no longer, kill the timer 
    for i=0,guiGridListGetRowCount(gridlist) do -- loop through all rows 
        guiGridListSetItemText(gridlist, i, 2, math.random(100,999), false, false) -- update the gridlist column with a new random value 
    end 
end, 1000, 0) -- do the function each 1000ms 
  
addEventHandler("onClientGUIClick", gridlist, -- when the gridlist is clicked on, do the function 
    function() 
        local row, col = guiGridListGetSelectedItem(gridlist) -- get the currently selected row and column 
        if (isTimer(updateLabel)) then killTimer(updateLabel) end -- if the timer exists, kill the timer 
        if (row ~= -1) and (col ~= -1) then -- if they clicked some row 
            local text1 = guiGridListGetItemText(gridlist, row, 1) -- get the name column value 
            local text2 = guiGridListGetItemText(gridlist, row, 2) -- and the r column 
            guiSetText(label, text1 .. ": " .. text2) -- update the current values 
            updateLabel = setTimer(function(row) -- execute a new timer to update them constantly 
                if (isElement(gridlist)) then killTimer(updateLabel) return end -- if the gridlist is no longer, kill the timer 
                local text1 = guiGridListGetItemText(gridlist, row, 1) -- get the name column value again 
                local text2 = guiGridListGetItemText(gridlist, row, 2) -- and the r column value as well 
                guiSetText(label, text1 .. ": " .. text2) -- and then update the label 
            end, 1000, 0, row) -- do the function each 1000ms for the corresponding row 
        end 
    end 
) 

Link to comment

addEventHandler("onClientGUIClick",root, 
function () 
if source == mgrid then 
killTimer(tim)  
local name = guiGridListGetItemText ( mgrid, guiGridListGetSelectedItem (mgrid), 1 ) 
if name and name ~= "" then 
triggerServerEvent("ping",localPlayer, name) 
end 
end 
end 
) 

addEvent("setPlayerPing",true) 
addEventHandler("setPlayerPing",root,function(Ping) 
if (isTimer(tim)) then killTimer(tim) end  
tim = setTimer (guiSetText, 1000, 0, ping, Ping) 
end 
) 
Link to comment

i did say that i do trigger

addEvent("ping",true) 
addEventHandler("ping",root,function(pla) 
  triggerClientEvent(source,"setPlayerPing",source,getPlayerPing(getPlayerFromName(pla))) 
 end 
) 

@solid

i'm trying to make when someone select a player from the grid then show his ping

and if his ping change then in the label change too.

Edited by Guest
Link to comment

Client Side:

addEventHandler("onClientGUIClick", root, 
function() 
    if source == mgrid then 
        local name = guiGridListGetItemText(mgrid, guiGridListGetSelectedItem (mgrid), 1) 
        if name and name ~= "" then 
            if isTimer(tim) then killTimer(tim) end 
            tim = setTimer(function(name)  
                local player = getPlayerFromName(name) 
                if isElement(player) then 
                    guiSetText(ping, tostring(getPlayerPing(player))  
                else 
                    if isTimer(tim) then killTimer(tim) end 
                end 
            end, 1000, 0, name) 
        else 
            if isTimer(tim) then killTimer(tim) end 
        end 
    end 
end) 

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