Forum

> > CS2D > Scripts > How to create a table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to create a table

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to create a table

prow
User Off Offline

Zitieren
Here , i made a simple table to execute commands , with messages
SORRY FOR MY BAD ENGLISH :@

Here we have the table
you can edit it and add more commands


1
2
3
4
5
6
7
8
9
10
11
funcandvar = {
[1] = function(id)
	parse("speedmod "..id.." 100")
end,
[2] = function(id)
	...
end,
[3] = function(id)
	...
end,
}

here the messages for some command:

1
funcandmsg = {"speedmoded","...","..."}

you can add more.

to execute with this


1
2
funcandvar[...](id) -- execute the commands
funcandmsg[...] -- messages

you can execute this in any hook

so i made a simple hook with math.random in some function
then:

1
2
3
4
5
6
7
8
addhook("say","tableuse")
function tableuse(id,txt)
	if (txt=="table") then
		local exec=math.random(1,#funcs)
		funcs[exec](id)
		msg(funcandmsg[exec])
	end
end

so the code would remain


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
funcandvar = {
[1] = function(id)
	parse("speedmod "..id.." 100")
end,
[2] = function(id)
	...
end,
[3] = function(id)
	...
end,
}

funcandmsg = {"speedmoded","...","..."}

addhook("say","tableuse")
function tableuse(id,txt)
	if (txt=="table") then
		local exec=math.random(1,#funcs)
		funcs[exec](id)
		msg(funcandmsg[exec])
	end
end

alt Re: How to create a table

prow
User Off Offline

Zitieren
is for those who need to execute commands without making things too long, it would be for people just starting to program, to help

alt Re: How to create a table

VADemon
User Off Offline

Zitieren
You have problems with making a function inside of a table?
I would do this this way:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
text = 15
table_func = {}

function insert_tbl_func(name_of_function)
table.insert(table_func,name_of_function)
end

function big_message(text)
print(text.."@C")
end

insert_tbl_func(big_message)

table_func[1](text)
Try out the code: http://www.lua.org/cgi-bin/demo

alt Re: How to create a table

prow
User Off Offline

Zitieren
user VADemon hat geschrieben
You have problems with making a function inside of a table?
I would do this this way:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
text = 15
table_func = {}

function insert_tbl_func(name_of_function)
table.insert(table_func,name_of_function)
end

function big_message(text)
print(text.."@C")
end

insert_tbl_func(big_message)

table_func[1](text)
Try out the code: http://www.lua.org/cgi-bin/demo


post your thread
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht