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: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/autorefresh_not_working_and_why_not_to_use_listen_server_for_dev_work.lua.html

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

client/concommand_clearvgui.lua = https://dl.dropboxusercontent.com/u/26074909/tutoring/_utilities/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 = https://bitbucket.org/Acecool/acecooldev_base/raw/master/gamemode/shared/core/util_benchmark.lua?at=master - Useful to determine how long certain things are taking to execute.

/hook_addtemp.lua = https://bitbucket.org/Acecool/acecooldev_base/raw/master/gamemode/shared/core/hook_addtemp.lua?at=master - 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 = https://bitbucket.org/Acecool/acecooldev_base/raw/master/gamemode/client/core/draw_this.lua?at=master - Simple helper function for hook_addtemp that adds a function to be called from HUDPaint
/client/render_this.lua =https://bitbucket.org/Acecool/acecooldev_base/raw/master/gamemode/client/core/render_this.lua?at=master - 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: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

If you want to set up FastDL: https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/fastdl_setup_instructions.lua.html

If you want an automated resource loader script that automatically resource.AddSingleFile’s things for you and resource.AddWorkshop’s things for you too: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_recursive_resource_loader/sv_add_gamemode_resources.lua.html

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: https://dl.dropboxusercontent.com/u/26074909/tutoring/includes/gm_name.rar

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 )
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_general_lua_learning.lua.html

Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_useful_programs_and_notepadpp_upgrades.lua.html

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! )
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_acecooldev_base_gamemode_info.lua.html

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…

Or…

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