#Madara Posted August 1, 2015 Posted August 1, 2015 Hi guys , Today I made Chat Log and i want to save the Log ( Text ) in the grid list when resource start or stop how i save that with using executeSQLQuery ? i need examples please because i want to learn how to connect sql with gridlist .
JR10 Posted August 1, 2015 Posted August 1, 2015 viewtopic.php?f=148&t=38203 I would suggest saving logs in .txt files instead of SQL. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
#Madara Posted August 2, 2015 Author Posted August 2, 2015 Anyone can explain to me how i save the log with sql ?
GTX Posted August 2, 2015 Posted August 2, 2015 It's quite easy, create a table like executeSQLQuery("CREATE TABLE IF NOT EXISTS logs (name TEXT, message TEXT)") Then you can insert the logs with executeSQLQuery("INSERT INTO logs (name, message) VALUES(?, ?)", getPlayerName(player), message) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 It's quite easy, create a table like executeSQLQuery("CREATE TABLE IF NOT EXISTS logs (name TEXT, message TEXT)") Then you can insert the logs with executeSQLQuery("INSERT INTO logs (name, message) VALUES(?, ?)", getPlayerName(player), message) ok now how i put what i save in sql in grid list ? Client : addEventHandler("onClientResourceStart", resourceRoot, function() Window = guiCreateWindow(373, 189, 519, 426, "..: [ Chat Log v1.0 ] :..", false) guiWindowSetSizable(Window, false) guiSetAlpha(Window, 1.00) guiSetVisible(Window,false) GridList = guiCreateGridList(9, 24, 500, 392, false, Window) plrName = guiGridListAddColumn(GridList, "# Player Name :", 0.4) plrMsg = guiGridListAddColumn(GridList, "# Chat Message :", 0.4) end ) addEvent("INSERT!",true) addEventHandler("INSERT!",root, function(name , msg) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrName,tostring(name), false, false ) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrMsg,tostring(msg), false, false ) end ) local Key = "F5" bindKey(Key,"down", function () guiSetVisible( Window , not guiGetVisible(Window)) showCursor(guiGetVisible(Window)) end ) Server : addEventHandler("onResourceStart",root, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS logs (name TEXT, message TEXT)") end ) addEventHandler("onPlayerChat",root, function(msg,_) if ( msg ~= "") or ( msg ~= " ") then local name = getPlayerName(source) triggerClientEvent(source,"INSERT!",source,name,msg) executeSQLQuery("INSERT INTO logs (name, message) VALUES(?, ?)", getPlayerName(source), msg) end end )
GTX Posted August 2, 2015 Posted August 2, 2015 You mean how to fetch data? executeSQLQuery("SELECT * FROM logs") Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 You mean how to fetch data? executeSQLQuery("SELECT * FROM logs") yes and put them in grid list
GTX Posted August 2, 2015 Posted August 2, 2015 That will return a table, send it to client and then loop through it and add them to gridlist. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 That will return a table, send it to client and then loop through it and add them to gridlist. i should create a new table ?
GTX Posted August 2, 2015 Posted August 2, 2015 Nope, that code I sent you will return Lua array and you'll have to send it to client and then loop through it. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 Nope, that code I sent you will return Lua array and you'll have to send it to client and then loop through it. can u give me example please ?
#Madara Posted August 2, 2015 Author Posted August 2, 2015 (edited) like this ? Client : addEventHandler("onClientResourceStart", resourceRoot, function() Window = guiCreateWindow(373, 189, 519, 426, "..: [ Chat Log v1.0 ] :..", false) guiWindowSetSizable(Window, false) guiSetAlpha(Window, 1.00) guiSetVisible(Window,false) GridList = guiCreateGridList(9, 24, 500, 392, false, Window) plrName = guiGridListAddColumn(GridList, "# Player Name :", 0.4) plrMsg = guiGridListAddColumn(GridList, "# Chat Message :", 0.4) end ) addEvent("INSERT!",true) addEventHandler("INSERT!",root, function(name , msg) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrName,tostring(name), false, false ) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrMsg,tostring(msg), false, false ) end ) local Key = "F5" bindKey(Key,"down", function () guiSetVisible( Window , not guiGetVisible(Window)) showCursor(guiGetVisible(Window)) end ) addEvent("Send",true) addEventHandler("Send",root, function(sql) for k , v in pairs (sql) then guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrName,tostring(v), false, false ) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrMsg,tostring(v), false, false ) end ) Server : addEventHandler("onResourceStart",root, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS logs (name TEXT, message TEXT)") Save() end ) addEventHandler('onResourceStop',root, function() Update() end ) addEventHandler("onPlayerChat",root, function(msg,_) if ( msg ~= "") or ( msg ~= " ") then local name = getPlayerName(source) triggerClientEvent(source,"INSERT!",source,name,msg) executeSQLQuery("INSERT INTO logs (name, message) VALUES(?, ?)", getPlayerName(source), msg) end end ) function Save() local Save = executeSQLQuery("SELECT * FROM logs") triggerClientEvent(client,'Send'client,Save) end function Update() executeSQLQuery('UPDATE `logs` SET message =? WHERE name =?',msg,name) end Edited August 2, 2015 by Guest
GTX Posted August 2, 2015 Posted August 2, 2015 Example: Server: local logs = executeSQLQuery("SELECT * FROM logs") if #logs > 0 then triggerClientEvent("addLogs", root, logs) end Client: function addLogs(logs) for i, v in ipairs(logs) do guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrName, v.name, false, false) guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrMsg, v.message, false, false) end end addEvent("addLogs", true) addEventHandler("addLogs", root, addLogs) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 DebugScript : ERROR: Server triggered clientside event addLogs, but event is not added clientside Client : addEventHandler("onClientResourceStart", resourceRoot, function() Window = guiCreateWindow(373, 189, 519, 426, "..: [ Chat Log v1.0 ] :..", false) guiWindowSetSizable(Window, false) guiSetAlpha(Window, 1.00) guiSetVisible(Window,false) GridList = guiCreateGridList(9, 24, 500, 392, false, Window) plrName = guiGridListAddColumn(GridList, "# Player Name :", 0.4) plrMsg = guiGridListAddColumn(GridList, "# Chat Message :", 0.4) end ) addEvent("INSERT!",true) addEventHandler("INSERT!",root, function(name , msg) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrName,tostring(name), false, false ) guiGridListSetItemText (GridList,guiGridListAddRow ( GridList ), plrMsg,tostring(msg), false, false ) end ) local Key = "F5" bindKey(Key,"down", function () guiSetVisible( Window , not guiGetVisible(Window)) showCursor(guiGetVisible(Window)) end ) function addLogs(logs) for i, v in ipairs(logs) do guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrName, v.name, false, false) guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrMsg, v.message, false, false) end end addEvent("addLogs", true) addEventHandler("addLogs", root, addLogs) Server : addEventHandler("onResourceStart",root, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS logs (name TEXT, message TEXT)") Load() end ) addEventHandler("onPlayerChat",root, function(msg,_) if ( msg ~= "") or ( msg ~= " ") then local name = getPlayerName(source) triggerClientEvent(source,"INSERT!",source,name,msg) executeSQLQuery("INSERT INTO logs (name, message) VALUES(?, ?)", getPlayerName(source), msg) end end ) function Load() local logs = executeSQLQuery("SELECT * FROM logs") if #logs > 0 then triggerClientEvent("addLogs", root, logs) end end
GTX Posted August 2, 2015 Posted August 2, 2015 Client side must be first in meta to load. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 Client side must be first in meta to load. it's first and debugscript say to me ERROR: Server triggered clientside event addLogs, but event is not added clientside meta
GTX Posted August 2, 2015 Posted August 2, 2015 I don't understand, why do you bold your text? It's always the same. addEventHandler("onClientResourceStart", resourceRoot, function() Window = guiCreateWindow(373, 189, 519, 426, "..: [ Chat Log v1.0 ] :..", false) guiWindowSetSizable(Window, false) guiSetAlpha(Window, 1.00) guiSetVisible(Window,false) GridList = guiCreateGridList(9, 24, 500, 392, false, Window) plrName = guiGridListAddColumn(GridList, "# Player Name :", 0.4) plrMsg = guiGridListAddColumn(GridList, "# Chat Message :", 0.4) triggerServerEvent("requestData", localPlayer) end ) function Load() local logs = executeSQLQuery("SELECT * FROM logs") if #logs > 0 then triggerClientEvent(source, "addLogs", source, logs) end end addEvent("requestData", true) addEventHandler("requestData", root, Load) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 ok it's work now , i have problem in gridlist this is the problem : i want the message be next player name like this :
GTX Posted August 2, 2015 Posted August 2, 2015 That's because you add rows twice for each column. guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrName, v.name, false, false) guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrMsg, v.message, false, false) Add it only once. local row = guiGridListAddRow(GridList) guiGridListSetItemText(GridList, row, plrName, v.name, false, false) guiGridListSetItemText(GridList, row, plrMsg, v.message, false, false) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
#Madara Posted August 2, 2015 Author Posted August 2, 2015 That's because you add rows twice for each column. guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrName, v.name, false, false) guiGridListSetItemText(GridList, guiGridListAddRow(GridList), plrMsg, v.message, false, false) Add it only once. local row = guiGridListAddRow(GridList) guiGridListSetItemText(GridList, row, plrName, v.name, false, false) guiGridListSetItemText(GridList, row, plrMsg, v.message, false, false) ah thank you very much
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