From GMod Wiki
- Lua is the scripting language used in Garry's Mod. Lua is a simple and easy to learn language.
- Lua scripts can be written and changed in any text editor.
- Lua Files or Scripts require no compiling! Meaning that you will only have to write them, and Garry's Mod will read from them.
- What does Lua look like? Some examples:
This says "Hello World!" to the console.
Some basic maths:
number=1 number=number*2 //number is now 2 (1x2) number=number+5 //number is now 7 (2+5) number=number-1 //number is now 6 (7-1) number=number/3 //number is now 2 (6÷3)
This creates the function SayMyName, and uses it to send "Hey Fred!" to the console:
function sayMyName(name) //Creates the function, which has the variable "name" Msg("Hey "..name.."!\n") //This sends the message with the variable e.g. if "name" is "George", then it replaces "name" with "George" end //end of the function sayMyName("Fred")
- Lua can be used to make a large range of things in Garry's Mod such as weapons, tools and even vehicles!
- Lua files/scripts need to be added to the correct folders for them to work.
- Replace "YourGamemodeName" with the name you want for your gamemode.
- The gamemode's lua files MUST go inside a folder named "gamemode" in the folder for your gamemode, or it will not work. E.g. If I created a build gamemode named "Build", I would put all the files in this folder:\garrysmod\garrysmod\gamemodes\Build\gamemode\
- If you are running a 64 bit version of Windows, use:
Program Files (x86)
Where to go now
This page is only of basic lua information.
Before you start learning lua, is is recommended you read this page so that you have everything you need to start creating lua scripts.
If you already have a script editing program, then it is time to start reading the tutorials.