Forum

> > CS2D > Scripts > lua scripts in cs2d (some questions)
Forums overviewCS2D overview Scripts overviewLog in to reply

English lua scripts in cs2d (some questions)

18 replies
To the start Previous 1 Next To the start

old lua scripts in cs2d (some questions)

NinjaEx
User Off Offline

Quote
Hello guys!!
I know very little about lua scripts in cs2d .
Just explain these things...
/////
if sample==nil then sample={} end
sample.classes={}
/////
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i]=0
     end
     return array
end

////////

addhook([[serveraction]],[[sa]])
function sa(id,a)
if a == 1 then
menu(id,[[Vote,Vote Mute,Vote Kill,Vote Kick,Vote Ban]])
end
end


PS: It is not one script

old Re: lua scripts in cs2d (some questions)

J4x
User Off Offline

Quote
I can explain u this
1
2
3
4
5
6
addhook([[serveraction]],[[sa]])
function sa(id,a)
if a == 1 then
menu(id,[[Vote,Vote Mute,Vote Kill,Vote Kick,Vote Ban]])
end
end

1. this part is called hook
1
addhook([[serveraction]],[[sa]])
the hook has to parts the hook and the name
the hook in this case is serveraction and the name is sa.the name (sa) can be replaced whit any other name
example:
1
addhook([[serveraction]],[[lol]])
.
the [[]] can be replaced with ". example:
1
addhook("serveraction","lol")

2. this is the fucntion
1
function lol(id,a)
the funtion is simple just add the word fucntion,the name that u put to the hook and the parameters thta in this case are (id,a). example:
1
function lol(id,a)
.

3.this one says to the script what to do
1
2
if a == 1 then
menu(id,[[Vote,Vote Mute,Vote Kill,Vote Kick,Vote Ban]])
.So only if u press the serveraction 1 a menu will be opened.

4. this part is the end of file also called <eof>
1
end end
. u have to add the necessary number of ends.
why? because if u dont add the necessary ends then the console will end u this error eod expected near(function) near <eof>.

old Re: lua scripts in cs2d (some questions)

NinjaEx
User Off Offline

Quote
thanks!
But in classmenu script i see that
1
2
3
4
5
6
7
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
What is about for i = 1, m do?

old Re: lua scripts in cs2d (some questions)

oxytamine
User Off Offline

Quote
GreY23 has written
thanks!
But in classmenu script i see that
1
2
3
4
5
6
7
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
What is about for i = 1, m do?

It's all about Turbo Pascal cycles. Have you heard about it? I thought pupils have Turbo Pascal on IT lessons in school.

old Re: lua scripts in cs2d (some questions)

oxytamine
User Off Offline

Quote
GreY23 has written
thanks!
But in classmenu script i see that
1
2
3
4
5
6
7
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
What is about for i = 1, m do?

Let's take a look at it. Here, 'i' - temporary variable.
1
for i:=1 to m do *something here*
That's what would be in Turbo Pascal. Oh... How to explain. Really, I dunno how to explain this to you.

old Re: lua scripts in cs2d (some questions)

Banaan
User Off Offline

Quote
i is a variable, which will be incremented with 1 until it reaches m (which is a number variable)

For each value of i that comes by, so for each i between 1 and m, it will execute the code after the do.

So:
for i = 1 until m, it sets the i'th value of the array (oh wait that's a table in lua) 'array' to 0, creating a table which contains m times 0.

old Re: lua scripts in cs2d (some questions)

Phenixtri
User Off Offline

Quote
this is why i still say lua is a mind fuck for the inexperienced coders like me @_@ I still don't get any of this & the fact that im a visual learner dosent help at all @_@

old Re: lua scripts in cs2d (some questions)

EngiN33R
Moderator Off Offline

Quote
Let me at least try to get this straight.

1
for i = 1, m do

In this case, i is a variable that contains all the numbers from 1 till m. E.g., if m==9, then i will be from 1 till 9, meaning i==1,2,3,4,5,6,7,8,9 AT THE SAME TIME.

The initArray(m) function is used for creating a table that contains m 'cells' (variables) with 0 value.

old Re: lua scripts in cs2d (some questions)

NinjaEx
User Off Offline

Quote
hhhmmm... I go to download books about pascal.
After learning pascal i will learn lua .
Anyway It will benefit me


Edit: Cool. I just have read this http://www.cs2d.com/tut/tkdlua/luatut.html
Anyway Thx Guys!:)


pls help me.
Why it not work?
1
2
3
4
5
6
addhook("say","sayh")
function sayh(text)
if (text=="!hello")then
msg2("hello!!")
    end
end
edited 2×, last 10.01.11 04:39:21 pm

old Re: lua scripts in cs2d (some questions)

Banaan
User Off Offline

Quote
the say hook passes two arguments to the function hooked to it: first the player ID, then text. Because your function only takes one parameter, only the first argument, being the player ID, is passed to your function. You are therefore checking if the player ID equals "!hello", which or course isn't true.

A correct script would be:
1
2
3
4
5
6
addhook("say","sayfunc")
function sayfunc(id,text)
	if (text=="!hello") then
		msg2("hello!!")
	end
end

old Re: lua scripts in cs2d (some questions)

EngiN33R
Moderator Off Offline

Quote
I'm sorry Banaan, but your script has a small error riiight there.
1
2
3
4
5
6
addhook("say","sayfunc")
function sayfunc(id,text)
     if (text=="!hello") then
          msg2(id,"hello!!")
     end
end

old Re: lua scripts in cs2d (some questions)

RAVENOUS
BANNED Off Offline

Quote
GreY23 has written
Thx. Hmmm... If write id on
1
msg2(id"Hello!!")
Then the player who wrote"!hello" can see the Message "Hello" from Server?


Only the player should be able to see it. When id is remaining his ID.

old CAR SCRIPTER

albachersont
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("say","cars") -we put a name optional 
function cars(id,txt) -same name ...        
	if(txt=="!car") then - va trebui pus un nume care se va accesa de la chat in cs 2d
freeimage(id) -accessing an image 
 parse("equip "..id.." "..45) -set of features 
parse("setmaxhealth "..id.." "..250)
parse("setarmor "..id.." "..200)
id1=image("gfx/car/tank.bmp",1,1,200+id) -Image Settings 
imagescale(id1,1,1) -options,settings images  
imageblend(id1,0)                               imagealpha(id1,1.0)
if (player(id,"team") == 2) then 
 imagecolor(id1,255,255,255) 
                
          elseif (player(id,"team") == 1) then 
               imagecolor(id1,255,255,255) 
          end 
	end
end
this is a prototipe...but still has to go.....I tried
edited 1×, last 02.07.11 07:50:01 pm

old Re: lua scripts in cs2d (some questions)

vilimonas
User Off Offline

Quote
hi can anyone help me i need a script and i want a rp script but i need in a line only one copy if more i make wrong×and only like samples those lua and plss when i download from here or anywhere it always bes in folder and and and

old Re: lua scripts in cs2d (some questions)

Banaan
User Off Offline

Quote
EngiN33R has written
I'm sorry Banaan, but your script has a small error riiight there.
1
2
3
4
5
6
addhook("say","sayfunc")
function sayfunc(id,text)
     if (text=="!hello") then
          msg2(id,"hello!!")
     end
end


Oops yeah you're right sorry :S
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview