12p Posted November 6, 2010 Share Posted November 6, 2010 Sorry about this but, I'm learning how to use SQLite3, and I'm doing good But I have this problem: I've used "Top 5 Players" script as example, and I don't know how to carry the SQL values to a GUI... Here is my code (server-side): executeSQLCreateTable ("players","name TEXT, number INTEGER, time_playing INTEGER") local allplayers = getElementsByType ("player") for i,player in ipairs (allplayers) do local name = getPlayerName(player) setElementData (player,"time_playing",0) setTimer ( function (player) local time = getElementData (player,"time_playing") setElementData (player,"time_playing",time+1) if executeSQLInsert ("players","'"..name.."', '1', '"..getElementData(player,"time_playing").."'") then outputDebugString ("SQL Tables updated!") else outputDebugString ("SQL Tables failed to update!",1) end end,1000,0,player) end And my client-side code: GUIEditor_Window = {} GUIEditor_Label = {} GUIEditor_Window[1] = guiCreateWindow(0.015,0.3317,0.3363,0.3417,"Top 5 Players",true) guiWindowSetSizable(GUIEditor_Window[1],false) GUIEditor_Label[1] = guiCreateLabel(0.0335,0.1073,0.9219,0.1171,"1.",true,GUIEditor_Window[1]) GUIEditor_Label[2] = guiCreateLabel(0.0335,0.2732,0.9219,0.0828,"2.",true,GUIEditor_Window[1]) GUIEditor_Label[3] = guiCreateLabel(0.0335,0.4439,0.9219,0.0828,"3.",true,GUIEditor_Window[1]) GUIEditor_Label[4] = guiCreateLabel(0.0335,0.6195,0.9219,0.0828,"4.",true,GUIEditor_Window[1]) GUIEditor_Label[5] = guiCreateLabel(0.0335,0.7805,0.9219,0.0828,"5.",true,GUIEditor_Window[1]) function updateTopPlayers(player,number,time) end addEvent ("onClientUpdate",true) addEventHandler ("onClientUpdate",getRootElement(),updateTopPlayers) I have custom event to get the players and put them into GUI, but no idea how to carry it with triggerClientEvent... Link to comment
dzek (varez) Posted November 6, 2010 Share Posted November 6, 2010 example not related to your script, just general one result = executeSqlQuery (..) if (result and #result>0) then triggerClientEvent(getRootElement(), "updateGuiWithData", getRootElement(), result) end -- client addEvent("updateGuiWithData", true) addEventHandler("updateGuiWithData", getRootElement(), function(result) for key,val in pairs(result) do outputChatBox(tostring(key).." => "..val['column_name']) end end) Link to comment
greacius Posted November 18, 2010 Share Posted November 18, 2010 Any errors? Maybe you can try to make the function inside the setTimer to a seperate function. This would be probably not solve your problem but looks better. 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