------------------------------------------------------
Now we will learn more complex things, like using cs2d commands in lua,variables, loops and Tables.
------------------------------------------------------

There are several loops in lua, some of the them are:
1
while,for
the first one we will learn to use is the while loop
this loop is very easy to use, here is an example:
1
2
3
4
5
2
3
4
5
x = 10 y = 1 while x > y do msg("Hi") end
Now we will learn to use the for loop. this one is harder to use, in cs2d we commonly use it when our hooks didn't have the id parameter.
example:
1
2
3
4
2
3
4
addhook("second","lol") funtion lol() msg2(id,"1") end
1
2
3
4
5
6
2
3
4
5
6
addhook("startround","lol") funtion lol() for i=1,32 do msg2(i,"Prepare to fight") end end
------------------------------------------------------

If u study math u must know what is a variable, a variable is just a letter or name that represents a value.
example:
1
2
3
2
3
a = 1 b = 2 a + b = 3
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
player_name = "player(i,'name')" addhook("startround","Die") function die() for i=1,32 do if player_name == "Linkin Park" then msg2(i,"hi admin") end end end
------------------------------------------------------

To use a cs2d command ( a console command) in lua u just have to write parse and ur command.
1
parse("THE COMMAND")
1
parse("mp_wpndmg ak-47 50")


edited 3×, last 08.04.11 02:58:59 am