jef Posted October 27, 2013 Share Posted October 27, 2013 Hello, Im currently making a 'Online Players' Window for mine new fresh gamemode. All mine players data are stored in Mysql Databases. I have now created the gui for the window. But i have now problem with the guiGridListSetItemText. The problem is that Mysql is serverside and guiGridListSetItemText is clientside. I have now currently have this in serverside: function StartOnlineTimer ( ) setTimer(RefreshOnline, 1000, 0, player) end addEventHandler ( "onPlayerJoin", getRootElement(), StartOnlineTimer ) function RefreshOnline() local result = mysql_query(handler, "SELECT * FROM accounts") if (result) then while true do local row = mysql_fetch_assoc(result) if (not row) then break end -- outputDebugString(row["name"]) -- outputDebugString(row["viplevel"]) -- outputDebugString(row["level"]) -- outputDebugString(row["money"]) end mysql_free_result(result) end end What functions should i use to send this data from serverside to clientside, So the clientside can use guiGridListSetItemText with the data received from serverside? triggerClientEvent i think? Link to comment
tosfera Posted October 27, 2013 Share Posted October 27, 2013 You are right, you can use a triggerClientEvent to trigger an event in the client side of your system. Giving the triggerClientEvent a few parameters would allow you to set the text. The easiest way to do so is to send a table filled with data to the client side. loop through all your players and use table.insert to insert them into a table. Which you will use as a parameter in your triggerClientEvent. Dont forget to add the event client sided using addEvent. Link to comment
jef Posted October 27, 2013 Author Share Posted October 27, 2013 Thanks for reply, I will try out. Link to comment
jef Posted October 28, 2013 Author Share Posted October 28, 2013 Hello, I have question about sending the table from serverside to clientside, How i can do this with triggerClientEvent? I have this: Clientside function SendGridRow() for index, variable in ipairs (TabelPlayers) do local name, viplevel, level, money = unpack(TabelPlayers) outputChatBox (name) end end Serverside function RefreshOnline() TabelPlayers = { } local result = mysql_query(handler, "SELECT * FROM accounts") if (result) then while true do local row = mysql_fetch_assoc(result) if (not row) then break end TabelPlayers = {{row.name, row.viplevel, row.level,row.money}} -- outputDebugString(row["name"]) -- outputDebugString(row["viplevel"]) -- outputDebugString(row["level"]) -- outputDebugString(row["money"]) end mysql_free_result(result) end triggerClientEvent ( "SendGridRow", getRootElement()) end Link to comment
tosfera Posted October 28, 2013 Share Posted October 28, 2013 Oke, that is a very ugly way of creating a table containing all the users, I won't create the code for you but take a look at the code I'm using to fill tables; local result = {} while true do local row = mysql_fetch_assoc( iselect ) if (not row) then break end table.insert(result, row) end this will actualy create a table and fill in all the users. All you have to do left is send the table 'result' as a parameter to the client side; triggerClientEvent ( "fillGrid", getRootElement(), result ) by the way, I wouldn't prefer using getRootElement() as a player element. Also, change the client function to; function fillGrid( playerTable) for i, player in ipairs ( playerTable ) do outputChatBox ( playerTable[i]["Name"] ); end end addEvent ( "fillGrid", true ); addEventHandler ( "fillGrid", getRootElement(), fillGrid ) 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