HUNGRY:3 Posted August 9, 2015 Posted August 9, 2015 hello so i made a chat in the grid list... i want to save the chat like when i type hi and then i reconnect i find the "hi" in the grid :3 so how to do it?
Malak Posted August 9, 2015 Posted August 9, 2015 Use XML who will be saved when someone type something (don't saved all chat only save the last 30 message for exemple. Then load it when u connect on the server.
HUNGRY:3 Posted August 9, 2015 Author Posted August 9, 2015 thank you.. but how to save the only 30 last msgs?
GTX Posted August 9, 2015 Posted August 9, 2015 Put them in a table and then insert messages like: local messages = {} table.insert(messages, 1, {playerName, message}) -- Insert a message into table at first position. if #messages > 30 then table.remove(messages) -- Remove last one end MySQL is much more faster and convenient than XML. Maybe you could use it and you wouldn't need to save only 30 last messages. You could make custom logs. And if you still want to fetch only 30 messages, you could easily fetch latest 30 from MySQL database by using LIMIT.
HUNGRY:3 Posted August 9, 2015 Author Posted August 9, 2015 i have no idea what i'm doing... it's not working local posFile = xmlLoadFile ("req.xml") if not posFile then posFile = xmlCreateFile ("req.xml", "root") end local text local newNode function add() for id, playeritem in ipairs(getElementsByType("player")) do if source == REQ.button[1] then text = guiGetText(REQ.edit[1]) local row = guiGridListAddRow ( REQ.gridlist[1] ) local row2 = guiGridListAddRow ( REQ.gridlist[1] ) if string.len(text) > 0 then if posFile then newNode = xmlCreateChild(posFile, text) if xmlNodeSetValue (newNode, text) then xmlSaveFile(posFile) guiGridListSetItemText ( REQ.gridlist[1], row, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row, 2, text, false, false ) end end end end end end addEventHandler("onClientGUIClick",root,add) function save() for id, playeritem in ipairs(getElementsByType("player")) do local rowx = guiGridListAddRow ( REQ.gridlist[1] ) local row2x = guiGridListAddRow ( REQ.gridlist[1] ) guiGridListSetItemText ( REQ.gridlist[1], rowx, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row2x, 2, text, false, false ) end end addEventHandler("onClientResourceStart",root,save)
iMr.SFA7 Posted August 9, 2015 Posted August 9, 2015 local posFile = xmlLoadFile ("req.xml") function ( ) if not posFile then posFile = xmlCreateFile ("req.xml", "root") end end local text local newNode function add() for id, playeritem in ipairs(getElementsByType("player")) do if source == REQ.button[1] then text = guiGetText(REQ.edit[1]) local row = guiGridListAddRow ( REQ.gridlist[1] ) if string.len(text) > 0 then if posFile then newNode = xmlCreateChild(posFile, text) if xmlNodeSetValue (newNode, text) then xmlSaveFile(posFile) guiGridListSetItemText ( REQ.gridlist[1], row, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row, 2, text, false, false ) end end end end end end addEventHandler("onClientGUIClick",root,add) function save() for id, playeritem in ipairs(getElementsByType("player")) do local rowx = guiGridListAddRow ( REQ.gridlist[1] ) guiGridListSetItemText ( REQ.gridlist[1], rowx, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], rowx, 2, text, false, false ) end end addEventHandler("onClientResourceStart",root,save)
HUNGRY:3 Posted August 9, 2015 Author Posted August 9, 2015 local posFile = xmlLoadFile ("req.xml") function ( ) if not posFile then posFile = xmlCreateFile ("req.xml", "root") end end local text local newNode function add() for id, playeritem in ipairs(getElementsByType("player")) do if source == REQ.button[1] then text = guiGetText(REQ.edit[1]) local row = guiGridListAddRow ( REQ.gridlist[1] ) if string.len(text) > 0 then if posFile then newNode = xmlCreateChild(posFile, text) if xmlNodeSetValue (newNode, text) then xmlSaveFile(posFile) guiGridListSetItemText ( REQ.gridlist[1], row, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row, 2, text, false, false ) end end end end end end addEventHandler("onClientGUIClick",root,add) function save() for id, playeritem in ipairs(getElementsByType("player")) do local rowx = guiGridListAddRow ( REQ.gridlist[1] ) guiGridListSetItemText ( REQ.gridlist[1], rowx, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], rowx, 2, text, false, false ) end end addEventHandler("onClientResourceStart",root,save) nope it doesn't save the text.
iMr.SFA7 Posted August 9, 2015 Posted August 9, 2015 try local posFile = xmlLoadFile ("req.xml") function ( ) if not posFile then posFile = xmlCreateFile ("req.xml", "root") end end function add() for id, playeritem in ipairs(getElementsByType("player")) do if source == REQ.button[1] then text = guiGetText(REQ.edit[1]) row = guiGridListAddRow ( REQ.gridlist[1] ) if string.len(text) > 0 then if posFile then newNode = xmlCreateChild(posFile, text) if xmlNodeSetValue (newNode, text) then xmlSaveFile(posFile) guiGridListSetItemText ( REQ.gridlist[1], row, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row, 2, text, false, false ) end end end end end end addEventHandler("onClientGUIClick",root,add) function save() for id, playeritem in ipairs(getElementsByType("player")) do guiGridListSetItemText ( REQ.gridlist[1], row, 1, getPlayerName ( playeritem ), false, false ) guiGridListSetItemText ( REQ.gridlist[1], row, 2, text, false, false ) end end addEventHandler("onClientResourceStart",resourceRoot,save)
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