1
Tbl = {"ex","x"}
Is it shared to everyone? Because I'm making an inventory system made from tables. Thank you.
Scripts
Is tables shared?
Is tables shared?
1

Tbl = {"ex","x"}
Starkkz: No, Must be in a game. Example like when I add something on the table and I can access the table by pressing f2, but How do you do it for only me to see the added item to the table? inv = {} -- Create the master table
addhook("join","createinv")
function createinv(id)
	inv[id] = {"ex","x"} -- Create the inventory table that's exclusive to player 'id'
end
addhook("serveraction","displayinv")
function displayinv(id,a)
	if a == 1 then
		menu(id,"Inventory,"..inv[id][1]..","..inv[id][2]) -- Show the player their inventory
	end
end
addhook("leave","destroyinv")
function destroyinv(id)
	inv[id] = nil -- Destroy a player's inventory when they leave the server
end
addhook("attack","additemtest")
function additemtest(id)
	table.insert(inv[id],"item") -- Inserts an item into a player's inventory every time they attack
end
function init_array(length,mode)
	local array={}
	for i=1,length do
		array[i]=mode end
	return array
end
myowntable=init_array(32,"")
myowntable[1]="Testing"
Dovahkin: The players don't literally own the array/table itself. It kind of just can be manipulated on the server-side however the clients connected to the server allows that manipulation to happen sort of say. A typical example for this is let's say a experience bar, the clients XP will be sent to the server-side Lua script hooks which will handle the experience seperately for each player. That's the best way I could describe it.
EngiN33R: It'd be user-friendly to also add a check for if table exists or not and if tables doesn't exist the Lua function will create new table or if table exists it will simply tell it exists.tbl={}
function c_table(t,c)
	if type(t)=="table" then
		print(string.format("%s exists.",t))
	else
		print(string.format("%s doesn't exist.",t))
		if type(c)=="number" and c==1 then
			local t={};return t
		else
			print(string.format("Wrong parameter value %q. Try %q instead.",c,1))
		end
	end
end
--[[ This creates new table based on checked table if checked table doesn't exist. ]]--
tbl2=c_table(tbl2,1) -- Create table if table doesn't exist.
--[[ This checks if table exists. ]]--
c_table(tbl) -- Check if table exists.
KimKat: Thank you for helping. But how do you make a shop on that table. Seems a little bit complicated at newbie's
shop=c_table(shop,1) -- Checks if table exists already and if it don't. It creates table with name shop.
print(shop) -- The table named shop is now usable.
tbl={} -- Otherwise use this to create a table, whatever is preferred. There's many ways to accomplish things.
shop[1]="Value" -- Storing strings.
shop[2]=1234 -- Storing integers (signed or unsigned).
shop[3]=1 -- Storing objects (such as images).
shop[4]=tbl -- Storing tables within specific table indexes.
-- Learn Lua by watching some tutorials and you will comprehend it.
EngiN33R: How do you make the inserted item function like a button just like in a menu with buttons in it. Because the inserted items goes every button numbers from 1-9 and I can't make all If button == 1
EngiN33R: a little help? or @
KimKat: one more favor. Please and Thank you
pocinventory = {}
function table.createNested(s)
	local tbl = {}
	for k = 1, s do
		tbl[k] = {}
	end
	return tbl
end
pocinventory.shop_items = {
	[1] = "Item 1",
	[2] = "Item 2",
}
pocinventory.inventory = table.createNested(32)
addhook("leave","pocinventory.leave")
function pocinventory.leave(id)
	for k in pairs(pocinventory.inventory[id]) do pocinventory.inventory[id][k]=nil end -- Clear inventory
end
addhook("serveraction","pocinventory.serveraction")
function pocinventory.serveraction(id, a)
	if (a == 1) then -- Open shop (F2)
		menu(id, "Shop,"..table.concat(pocinventory.shop_items,",")) -- Display shop items in a menu (the first 9)
	end
	if (a == 2) then -- Open inventory (F3)
		menu(id, "Inventory,"..table.concat(pocinventory.inventory[id],",")) -- Display inventory in a menu (the first 9)
	end
end
addhook("menu", "pocinventory.menu")
function pocinventory.menu(id, menu, button)
	if (menu == "Shop") then
		if (pocinventory.shop_items[button]) then -- Just in case
			table.insert(pocinventory.inventory[id],pocinventory.shop_items[button]) -- Add item to inventory
	end
end
1
