Jump to content

Ask about tables ( { }; )


MR.GRAND

Recommended Posts

Posted

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 :$

Posted

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

 

Posted
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 ?

Posted
54 minutes ago, Tekken said:

Well I don't understand what you mean.

p_353seo4b1.png

 

 

i just have this gridlists and i want from it to be multi gridlists for all players and chats

Posted

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.

  • Like 1
Posted
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 ?

Posted

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.

Posted
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 ...

Posted
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 ]]

 

  • Like 1
Posted

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.

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...