Forum

> > CS2D > General > Lua scripting tutorial
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Lua scripting tutorial

51 replies
Page
To the start Previous 1 2 3 Next To the start

old Lua scripting tutorial

ohaz
User Off Offline

Quote
I'm currently creating a little lua scripting tutorial, you could say a crash course.
You can see the current development status here and I would be happy if you would give me suggestions (or just try to learn it with this tutorial). Like I said, it's currently under development, so I'm at the moment at if-queries and while-loops.
Have fun learning lua

old Re: Lua scripting tutorial

kikinep
User Off Offline

Quote
thx so much i be waiting for this too long thx really thx

@Edit:
heeeelp when i put this in my script:
1
2
3
4
5
6
7
----------------------
-- Join Player --
----------------------
addhook("say","adm.Join.say")
function adm.Join.say(id)
  msg("Player"..player(id,"name").."joined")
end

in the console say:
1
LUA ERROR: sys/lua/server.lua:337: attempt to index field 'Join' (a nil value)

plz help me!!!
edited 1×, last 22.06.09 07:11:50 pm

old Re: Lua scripting tutorial

horus
User Off Offline

Quote
How many projects are you running? You've got this and USCN running at the same time? xP
Still, I'm going to read some of it, since Lua hates me. No suggestions from me because I am to Lua as a child is to advanced calculus.

EDIT: Disregard that no suggestions part. How about a fully fleshed-out Lua script as an example that incorporates every part of the tutorial? [loaded with comments, naturally]

old Re: Lua scripting tutorial

KimKat
GAME BANNED Off Offline

Quote
Well pretty nice tutorial... although there is one thing missing in my honest opinion. Pictures that show result of code, and thingies.

old Re: Lua scripting tutorial

Flacko
User Off Offline

Quote
Sometimes I feel like it's very hard to teach how to program.
I liked your comparison of the boxes and variables, reminds me when I was 11 and it costed me like hell to figure out how to use them.
Goodluck with your tutorial

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
kikinep has written
1
2
3
4
5
6
7
----------------------
-- Join Player --
----------------------
addhook("say","adm.Join.say")
function adm.Join.say(id)
  msg("Player"..player(id,"name").."joined")
end

in the console say:
1
LUA ERROR: sys/lua/server.lua:337: attempt to index field 'Join' (a nil value)

First thing: Why do you use "say" in addhook if you want to message a player who's joining?
second thing: I don't really see the problem, but I think it has to do with the dots in your function name. In Lua dots mean something like "sub"-variables.
Try out the following thing:
1
2
3
4
5
6
7
----------------------
-- Join Player --
----------------------
addhook("join","adm_Join_say") --use Join here, as you want the script to be started when someone joins
function adm_Join_say(id)
  msg("Player "..player(id,"name").." joined")
end

Quote
How many projects are you running? You've got this and USCN running at the same time? xP
I'm running even more projects... there's a little bash site for the chat, and so on, and so on
Quote
How about a fully fleshed-out Lua script as an example that incorporates every part of the tutorial?
Nice idea... I'm thinking about it
Quote
Pictures that show result of code, and thingies.
You're talking about ingame pictures, or screenshots of the script?
Quote
I liked your comparison of the boxes and variables, reminds me when I was 11 and it costed me like hell to figure out how to use them.
Yes, it's my personal favourite part of the tutorial

old Re: Lua scripting tutorial

KimKat
GAME BANNED Off Offline

Quote
Your choice TheKilledDeath. You could do both, if you like. Nothing is better than a powerful and effective tutorial... and we live in the future (not to put to much work on you or anything). But I'd love some screenshots.

@horus: Stop being a wiseguy!
I ment that I wanted screenshots inside of the tutorial (like result of code and stuff), not just a plain text page.
edited 1×, last 25.06.09 08:30:06 pm

old Re: Lua scripting tutorial

horus
User Off Offline

Quote
Screenshots? Just click the link and you're there. xP
Could you find a different way to distinguish code from text? Because the bold doesn't [in my opinion] really stand out that much.

EDIT: Loving it so far! ^-^
There is, however, a little problem that many may find insignificant, but I think it's very significant indeed: the grammar. I know it isn't some essay for college, but this still annoys me a bit. There are several misuses of commas, which kind of throws me off while reading. Find an editor for it so it can be easier to read for people who can't understand something if there is a single grammar error.

EDITEDIT: Oh noes! I've found spelling errors!
They're really small ones, so I don't think anyone will notice. Anyone except me, of course.
edited 2×, last 22.06.09 10:51:14 pm

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
Yes, I'm sorry for the mistakes, I'll read through it again and hope that I'll find some of them...
Quote
if you could code the AMX way to, that would be useful.
Well... I never read any AMX code, so I don't really know how the AMX way is. But perhaps I'll add a section for it. But the primary aim of this tutorial is to show people how to script at all, not how to script in AMX way. Well, but let's see
Quote
Because the bold doesn't [in my opinion] really stand out that much.
Yes, I thought so too, but I haven't found a better idea so far... but now as I think about it... I'll do it with tables!

old Re: Lua scripting tutorial

Lee
Moderator Off Offline

Quote
Quote
Well... I never read any AMX code, so I don't really know how the AMX way is. But perhaps I'll add a section for it. But the primary aim of this tutorial is to show people how to script at all, not how to script in AMX way. Well, but let's see


I've found that my amx2d is targeted at a lost audience, therefore I've stopped support of it, there's nothing really to learn of amx2d since it's just a collection of tools to help write cs2d-lua code for begginers. I can help you write a part of the tutorial for my amx mod. Also, if you need, I can also create the webdesign for the tutorial.

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
Would be a pleasure to work together with you
About the webdesign. The tutorial is currently just a *.html file, nothing more. So the only real way to make a design is with css and frames?

old Re: Lua scripting tutorial

wups
User Off Offline

Quote
This is in the tutorial
1
2
3
4
addhook("say", "exerciseJoin") --of course the "exerciseJoin" doesn't need to have the same name at your script, the important thing is that you take the same name in the next line
function exerciseJoin(id)
   msg("Player "..player(id, "name").." joined")
end

Should it not be "join" instead of "say" in the hook?

old Re: Lua scripting tutorial

wups
User Off Offline

Quote
I like the site, but it can be better.
And the colours remind me too much of futaba. :p

You should change colour on the background of the codebox.
So its easier to look at it. Then all other looks ok.


The only thing that mess up for the eyes is this
Quote
addhook("say","tutorialsay")
text text text text text text
function tutorialsay(player, text)
text text text text text text
msg("Player "..player(player, "name").." said: "..text)
text text text text text text


Anything to work at?
Should looks better for the eye when reading
Quote
addhook("say","tutorialsay")
text text text text text text

function tutorialsay(player, text)
text text text text text text

msg("Player "..player(player, "name").." said: "..text)
text text text text text text



TDK look at this codebox method:
http://www.sendspace.com/file/glorwk
edited 2×, last 23.06.09 09:59:26 am

old Re: Lua scripting tutorial

Night Till Death
User Off Offline

Quote
TheKillerDeath cant you just make a video? i dont understand nothing! im russian for peat sake and i can only understand normal english word! plz make a video!

old Re: Lua scripting tutorial

sonnenschein
User Off Offline

Quote
NTD has written
yeah and if you can in russian plz!

maybe try to use google translator xDDD
i know its not best option, but try

BTW Nice tutorial TheKilledDeath
To the start Previous 1 2 3 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview