KillerLUAGuideToLUA

From GMod Wiki

Jump to: navigation, search

Contents

KillerLUA's Guide to LUA

Introduction

Hello there, your at this page because you want to learn LUA. You want to put effort it and understand that learning a new language is not very easy. Otherwise we would have alot of LUA 'Technicians', that brings me to another discussion on my AxlGaming Heavily Modified DarkRP server. Lot's of people were complaining about the lack of 'mingy' jobs that have no real purpose. One particular person noted:

'I CAN HELP YOU ADD NEW JOBS, I'M A SPECIAL TECHNICAL LUA TECHNICIAN. JUST GIVE ME XENON SERVERS PASS DUDE'

My first reaction to this is buzz off, haven't you noticed that I've already made my own customized help menu, shipment system, theifing tools etc. People who think they have the special talent of adding a single line of pre-documented code makes me really annoyed. A un-related comment about xenon, they have one server location, many servers and often 15-20 servers per computer. They are squeezing too much into one building, thus creating lag. Xenon servers aren't the only good server company around, I'm not naming any as that could be classed as advertising. Lastly, people who charge very large amounts for simple code makes me sick. One server payed over £5 (GBP) for a few jobs, it's just a simple exploiting scam that's going around.

Say you were that person, well come along here and learn how to create your own code. Of course I'm not going to go straight into how to code your own custom gamemode, the first few scripts you make may not even happen until the next part of this guide.

Scripting/Compiling, A common mixup

A very common mixup while coding LUA scripts is what a script and what a compiled script is. LUA is a scripting based language, meaning that you don't do any compiling whatsoever. While C#, C++ or Visual Basic (just to name a few) are compiled languages. LUA however latches onto the source engine, and hooks onto the differant events, makes requests and controls the garrys mod. This created a spur of new content as you no longer had to compile a source mod DLL.

Server and the Client

The way GMod-LUA works involves absoloutely no sharing of the clients memory and the servers memory. For example, if you created a function on the client, unless you created one with the same name on the server it would spark up as an error. If the server wishes to run a clientside command it simply creates a new file and uses the

AddCSLuaFile(<filename>)
command to send it to the client. The clientside part of the code would then have to include that file.



A very important item to know about, hacks. The result of poor coding in GoFish2 means that typing buy gmod_tool -5000000 would result in 5000000$ in cash and a toolgun! You have to make sure that the end result of doing whatever you do on the actual clients game is managed by the server. For example, buying a gun in DarkRP. You click the button, the game sends a message requesting that the gun should be bought and nothing else. If you can afford it or not is not managed by the client.

Script Enforcer

Script enforcer restricts the use of clientside scripts, these can range from useful scripts to scripts that can give you an unfair edge in the game such as aimbots. If script enforcer is on, only core scripts will run (and scripts allowed by the server) and any other autorun scripts will be disabled. Some of the console commands include:

 
lua_run_cl
lua_run
lua_openscript
lua_openscript_cl
 

Special DLL's can be used to disable script enforcer however, this will thankfully get you Vac Banned for using them. My advice, if a server is VAC Protected or Script Enforcer Enabled, just don't use hacks! It's simple that the owner doesn't want them, many people may argue that it's Garrys Mod is a sandbox game. But they are wrong, Garrys Mod is no longer just a sandbox game.

Feel free to read my other tutorials here.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox