GMod Server

Hello, I’m new to GMod coding, but I noticed that each time I edit any script I have to restart the server… not only the gamemode or the script, any solution to script faster?
I’ve been coding MTA:SA Lua for the past two years, sorry :stuck_out_tongue:

Do your development on a listening server; Things are reloaded as they are saved for the most part.
There are still cases when you’ll need to change the level or restart gmod entirely.

-EDIT- Long Post, you can read it here with some color:

Some other utilities I recommend. Add these files into a new addon, starting from this folder: addons/acecool/lua/autorun/

client/concommand_clearvgui.lua = – When you are working with VGUI it is easy to make a mistake / typo and end up with a phantom vgui window that you can’t get rid of. By adding this to your server addons, you can type clearvgui and it’ll remove all vgui panels from existence!

/util_benchmark.lua = - Useful to determine how long certain things are taking to execute.

/hook_addtemp.lua = - Useful to create a temporary hook. It manages a list and creates a maximum of 1 hook per hook-name and the helper-function that is used runs through the list executing them when the hook is called. Useful if you want to create something on screen for x seconds, or debug something for x seconds, etc…

Examples for hook_addtemp.lua ( to create helper functions to use ):

/client/draw_this.lua = - Simple helper function for hook_addtemp that adds a function to be called from HUDPaint
/client/render_this.lua = - Simple helper function for hook_addtemp that adds a function to be called from PostDrawTranslucentRenderables

Don’t do your dev-work on a listen-server ( server created within gmod client ) because client and server code will both run on the client and it’ll give you odd results because server vars can overwrite client and vice-versa. So unless it is coded very specifically, doing dev-work on a listen server can be a waste of time.

I’d recommend a local SRCDS because it will act essentially exactly like it would when it is uploaded to a server. It is FAST developing on a local server. If your client crashes ( which can happen if you call certain commands on the client, or have a memory leak ) you’ll be able to find the issue more quickly because of the reduced start-up time PLUS the fact that your client crashed which limits the crash to client/shared code instead of ALL code. Vice versa, if the server crashes it helps isolate the issue to one realm…

If you’re not already running a local dev server, here is everything you need to get started:

If you want to set up FastDL:

If you want an automated resource loader script that automatically resource.AddSingleFile’s things for you and resource.AddWorkshop’s things for you too:

I just updated the resource script to load GMA files from the main addons/ folder.

Now, for the auto-refresh. You’re running windows, so autorefresh should be enabled. If not, just double-check the variable: ( -enableluarefresh in launch options MAY OR MAY NOT WORK. -disableluarefresh is how to turn it off, so it may even be on by default )

The way it works is when you save a file, it should work. If you are using SUBLIME TEXT EDITOR try toggling your atomic saving feature. What it does is it saves the file somewhere else, then replaces the real file. It is supposed to prevent file corruption, but it will cause the issue of auto-refresh NOT working.

I’d recommend Notepad++ plus a few upgrades such as the GModLua lexer / syntax highlighting addon along with the updates. I’ll provide links below to a lot of helpful things.

Next, if the autorefresh still doesn’t work, or if you’re on Linux, then you may need to create a command to do it for you. If you’re creating your own game-mode, I’d recommend writing or using an auto-loader ( links below to mine, base developer game-mode which has my autoloader, check the automatic file loading system link in the acecooldev_base link at the bottom )…

If you don’t want to use an autoloader, and you’re running linux or auto-refresh isn’t working, you can make it work by creating a console command to do it for you. Simply wrap your includes / AddCSLuaFiles up in a function. Call the function at the bottom of the loader file, and then add a console command which calls that function. Mine is loadgm if you end up using my dev-base.

I’d also recommend moving ALL include/AddCSLuaFile calls to your shared.lua file inside gamemodes/<gm_name>/gamemode/ because then it makes it easier to wrap the includes up into a console command / function. Here is an example of how to set up your game-mode to have 1 file do all includes / AddCSLuaFile calls and work properly - blank gamemode called gm_name:

Hopefully these tutorials and information helps. As always, to view the Lua from any of my tutorials to enable copy/pasting ( HTML doesn’t copy/paste well in terms of HTML / CSS Highlighted Lua ), remove .html from the url.

Hey, welcome to FacePunch.
I have written over 400 tutorials and completed “systems” in Lua for Garry’s Mod. I tutor and answer questions for free; feel free to add me on Steam if you need some guidance. This forum is for devs that need help working on things. Here are some resources to help you get started:

Generalized Lua Help ( Links to Wikis, Answers the question of “Where do I post a simple question or DarkRP Specific question”, links to other resources compiled by forum members )

Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades

Acecool Dev Base Skeletonized Base Game-Mode ( Never worry about Include or AddCSLuaFile ever again; comes with New Hooks, Console Commands, Meta-Table Objects, Helper Functions, Extended Functionality, and more! )

Oh my god, i can’t believe that i thought he writes this every time, he just paste it :v

Actually, I did write that post above except for the 3 links at the bottom. I’m using BBCodeXtra for Firefox which lets me setup bbcode so I can select text and apply [lua] tags around it, or from clipboard, TAB, quote, video, etc…

I copied that post to a “tutorial” file because it was long and informative…


You could make a single player game and code in there, lua files refresh 90% of the time.