fairyoggy Posted July 30, 2019 Share Posted July 30, 2019 --client addEventHandler("onClientGUIClick", root, function () if ( source == button ) then local jaloba = guiGetText(edit1) local name = getPlayerName(getLocalPlayer(source)) servertime = getRealTime () hours = (servertime.hour) minutes = string.format("%02d", servertime.minute) second = string.format("%02d", servertime.second) guiGridListAddRow(gridSms,hours..":"..minutes..":"..second,name,jaloba) end end) The player stores the information in the gridlist only for himself, how to do the same for the server? I mean, if a player adds this information to the gridlist, only he sees it, and others do not Link to comment
HassoN Posted July 30, 2019 Share Posted July 30, 2019 You send the text to server side, store it in a table, then whenever someone opens the panel, you trigger to server side to get the text from that table. Link to comment
fairyoggy Posted July 30, 2019 Author Share Posted July 30, 2019 15 minutes ago, HassoN said: You send the text to server side, store it in a table, then whenever someone opens the panel, you trigger to server side to get the text from that table. I haven't mastered the tables yet. I do not understand You can 1 example, save at least one line from gridlist and then transfer it to the server that other players would see? Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 -- client side triggerServerEvent("sendText", resourceRoot, text) -- text represents the text string you want to show in everyone's GUI. -- server side local savedText = {} function savedText(text) table.insert(savedText, text) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) -- client side again function showText(myTable) for i, v in ipairs(myTable) do -- whatever you want, but for example: guiGridListAddRow(gridlist, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) I have used a table so you can call it whenever you want to show the text even if the player reconnects. But if you don't care about if the text gets lost if the player reconnects then ignore the usage of tables. Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 2 hours ago, HassoN said: -- client side triggerServerEvent("sendText", resourceRoot, text) -- text represents the text string you want to show in everyone's GUI. -- server side local savedText = {} function savedText(text) table.insert(savedText, text) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) -- client side again function showText(myTable) for i, v in ipairs(myTable) do -- whatever you want, but for example: guiGridListAddRow(gridlist, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) I have used a table so you can call it whenever you want to show the text even if the player reconnects. But if you don't care about if the text gets lost if the player reconnects then ignore the usage of tables. I understood correctly? --client function sendreport () local name = getPlayerName(getLocalPlayer(source)) guiGridListAddRow(gridSms,name) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function savedText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 (edited) 13 minutes ago, slapz0r said: I understood correctly? --client function sendreport () local name = getPlayerName(getLocalPlayer(source)) guiGridListAddRow(gridSms,name) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function savedText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Yes, but remove line 5. guiGridListAddRow(gridSms,name) Edited July 31, 2019 by HassoN Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 6 minutes ago, HassoN said: Yes, but remove line 5. Without this line does not add even for 1 player Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 (edited) 9 minutes ago, slapz0r said: Without this line does not add even for 1 player --client function sendreport () local name = getPlayerName(localPlayer) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function sendText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Edited July 31, 2019 by HassoN Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 (edited) 11 minutes ago, HassoN said: --client function sendreport () local name = getPlayerName(getLocalPlayer(source)) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function sendText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Where and how do I need to fix it? addEventHandler("sendText", root, sendText) Edited July 31, 2019 by slapz0r Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 1 minute ago, slapz0r said: Where and how do I need to fix it? It says that instead of table, there's a nil value. Which line is that? Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 Just now, HassoN said: It says that instead of table, there's a nil value. Which line is that? function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) line - 2 Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 5 minutes ago, slapz0r said: Where and how do I need to fix it? addEventHandler("sendText", resourceRoot, sendText) Make sure that the function's name at the 3rd argument of addEventHandler matches the function's name above. 2 minutes ago, slapz0r said: function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) line - 2 this part of the code is fine. Try to copy the last code I sent, because I've modified it. Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 3 minutes ago, HassoN said: Make sure that the function's name at the 3rd argument of addEventHandler matches the function's name above. this part of the code is fine. Try to copy the last code I sent, because I've modified it. --client function sendreport () local name = getPlayerName(getLocalPlayer(source)) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) addEventHandler("onClientGUIClick", root, function () if ( source == buy_report ) then sendreport() showText() end end) --server local savedText = {} function savedText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", resourceRoot, sendText) it's this line - 2 line. function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) What am i doing wrong i don't understand Quote Make sure that the function's name at the 3rd argument of addEventHandler matches the function's name above. i fix it but now 639 - for i, v in ipairs(myTable) do 56 - table.insert(savedText, name) 38 minutes ago, HassoN said: --client function sendreport () local name = getPlayerName(localPlayer) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function sendText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Now I used this code and the line was added to gridlist BUT i still have this error "bad argument #1 to 'ipairs' (table expected, got nil) Line - 2 function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 I told you to copy the last version I posted. Your code doesn't match my last version. Here you go again: --client function sendreport () local name = getPlayerName(localPlayer) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function sendText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 2 minutes ago, HassoN said: I told you to copy the last version I posted. Your code doesn't match my last version. Here you go again: --client function sendreport () local name = getPlayerName(localPlayer) triggerServerEvent("sendText", resourceRoot, name) end addEvent("sendreport", true) addEventHandler("sendreport",root, sendreport) function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText",root, showText) --server local savedText = {} function sendText(name) table.insert(savedText, name) triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) Yes, I already did it, in gridlist added but error about "bad argument #1 to 'ipairs' (table expected, got nil) Line - 2 function showText (myTable) for i, v in ipairs(myTable) do guiGridListAddRow(gridSms, v) end end addEvent("showText", true) addEventHandler("showText", root, showText) Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 Where and how to announce "myTable" ?? Only in this function is it used Link to comment
HassoN Posted July 31, 2019 Share Posted July 31, 2019 5 hours ago, slapz0r said: Where and how to announce "myTable" ?? Only in this function is it used myTable represents the 1st passed argument by the trigger "showText". It is fine. The code seems fine to me so I don't know what could cause the problem. P.S: I tried the code and it worked. Link to comment
fairyoggy Posted July 31, 2019 Author Share Posted July 31, 2019 (edited) 1 hour ago, HassoN said: myTable represents the 1st passed argument by the trigger "showText". It is fine. The code seems fine to me so I don't know what could cause the problem. P.S: I tried the code and it worked. Yes it works, but with debugscript 3 getting this error. When you first add it goes well BUT when try to add second time double line is obtained. I mean, for example, for the first time added the name of the player in the grid Happened: PlayerName When is the second time trying to do the same operation it starts to duplicate. First time: PlayerNameSecond time: PlayerName PlayerName Third time: PlayerName PlayerName PlayerName PlayerName Fourth time: PlayerName PlayerName PlayerName PlayerName PlayerName PlayerName PlayerName PlayerName but I need it to save the data and another player could read them First time: PlayerNameSecond time: PlayerName PlayerNameThirt time: PlayerName PlayerName PlayerName Edited July 31, 2019 by slapz0r Link to comment
fairyoggy Posted August 1, 2019 Author Share Posted August 1, 2019 (edited) 22 hours ago, HassoN said: Use guiGridListClear This completely clears the gridlist, BUT I need each record to be saved for other users. not duplication Is it possible to make records from the grid recorded in xml file and after read from this file for other players? Edited August 1, 2019 by slapz0r Link to comment
HassoN Posted August 1, 2019 Share Posted August 1, 2019 You mean that player's name get duplicated after you trigger it more than once? Or you mean only if you do it once, then re-open the panel you get the text duplicated? If it was the 1st issue then you may check the table if it had that X variable inside then do nothing, otherwise add new line, something like: local savedText = {} function sendText(name) local duplicated = false for i, v in ipairs(savedText) do if (v == name) then duplicated = true end end if (not duplicated) then table.insert(savedText, name) end triggerClientEvent(root, "showText", root, savedText) end addEvent("sendText", true) addEventHandler("sendText", root, sendText) 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