Forum

> > CS2D > Scripts > Table={} Menu
Forums overviewCS2D overview Scripts overviewLog in to reply

English Table={} Menu

8 replies
To the start Previous 1 Next To the start

old Table={} Menu

xSkyLordx
User Off Offline

Quote
Hello Everybody today i writed lua script again but its not working again i need table menu

E.G:
Spoiler >


Script:
1
2
3
4
5
6
7
8
9
10
11
12
13
itemnames={'Item1,','Item2,','Item3'}

addhook("serveraction","menuadd")
function menuadd(id,a)
if a==1 then
	for i = 1,#itemnames do
			menus=itemnames[i]
	menu(id,'Inventory,'..menus)
	
	
end
end
end
× itemnames[1],itemname[2]
√ Little Script Full menu

• Fail:

IMG:https://s16.postimage.org/3yoo38h39/Ads_z.png

photo upload

• Error Code:

nothing

old Re: Table={} Menu

Snurq
BANNED Off Offline

Quote
function serialize_menu(...)
     local s = ""
     for i,v in ipairs(arg) do
          s = s..v..','
     end
     return s     
end     
     
itemnames={'Item1','Item2','Item3'}

addhook("serveraction","menuadd")
function menuadd(id,a)
if a==1 then
print(unpack(itemnames))
menu(id,'Inventory,'..serialize_menu(unpack(itemnames)))
end

end

old Re: Table={} Menu

xSkyLordx
User Off Offline

Quote
Thank you its working but i dont understand what is arg ? i cant see arg={} or function unpack()

old Re: Table={} Menu

EngiN33R
Moderator Off Offline

Quote
arg is a table constructed automatically if you specify '...' as the function arguments. It's a table of all arguments provided, you don't have to declare it yourself. unpack is also a default function that makes a table into a set of variables - so, {1,2,3} becomes 3 separate variables that are 1, 2 and 3.

old Re: Table={} Menu

xSkyLordx
User Off Offline

Quote
Nicee , But i cant use when i use table[1]={} table[2]={}

how can i fix that ??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function serialize_menu(...)
     local s = ""
     for i,v in ipairs(arg) do
          s = s..v..','
     end
     return s     
end     
     
itemnames={''}
itemnames[1]={'Item2'}
itemnames[2]={'Item3'}

addhook("serveraction","menuadd")
function menuadd(id,a)
if a==1 then
for b=1,#itemnames do
print(unpack(itemnames))
menu(id,'Inventory,'..serialize_menu(unpack(itemnames[b])))
end

end

its show me itemnames[2] not 1

old Re: Table={} Menu

Happy eyes
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
itemnames={}
itemnames[1]="Sell car"
itemnames[3]="Buy exp"
itemnames[9]="Last button"

function showmenu(id)
	local m = 'Menu name here,'
	for a=1,9 do
		local w = itemnames[a]
		if w then
			m = m..w..','
		else
			m=m..","
		end
	end
	menu(id,m)
end

addhook('serveraction','serveraction')
function serveraction(id,action)
	if action == 1 then
		showmenu(id)
	end
end

Maybe not best way to do so, but atleast it works fine

old Re: Table={} Menu

xSkyLordx
User Off Offline

Quote
Thank you Happy i feel so hapy

How can i use with [id] ??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
itemnames={}
itemnames[0]=""

function showmenu(id)
     local m = 'Menu name here,'
     for a=1,9 do
          local w = itemnames[a]
          if w then
               m = m..w..','
          else
               m=m..","
          end
     end
     menu(id,m)
end

addhook('serveraction','serveraction')
function serveraction(id,action)
     if action == 2 then
          showmenu(id)
     end
end


addhook("say","amcikkoo")
function amcikkoo(id,t)
if t=="göt ekle" then
for a=0,#itemnames+1 do
itemnames[id]="göt"
end
end
end
edited 1×, last 22.08.12 11:56:05 pm

old Re: Table={} Menu

Happy eyes
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
itemnames={}
for a =1,32 do
	itemnames[a]={}
end

--itemnames[1-32][1-9]="xxx"
--itemnames[player id][button number]="xxx"

function showmenu(id)
     local m = 'Menu name here,'
     for a=1,9 do
          local w = itemnames[id][a]
          if w then
               m = m..w..','
          else
               m=m..","
          end
     end
     menu(id,m)
end

addhook('serveraction','serveraction')
function serveraction(id,action)
     if action == 1 then
          showmenu(id)
     end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview