people playing: 129, servers online: 38, games played: 145,072,151 Top Player: Gentleman

  Toribash Community » Toribash » Mods » Lua scripts
Register FAQ General Rules Community
Thread Tools Display Modes
Old Jun 9, 2007   #1
Senior Member
White Belt
Join Date: Nov 2006

Toribash Lua tutorial
Okay, first of all, if you need programming basics for Lua, either learn on your own, ask me, or go to and read the tutorials. This tutorial will describe things as detailed as possible, but it won't go in detail on each function.

Okay, to start off, get 2.6.

Then, go to your scripts folder:

Here, create a text document, and rename it to [name-of-your-script].lua. If asked about the extension, hit Yes, if not, go to Folder Tools, Advanced and uncheck "Hide extension for known file-types", then rename it again.

After that, paste this code into the .lua, save it, then re-open it, and read everything. The code is commented, so you can understand easily what it's about. Before reading it, though, go to, and go to Documentation > User Manual, and read the part about syntax (variables, etc)

-- tutorialscript.lua -- A script that will be used in Jok's tutorial -- The two dashes are what signal Lua not to use this line. Called "commenting". --[[ This type of commenting stretches across multiple lines like this ]]-- --------- local function start() -- this is the main function. int main() { } in C/C++, begin in Pascal, etc. --This is what gets run as soon as the script starts helloworld() -- this is called a function call. It basically means it'll go to the other FUNCTION helloworld, then execute it end -- This ends every function and statement (if then else, for - do, while - do, etc) --------- local function helloworld() -- And this is the function that gets called. Looks almost the same as start() local a = 1337 -- giving a variable (a) a value (1337) is called assigning, -- and is done by simply writing var = value, replacing the two with their actual values local b = "Who is" -- almost the same as the first variable, this var, b, is a string. Basically a row of characters. local c = "Jok is!" -- same thing here. If you print them, to make a new line, use the \n operand, writing, for example "Jok is!\n" local d = b .. " " .. a -- This is called concatenating a string. It merges the two values, and gives out a string of the two. -- In this case "Who is 1337" echo(d) -- The echo() command writes a message to the chat area, same as if you were doing /echo in-game. centerprint("",c,"",100) -- The centerprint() command writes three lines of text, in the middle of the screen. -- the first argument ("") is the first line, second (the string c) is the middle, third is the last -- The fourth argument (100) is the time the text will be displayed on the screen end ---------- --Now for the tough bit. A hook is a 'function' that instead of having to call it when you use it, will be attached to the end of the game's default functions --For example, attaching a hook to a function, the hook being "new_game", the function will be ran at every new game, with no other necessities local function Hello() local a = get_player_info(0) -- This function will return a table of two things, name and score. These are accessed with a.score,, etc local b = get_player_info(1) -- Read the readme for the full list of commands draw_text("Welcome ".. ..". Good luck to ".. .." as well.", 0, 300) -- this function draw text (the strings) to a specific spot on the game screen -- x = 0, and y = 300. Measured in pixels end add_hook("new_game","unique_group_name",Hello) -- This is the actual hook. From now on, every new game will run the Hello() function at the start of the match -- The "unique_group_name" can be assigned to different hooks so you can remove them all at once using remove_hooks([name]) local function pain() -- this is a test function, which will print these messages on injury of either player local a = get_player_info(0) -- Read the info local b = get_player_info(1) -- For both players if a.injury > 1000 then -- This is the basic Lua IF syntax, remember it well: if [condition] then [code-to-run] {else [code-to-run-if-condition-is-false]} end Everything in-between {} is optional centerprint("Ouch","","Red is hurt.",100) -- Note that it will not reset, and messages get displayed only once else if b.injury > 100 then centerprint("Ouch,"","Blue is hurt.",100) end end end add_hook("enter_freeze","lua_group_here",pain) --This is it. Credits to hampa, for the awesome game, the devs for the continued production, and last but not least, the members of Toribash IRC for the motivation to write this. --Have fun, guys.
That's it. Comments/ideas go here.

Have fun guys.

Last edited by Jok; Sep 20, 2007 at 06:47 PM.. Reason: fixed [code] blocks
Jok is offline   Reply With Quote
Old Jun 9, 2007   #2
2nd Dan Black Belt
Join Date: Feb 2007
Posts: 422

Re: Toribash Lua tutorial
Is there an editor that you would suggest, or should we simply use Notepad?

Also, this should be stickied, in my opinion. : D Great tutorial!
[22:26] million: someday, we're gonna destroy space-time
[22:26] million: I'd like to be partly responsible
umbrafire is offline   Reply With Quote
Old Jun 9, 2007   #3
Senior Member
White Belt
Join Date: Nov 2006

Re: Toribash Lua tutorial
Thanks. And, you could use Notepad++, though I use Notepad, plain. Don't need syntax highlighting, for one.
Jok is offline   Reply With Quote
Old Jun 10, 2007   #4
Senior Member
7th Dan Black Belt
Join Date: Mar 2007
Posts: 1,046

Re: Toribash Lua tutorial
And where would i get this Beta =]?

-- Dw, all mighty Isha showed me the light
Don't change my title you asshole
Hawkinz is offline   Reply With Quote
Old Jun 10, 2007   #5
Re: Toribash Lua tutorial
Yeah, get Notepad++. Just an awesome everyday editor. Has syntax colouring for many languages and has some neat features.
don't unban, he has hard coded userid bypasses everywhere.
veb is offline   Reply With Quote
Old Mar 8, 2008   #6
Junior Member
Brown Belt
Join Date: Mar 2008
Posts: 20

What values do we actually have access to in our people?
Axoren is offline   Reply With Quote
Old Oct 24, 2008   #7
6th Dan Black Belt
Join Date: Mar 2008
Posts: 1,274

BAN VEB BAN VEB sorry about oftop hawkinz cool avatar xD
931bw is offline   Reply With Quote
Old Oct 24, 2008   #8
Black Belt
Join Date: Aug 2007
Posts: 3,203
Clan: re

FYI, you can't ban Veb, noone can, he's like... god.
Mapleleaf is offline   Reply With Quote
Old Oct 24, 2008   #9
6th Dan Black Belt
Join Date: Mar 2008
Posts: 3,794

which is why the avatar repeats so often.

awesome tutorial, I'll have to try it out sometime.
Item Forger
Stupinator is offline   Reply With Quote
Old Jan 19, 2009   #10
4th Dan Black Belt
Join Date: Jul 2008
Posts: 1,541

It only applies to pc users
FoodEater is offline   Reply With Quote

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
ragdoll fighting game physics fighting game ragdoll fighting physics funmotion joints martial arts karate pc mac free game turn based game