Lua Beginner Guide (Part 1)
#1
Lua Beginner Tutorial:

Do you want to know how to code in Garry's mod? Are you completely new to the coding language? Then this is the place for you! 

Or maybe you could search YouTube and get someone 100 times better than me but anyway.

What do I need?
You need notepad++ or Sublime text with the Garry's mod plugin. I use Notepad++ because of personal preference but it does not matter too much.





Also ALWAYS use the Garry's mod Wiki. You can search for everything there and it is very important.



1. Basic Networking and Setup:
Garry's mod uses networking for everything even if you are in a multiplayer or single player. Every single game has a client and a server. 

Each script can be run on both the client and the server with lua_openscript (script name) for running on server and lua_openscript_cl (script name) when in the console. 

These functions find the script you have saved in the path here: C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\lua

Or where your Garry's mod in saved then click garrysmod>lua and save it there.
Different variables, functions, hooks and etc have a specific thing they can run on like the client or server. If there is a Blue circle next to it on the Garry's mod wiki then it can only be ran on the server and will have to be opened with lua_openscript (script name). If there is an orange circle then it can only be ran on the client and will have to be opened by typing lua_openscript_cl (script name) in the console. If there is a mixture than it can be used on both client and server.

There is a way of sending messages from the client to the server and the other way around but I will explain that later. 


2. Functions:
Functions are one of the most important part of Lua and I will show you some.
First of all you have to set variables, which are essentially numbers, words, tables, etc assigned to words that can change. It is hard to explain but variables are very simple and you need to understand before coming to this guide.
First off you need to set a variable to the player:
Code:
local ply = LocalPlayer()

Caps are very important here along with (), which means 'Give me an output here' used for most functions.
Now that they player is assigned to ply we can use this variable in a function like:

Code:
local ply = LocalPlayer()

local deaths = ply:Deaths()

ply:ChatPrint( deaths )

If this is ran on the client then it prints the number of deaths in chat. 
In case you don't get this then I use the first variable to get the client. 
Then I use that in a function to get the number of deaths from the player.
Last of all I printed it in the chat for only the client to see.


3. Conclusion:
This is only a very short guide for the time since I want to see how much people want to learn it and need help. It is just a test run.

If you need any help, have any concerns or want to meme on me then message me on discord, pm me on fearless or reply to this thread. Thanks! Also save your files as .lua!
[Image: KtSNMBw.jpg]


Messages In This Thread
Lua Beginner Guide (Part 1) - by DramaLlama - 09-08-2018, 01:45 PM
RE: Lua Beginner Guide (Part 1) - by King Kickass - 09-09-2018, 12:48 PM
RE: Lua Beginner Guide (Part 1) - by DramaLlama - 09-09-2018, 01:05 PM
RE: Lua Beginner Guide (Part 1) - by Greed^ - 09-09-2018, 12:55 PM
RE: Lua Beginner Guide (Part 1) - by DramaLlama - 09-09-2018, 01:04 PM
RE: Lua Beginner Guide (Part 1) - by Pollux - 09-11-2018, 11:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)