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]
#2
I respect you for trying to encourage new people to the language but Lua is a pretty deceptive language in terms of the learning gaps within it.

It's a language where you can learn the basics in a matter of 10 youtube videos which can let you do cool stuff in Gmod like making an entity then giving it properties like when you run over it your health turns to zero. Stuff like that. Unfortunately basic shit like that is NOT enough if you wana do something like become a contributor. There might be loads of youtube videos and small handy guides but there's nothing that can replace the official Lua book https://www.lua.org/pil/

Believe me i know i was made contributor with, yup you're right the experience of 10 youtube vids in coding that let me get past the small tests Avgar gave me. I wanted to become a contrib cause i wanted to help the server at the time. I had NO interest in coding. Once i saw what the job really wanted out of me i realized i was shit out of my league and up and left in a matter of like 3 months, because i was clearly not helping the server and i was just wasting everyone's time.
Now in college in a profession complacently different to codding and enjoy it.

Tl:dl Don't learn the language if you've no other coding experience and only want to do it because you're interested in becoming contributor and have no interest in doing anything to do with coding in the future or you might make an ass out of yourself. If you want to take the plunge to Lua then go all out in learning it. Might as well after all.
[Image: 10WI43J.gif?1]
The following 1 user Likes King Kickass's post:
  • DramaLlama
#3
Isnt LUA pretty useless outside of game modding?
The following 2 users Like Greed^'s post:
  • DramaLlama, Idea
#4
(09-09-2018, 12:55 PM)Greed^ Wrote: Isnt LUA pretty useless outside of game modding?

Yeah. I prefer GML as it is pretty simple but useful.
[Image: KtSNMBw.jpg]
#5
(09-09-2018, 12:48 PM)King Kickass Wrote: I respect you for trying to encourage new people to the language but Lua is a pretty deceptive language in terms of the learning gaps within it.

It's a language where you can learn the basics in a matter of 10 youtube videos which can let you do cool stuff in Gmod like making an entity then giving it properties like when you run over it your health turns to zero. Stuff like that. Unfortunately basic shit like that is NOT enough if you wana do something like become a contributor. There might be loads of youtube videos and small handy guides but there's nothing that can replace the official Lua book https://www.lua.org/pil/

Believe me i know i was made contributor with, yup you're right the experience of 10 youtube vids in coding that let me get past the small tests Avgar gave me. I wanted to become a contrib cause i wanted to help the server at the time. I had NO interest in coding. Once i saw what the job really wanted out of me i realized i was shit out of my league and up and left in a matter of like 3 months, because i was clearly not helping the server and i was just wasting everyone's time.
Now in college in a profession complacently different to codding and enjoy it.

Tl:dl Don't learn the language if you've no other coding experience and only want to do it because you're interested in becoming contributor and have no interest in doing anything to do with coding in the future or you might make an ass out of yourself. If you want to take the plunge to Lua  then go all out in learning it. Might as well after all.

You are right. I have an inherent interest in coding and Lua was not my first language. I learned Lua as I wanted to be part of a bigger coding project and for making mods.
[Image: KtSNMBw.jpg]
#6
(09-09-2018, 12:55 PM)Greed^ Wrote: Isnt LUA pretty useless outside of game modding?

It's quite similar to other high-level languages. For example, I was able to learn glua in a few days due to it being quite similar to Python (which I use a lot at school). It's a good language to start with as it's easy and you can make some cool stuff.
Pollux
Fearless Management
bork
__________________________________________________________________
The following 1 user Likes Pollux's post:
  • max.


Forum Jump:


Users browsing this thread: 1 Guest(s)