Jump to content

Simple SQL Question (hope you solve it :P)


12p

Recommended Posts

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

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
  • 2 weeks 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...