MR.GRAND Posted December 19, 2016 Share Posted December 19, 2016 Hello all, I've window with 2 gridlists and edit box ok ? so i put all players in the first gridlist, and i want when anyone click on the player in that gridlist go to show his messages with that player, in gridlist 2 and another one when click on the first gridlist show his messages with him in gridlist 2 ( same gridlist ) i know all of that needs tables, and i tried to do it and i failed !, i hope you give me tables idea for do that and tell me an example for do it . thx all Link to comment
Tekken Posted December 19, 2016 Share Posted December 19, 2016 All you need is something like this: local table = {gridlist = {},column = {}}; table.gridlist[1] = guiCreateGridList(17, 37, 201, 252, false); table.column[1] = guiGridListAddColumn(table.gridlist[1], "Player", 0.7); for _,v in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(table.gridlist[1]); guiGridListSetItemText(table.gridlist[1], row, table.column[1], getPlayerName(v), true, false); end -- And later use something like this: local player = guiGridListGetItemText(table.gridlist[1], guiGridListGetSelectedItem(table.gridlist[1]), 1); if player and getPlayerFromName(player) then --Call the server to do whatever you want. end Link to comment
MR.GRAND Posted December 19, 2016 Author Share Posted December 19, 2016 10 minutes ago, Tekken said: All you need is something like this: local table = {gridlist = {},column = {}}; table.gridlist[1] = guiCreateGridList(17, 37, 201, 252, false); table.column[1] = guiGridListAddColumn(table.gridlist[1], "Player", 0.7); for _,v in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(table.gridlist[1]); guiGridListSetItemText(table.gridlist[1], row, table.column[1], getPlayerName(v), true, false); end -- And later use something like this: local player = guiGridListGetItemText(table.gridlist[1], guiGridListGetSelectedItem(table.gridlist[1]), 1); if player and getPlayerFromName(player) then --Call the server to do whatever you want. end This thing such which i want ? You know i have 2 gridlists only and i want gridlist number 2 to be multi gridlist in one for chatting, this example is enough for my request ? Link to comment
Tekken Posted December 19, 2016 Share Posted December 19, 2016 Well I don't understand what you mean. Link to comment
MR.GRAND Posted December 19, 2016 Author Share Posted December 19, 2016 54 minutes ago, Tekken said: Well I don't understand what you mean. i just have this gridlists and i want from it to be multi gridlists for all players and chats Link to comment
Tekken Posted December 20, 2016 Share Posted December 20, 2016 And what's the problem? You will need a database to store the player's massages and when the player clicks a player in the first gridlist you request the data from the database and display them in the second one. 1 Link to comment
MR.GRAND Posted December 20, 2016 Author Share Posted December 20, 2016 2 hours ago, Tekken said: And what's the problem? You will need a database to store the player's massages and when the player clicks a player in the first gridlist you request the data from the database and display them in the second one. I know that's easy with db, but if i want to make that with tables ? Link to comment
Tekken Posted December 20, 2016 Share Posted December 20, 2016 Well you can do it, but that's pointless 'cause the tables will erase the data in it when you restart the resource. It's pretty simple using the method I gave you. Link to comment
MR.GRAND Posted December 20, 2016 Author Share Posted December 20, 2016 16 minutes ago, Tekken said: Well you can do it, but that's pointless 'cause the tables will erase the data in it when you restart the resource. It's pretty simple using the method I gave you. i did it right now with db, and it's working successfully but when i want to use tables instead of db can you give me example for this tables because i have a trouble with get data from tables ... Link to comment
pa3ck Posted December 20, 2016 Share Posted December 20, 2016 local player = guiGridListGetItemText(table.gridlist[1], guiGridListGetSelectedItem(table.gridlist[1]), 1); if player and getPlayerFromName(player) then -- so let's say you already got the "targetPlayer" in variable "player" setElementData(player, "lastChatMessage", { getPlayerName(localPlayer), "The New Message To Send" }) end -- then... local playerMessages = {} addEventHandler ( "onClientElementDataChange", getRootElement(), function ( dataName ) if getElementType ( source ) == "player" and dataName == "lastChatMessage" and source == localPlayer then local newValue = getElementData(localPlayer, "lastChatMessage") if not newValue then return end if playerMessages[newValue[1]] then table.insert(playerMessages[newValue[1]], newValue[2]) else playerMessages[newValue[1]] = { newValue[2] } end setElementData(localPlayer, "lastChatMessage", false) end end ) --[[ so this way the table should look like this: local playerMessages = { ["playerName1"] = { "Hello", "How's things?"}, ["playerName2"] = { "Hi", "Not so bad.."} } and you can just easily loop through the table to find a specific player's message by name ]] 1 Link to comment
Dealman Posted December 20, 2016 Share Posted December 20, 2016 If you want the data to be "permanent", in other words - persist even if the resource is restarted you'll need to save it to a file. Alternatively using account data could work, but I personally would with storing it in a file. You could store them locally on every client and if an admin wants to access it you can always send it to them (client 1 -> server -> client 2). Data stored in a table would be lost when the resource is restarted. Link to comment
Tekken Posted December 22, 2016 Share Posted December 22, 2016 On 12/20/2016 at 6:54 PM, Dealman said: If you want the data to be "permanent", in other words - persist even if the resource is restarted you'll need to save it to a file. Alternatively using account data could work, but I personally would with storing it in a file. You could store them locally on every client and if an admin wants to access it you can always send it to them (client 1 -> server -> client 2). Data stored in a table would be lost when the resource is restarted. You can't store tables in account data. Link to comment
pa3ck Posted December 22, 2016 Share Posted December 22, 2016 But you can store stringified JSON if really needed. 1 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