The Killer Posted November 30, 2013 Share Posted November 30, 2013 hello how can i make the label refresh every 1 sec ? Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 You can use the setTimer for example. Not the best choice but there aren't many other anyways. If it's a temporary label, then it should be good. I suggest looking at text items as well. Link to comment
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) so i did use it like this : setTimer (guiSetText, 1000, 0, ping, Ping) but if i select another player it still in the gui ? Edited November 30, 2013 by Guest Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 You have to kill the timer with killTimer. Link to comment
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 is there any other way cause i use killTimer if the player select no one, it's work but if i reselect the player and select no one it kill the timer but the other timer that i reselected not killed , so is there any other way ? Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 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
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 i did like what you say but didn't work it work but if i select a player after 1 sec it's show his ping i want it if the ping change then in the label change too, and i want to tell you that i'm using trigger if that make different. Link to comment
TAPL Posted November 30, 2013 Share Posted November 30, 2013 trigger? getPlayerPing is exists both side. Post your code so we can see where is the problem. Link to comment
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 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
Castillo Posted November 30, 2013 Share Posted November 30, 2013 You're trying to get the ping of a remote player? Link to comment
TAPL Posted November 30, 2013 Share Posted November 30, 2013 What you post make no sense, i don't even see where is getPlayerPing. Link to comment
Castillo Posted November 30, 2013 Share Posted November 30, 2013 What are you trying to do then? get the ping of the local player? Link to comment
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) 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 December 2, 2013 by Guest Link to comment
Castillo Posted November 30, 2013 Share Posted November 30, 2013 That's exactly what I said, why did you said no then? Link to comment
The Killer Posted November 30, 2013 Author Share Posted November 30, 2013 TAPL, it's work but i want it refresh, i want it if the ping change then in the label change. @solid sorry because i didn't understand you. Link to comment
TAPL Posted November 30, 2013 Share Posted November 30, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now