Creating & Running
![]() | This is an introduction to the lua language in general and is a recommended read if you are a beginner. |
![]() | Dim1xs |
![]() | September 28th 2023 |
Introdution
A lua file is called a script, to create and edit these scripts you need a Lua Editor such as notepad.
You can use any text editor, but to make your life easier, we recommend that you use Quick Edit.
For our first script, we're not going to do anything too complex. Just send some message into game console.
Type the following code into your chosen editor :
You're now ready to create the actual Lua script file. To find your lua folder follow the following path - it will look something like this:
Now, open the console and type the following :
SERVER side.
That also means using
CLIENT side.
Send it. If you did everything correctly up to this point you should see a message in the console :
By using
SERVER side.
So logically using
CLIENT side.
Look at the example:
You can also use 'lua/autorun/' directory, for make script run every map start.
Thank you for reading this tutorial, see ya later!
JOIN HL2GMED DISCORD SERVER!
You can use any text editor, but to make your life easier, we recommend that you use Quick Edit.
Creating the script
For our first script, we're not going to do anything too complex. Just send some message into game console.
Type the following code into your chosen editor :
print( "Hello World!")
Saving the script
You're now ready to create the actual Lua script file. To find your lua folder follow the following path - it will look something like this:
srceng/hl2/custom/hl2gmed/lua/*And you must save it with lua format (.lua)
Running the script
Running file script
To run any of your scripts you need to be playing a map.Now, open the console and type the following :
lua_dofile scriptname.luaMake sure, using
lua_dofile
command will run script from 
That also means using
lua_dofile_cl
command will run script from 
Send it. If you did everything correctly up to this point you should see a message in the console :
Hello World!The script has done exactly what you told it to.
Running script line
By using
lua_dostring
command, line from argument, will be executed from Lua 
So logically using
lua_dostring_cl
command, same will be done from 
Look at the example:
lua_dostring print("Hello World")After sending that command let's look at the output:
Hello World
Autorun
You can also use 'lua/autorun/' directory, for make script run every map start.
Autorun Structure
'lua/autorun/ - Shared
'lua/autorun/client/ - Client
'lua/autorun/server/ - Server
Thank you for reading this tutorial, see ya later!
JOIN HL2GMED DISCORD SERVER!