Lessons from Garry's Mod

July 24, 2007

Garry's Mod is a fascinating study in guerilla programming. It's an incredibly successful mod for the game Half-Life 2 that essentially converts it into a giant sandbox powered by Lua.

There are a large number of Lua scripted 3rd party modifications for Garry's mod. In a server running the Roleplay modification, you have money and tools which enable you to sell items on the map, or to interact with other players. Newer game modes have inventories and highly advanced capabilities including Item Combining and Stock Markets.

Another example is "Wood Wars", where teams make vehicles or buildings out of wood, and then attack the other team's creations with weapons made up of anything from gas canisters with thrusters on, to shells launched from makeshift cannons.

Screenshot of Garry's Mod

It has also become a tool for users to create music videos, comics and other forms of Machinima.

If Garry's Mod sounds a lot like a full-blown development environment inside a 3D world governed by physics, that's because it is. But it started out as something much simpler. In this recent interview, Garry describes the humble beginnings of his eponymous mod:

Garry Newman: [GMod] was a total experiment. I was really out of my depth in the Source engine at that point. I had no idea how anything worked, but managed to throw version one together by thinking back into Half-Life 2--to work out where I'd seen the feature before. For example, the rope gun. I didn't know how to make rope so I thought back and realized that the Barnacle's tongue was rope. So I just pretty much copied that code into a simple weapon and it worked. Well, kind of worked. This was one of the good things about GMod. I could see the right way to do stuff because a lot of the time Valve had already done it somewhere else in the code. So their code would teach me. I'm not the kind of person that can learn from books, I really need working examples.

Shack: What would you suggest to mod teams to help them avoid getting held up on the details? Start with a simple idea and build on it?

Garry Newman: I would recommend the iterative method to anyone. The main argument against this is that they don't want to release a shit version of their idea and turn everyone off. Fair enough, but it's going to be so much worse if you work your balls off on it for 2 years then release, and your idea is still rubbish. Iterating would have let you know that this idea isn't working out, so you could adjust it. In every update you're picking up more people playing your mod. You build a community.

Garry cites classic sandbox games as his inspiration, such as SimCity, The Sims, and Rollercoaster Tycoon. But I'd say the current version of GMod goes far beyond those games and delves deep into software development territory -- he's created a sandbox for creating new sandboxes.

Posted by Jeff Atwood
40 Comments

one thing I thought about Garry's mod is that it was somewhat limited in the functionality of creating complex structures, there is actually a mod for it called Wire Mod, (http://www.wiremod.com/) which introduces a lot of mathematical functions to do some crazy stuff, like there is a hologram tool which is basically a formula with multiple inputs that you use other tools to link to it. It's sort of hard for me to explain exactly what it is, so here are a few videos of a few things you can do:

timed bomb:
http://youtube.com/watch?v=ui9J1VVPWfw

hologram:
http://youtube.com/watch?v=bmO_WEIef0M

built in usable OS:
http://youtube.com/watch?v=wghkhmVLCrQmode=relatedsearch=

KC on July 25, 2007 2:04 AM

Plus, the language was a little toy language which was specifically
made just for Quake 1, so it was really quite easy to get started.
For example, my first mod swapped grenades with gibbed heads. It took
about an hour from start of download to first successful test.

QuakeC is not a little toy language, or a scripting language. It's just as powerful as C, with builtin functions and macros to make the 3D coding easy. Easy != toy language. =)

In your case, you did do a setmodel() on the new grenade entity (newmis) to the head model instead of the grenade model, in weapons.qc. =) The QuakeC builtin setmodel() can be used to set or remove the model from an entity (an object in the world), likewise you can set the bounding box, the movement type, etc., with other builtins.

IMO, the brilliance of the division between QuakeC (an interpreted language) and the engine C code is that the engine C code exposed enough power to the coder that you could write nearly any FPS you wanted. While there were third person games, they didn't work as well as FPS mods. This, I think, was why they switched to C for Quake2. And, just like you said, the additional complexity (and lack of trust for people to download and run .dlls coded by who-knows-who) kept a lot of modders working with Quake1.

Quake1 still has an active coding and playerbase. When I first started writing CustomTF in '99 or so, Team Fortress had about 45k lines of code. Now it has 100k line of code, and much of the old code has been stripped out and/or simplified. So really, it's almost an entirely different game from what ID originally released. Carmack never expected mods of that size to be written, so we actually hit the opcode limit in the QuakeC engine, requiring a new compiler to be written, along with new server code to support it. The Quake clients have been heavily modified as well, with clients like FTEQuake supporting shaders, real time lighting, bump mapping, bloom, etc. in *Quake1*. Almost all the efforts are open source, too.

All in all, I think the power of Gary's mod is that it takes the relatively complex development environment for HL2, and flattens out the learning curve.

http://www.customtf.com
http://customtf.sourceforge.net/forum/

Bill Kerney on July 25, 2007 3:00 AM

Ryan: hate is not worthwhile process, love will set you free.

maht on July 25, 2007 3:21 AM

iterate

David Ginger on July 25, 2007 5:30 AM

QuakeC is not a little toy language, or a scripting language.
It's just as powerful as C, with builtin functions and macros
to make the 3D coding easy. Easy != toy language. =)

Don't get me wrong, I have a lot of affection for QuakeC. QuakeC was where I cut my teeth as a programmer, and I absolutely loved the variety of gameplay available through Quake 1 mods. The hoverboard mod (Slide) is still the most fun I've had at a lan party.

And I do realize that QuakeC is compiled, although I thought it was compiled to a cross-platform byte-code that was then interpreted.

And perh aps calling it a 'toy' language came off more derogatory than I was hoping. 'Single-purpose' is more accurate. It does an extremely good job at what it was designed for. On the other hand, being single-purpose was the reason why many mod writers eventually outgrew it.

QuakeC lacks a few things to be as general purpose as C. First, you only have one 'struct' to work with, the Entity, IIRC. This leads to massive overloading/reuse/abuse of every member variable, because adding any new members increases the memory footprint of every single instance. Second, strings elements are not individually addressable, so string manipulation is nigh-impossible. I did write a mod that allowed users to type commands to the server console or other players consoles. It involved rebinding each key to an impulse, building strings as a linked list of entities with one string literal each, and then dumping them in order to the appropriate console when 'enter' was pressed. Not so fun.

I think the perfect solution would be a single-purpose language that doesn't have the power to damage your machine, that could make calls to a specific dll - that is, same name, same directory as the single-purpose language file. That way it'd be easy to tell if a given mod was 'dangerous' or not, it would be easy to get started, and it would still be as extensible as current systems, if a little less convenient.

Tom Finnigan on July 25, 2007 6:01 AM

And I do realize that QuakeC is compiled, although I thought it was
compiled to a cross-platform byte-code that was then interpreted.

It is. It has it's own virtual machine code, which gets compiled by qcc, and is then interpreted by the server C code. Works out nicely, since it traps runaway loops, null references, etc., like Java can do easily, but C++ can only do somewhat hackishly. The only downside is that it traps too easily on nested function calls, reporting as an infinite loop if you go over 32 recursive function calls, or so, which simply means you have to avoid recursion over long lists. With the server code available though, this constant is easily tweaked.

The fact that Carmack through together his own virtual machine, you know, just because, has always been an inspiration to me. =) It also means you have mods that can easily run cross-platform, without forcing the coder to compile to different target platforms. Since most servers run on linux, this presents issues to the .dll crowd that don't know how to make .so's.

QuakeC lacks a few things to be as general purpose as C. First, you
only have one 'struct' to work with, the Entity, IIRC. This leads to
massive overloading/reuse/abuse of every member variable, because
adding any new members increases the memory footprint of every
single instance.

Sure. By about 4k of memory footprint per member variable added, to the server (only). TF massively reused member variables, but, IMO, on today's systems with 1GB or more of memory, 4k of memory is a trivial amount to add, especially when it makes your code look better.

There have several times been proposed overhauls by people to redo all of TF in C++ (you can see them on the forums I linked to, above), but the general consensus is there's no real need for object oriented code. The existing codebase, IMO, works much better without OO than it would with.

Plus, dlls are windows-specific, so it would mean losing the ability to generate one compiled progs file and distribute it to linux, mac and windows servers, unless you wrote a C++-to-progs compiler, which seems a needless amount of effort.

Second, strings elements are not individually addressable, so string manipulation is nigh-impossible.

This was fixed back in, hmm, '98 or '99 or so. There's real string manipulation now, along with arrays, which were also missing -- but curiously not needed. 100k LOC, and I haven't found the need for one array yet; the iterators provided by the server builtin functions allows one to iterate across basically any sort of entities in the game, whether it be sorted by space, or all clients, or all things with a classname of "rocket" or whatever.

It's an interesting example of Turing completeness.

I did write a mod that allowed users to type commands to the server
console or other players consoles. It involved rebinding each key to
an impulse, building strings as a linked list of entities with one
string literal each, and then dumping them in order to the
appropriate console when 'enter' was pressed. Not so fun.

Yeah, this sort of hack isn't needed any more.

In general, I actually think the underlying architecture of Quake1/Quakeworld is pretty superior. Not only does the virtual code / interpreter breakdown have great security benefits while still exposing quite a lot of power to modders, but the network code is, IMO, superior to any other FPS ever made. I stopped playing TFC because I couldn't handle how slow and laggy TFC games were to QW. People in modern FPSs move *slow*. Mainly, because their network protocols suck, and so they disguise it by making people move slowly. It's amazing to a modern player who goes back to Quake to see how fast all the targets are moving around. If you play HL deathmatch, and then Quake1 deathmatch, you'll see what I mean. CustomTF has maintained it's popularity over the years in part due to the love people have of the speed and flexibility of movement in the game.

The only real weakness of the Quake1 architecture is that all the client side prediction is hard-wired, and so there's certain fundamental limits on what you can do, if you want to maintain compatibility with all Quakeworld clients. For example, there's only 10 or so particle effects in the game, and you can't add new ones without breaking backwards compatibility. Likewise, the prediction works great for FPS games, but reveals its weakness when you try to do Quake BattleChess, or whatever, like some mods did.

All in all, I think the story of the Quake engine is a very interesting one, and one that could use an article of it's own. While the Quake wiki page goes into a little detail on the tech behind it, it's not really very complete. The Quake family of engines, though, has grown dramatically over the years, as this image shows:
http://en.wikipedia.org/wiki/Image:Familytree11.png

Bill Kerney on July 25, 2007 8:20 AM

One thing that intrigues me about GMod is the return to an easy scripting language for further modification. Perhaps the most modded game ever was Quake 1, for a number of reasons.

It was the first game where _all_ of the game logic was separate from the low-level physics and rendering, so there was a lot of pent up demand for users to play with a fully fledged game engine - a lot of ideas people had had kicking around for a while. Mechaquake, Hoverboard quake, quake rally, pacman quake, breakout quake, side-scrolling quake, quake soccer, quake chess, headhunter quake, not to mention more popular ideas like Team Fortress, various new CTF flavors, and so on. The list is huge.

The other main reason in my mind is that the dev environment was so very easy. They gave you all of the tools needed to do dev in a single download, all the current game logic source code, and the compiler. Plus, the language was a little toy language which was specifically made just for Quake 1, so it was really quite easy to get started. For example, my first mod swapped grenades with gibbed heads. It took about an hour from start of download to first successful test.

The more serious modders complained that the toy language was very limiting, so Quake2 switched to c++ for game logic. While I'm happy that more serious modders are now able to harness the full power of c++, I think the end result is that fewer mods are being made due to the higher barrier to entry.

I bet if you look at the GMod community, there's a bunch of wacky stuff being tried for the fun of it, which makes me very happy.. :)

Tom Finnigan on July 25, 2007 9:31 AM

I love garry's mod. i like to build a cage, put hundreds of npc's in it, fire a rocket into it, and lock up my computer XD

Darren Kopp on July 25, 2007 9:32 AM

Lego on steroids, but is it a game? I'm not sure. Games has usually some goals, some conflicts and some dilemmas. Wondered where are they here.

Lior on July 25, 2007 10:06 AM

I agree, I had often argued that the game modding scene was essentially dead because it was far too difficult and time consuming to create new content in today's game engines. Garry's Mod sort of proves me wrong, because it shows that people are still content to just screw around and make a bunch of retarded wacky junk, without having to worry about compilers and normal maps and whatever.

Back in the day people would waste time making Beavis and Butthead Doom mods because it was easy enough. Nowadays it would be way too much work to try and model and animate and import Beavis and Butthead into some game, but Garry's Mod makes it easy enough to do something equally inane, like make a go-cart out of a refrigerator and run over a bunch of Alyxes posed to be having sex with each other.

Andrew on July 25, 2007 10:35 AM

That mod interface reminds me so much of Expression Blend.

Alan Le on July 25, 2007 11:09 AM

"Building (and overclocking) PCs isn't for everyone. But I hope my series illustrated that it isn't particularly difficult"

Not anymore, I remember building PCs back in the mid 90s.. now that was a task and it was even better trying to find that correct driver for Windows 98 and NT.

Things are alot easier now adays with setting up systems. Very plug and play as long as you have the correct components for the mobo chipset.

Scott on July 25, 2007 12:28 PM

I can't believe I posted a comment in the wrong blog... serves me right for reading two Codding Horror blogs at once...

Scott on July 25, 2007 12:37 PM

I have a lot of fun playing GMod, yes, but I honestly wouldn't give Garry as much credit as you do. In fact I, along with a large portion of the rest of the HL2 Mod development community, hate him. He stole code (and I'm not talking about Valve's code), he let the community do the work for him and generally earned himself a crappy reputation among other developers near him.

That said, GMod is what it is: a lot of fun. This is because of the community and the work others have put into it (wiremod is the only reason I still play it).

So basically: love Garry's Mod, hate Garry. That's my view.

(There is also some debate as to whether it's actually a mod or not. Many people, including myself, prefer to think of it as a tool, so as to not insult actual, total-conversion mods such as Dystopia)

Ryan on July 25, 2007 1:16 PM

Lior - It's not a game, it's a sandbox.

I think one of the reasons for such a success is that it makes a lot of the areas simpler (though less powerful) than the standard modding tools. This means that, for instance, while someone might be an excellent coder they can't necessarily map well. But they don't need to, because Garry's Mod gives you an easier way to "map" (again, less powerful). This makes it so much easier for one person to create a fun game.

Having said that, I program and map and no interest in making one model sniff another's butt, so have little need for Gary's Mod. Well...to be honest I'm just being snobbish.

Because of the simplicity, it's also great for prototyping. It's very easy to get the bare bones of a mod idea working, play it, see if it's any good and then refine it into a proper mod.

I don't know how much Quake3 is powered by config files, but I do know the Q3 powered Alice has huge reams of config files. Changing something is a matter of editing a value in a plaintext file and you're away.

It should also be noted that Garry's Mod didn't always have the LAU scripting.

[ICR] on July 26, 2007 3:16 AM

I was disappointed to find (from the wp link) that this mod is something you buy, over Steam.

Scott L on July 26, 2007 6:08 AM

Scott L:

To be fair, it was originally a freely available entirely independent mod that Valve snapped up and started selling only fairly recently (version 10), just like Counter-Strike. But I was also disappointed to learn that it had been commercialized.

Will on July 26, 2007 6:43 AM

It is only 10 dollars and the entertainment you get from that in the game+mod is well worth it. It's not going to break the bank people.

Scott on July 26, 2007 12:34 PM

It went commercial at the same time he got access to the actual engine code. If you wanted to buy the engine code, it would cost you a lot of money. It's a fair deal really.

[ICR] on July 26, 2007 12:42 PM

Jon,

This is Jeff's blog. He can write about whatever he wants. A lot of us find his posts immensely interesting, whether they're on .NET or not.

-Nicholas
http://www.pdsys.org/blog/

Nicholas on July 26, 2007 1:06 PM

Oh a similar vein is http://www.calamitygame.com/

It's a Flash based game with physics - it provides you the user with a sandbox. You create physics based devices and machines which then... well... just do stuff

It's not really a classic 'game', but like Garrys mod, it's fun just to mess about in!

Peter Bridger on July 27, 2007 8:24 AM

I think the issue with GMod being sold commercially is that it is claimed that he took code from others. He is now selling that code without giving recompense to the actual authors of the code.

Kai Tain on July 27, 2007 8:58 AM

Of course you could jusp play the old Version 9 for free

Miles Bacchus on September 11, 2007 9:57 AM

Of course, the fundamental difference in that is - well, fundamental. Garry's Mod (10) is a completely standalone app, while Garry's Mod 9 is a mod, piggybacking on a combination of a few Source games (you should know what they are). This means that it has no texture, model, or map dependencies - it dynamically loads everything from the internet, unless you've completely downloaded it. And, Miles Bacchus, believe me, there's a whole world of differences between a mod, and a completely standalone app.

HubmaN on September 29, 2007 11:19 AM

actually HubmaN you are required to have another source game if you want to play GMOD 10. Didn't know Garry stole other peoples code though :/, that makes me like the mod less...Wiremod is too amazing to just give up though...

Polymer on December 27, 2007 9:23 AM

Hello, being a gmod player I just wanted to clear out some stuff about garry's mod. Versions 1 to 9.0.4 can still be freely downloaded from the internet, lua is supported since about version nine. Gmod 10 costs 10$ or so and comes with free updates of the game, the lua, and some other stuff. Being the newest version, gmod 10 is supported by a community of couple dozen thousands people, while gmod 9 serves as an unsupported demo. There was a deal between Garry and Valve. Valve would give sell hismod through Steam, and he would get half of the money. Garry in turn was givenacess to source code to source engine (forever i think) to help him improve his mod in ways he couldn't without it. I personally think Garry have done what any of us could do, if we cared to and had will. Since he tracks down bugs players notice, and does what he promises, I have nothing to blame him for. Oh and excuse me for the bump.

zondartul on May 2, 2008 3:24 AM

Gmod 10, i find, is the best thing that happened to the PC. of course, it was made some time ago (before Crysis and Assasin's Creed and COD 4 came out) but I still find it a hell of a lot of fun.

Gmod 9 was alright for starters or beginners to the new Half Life Era, but after a good amount of time using a *crossbow* to make wheels and explosions, you get the urge to go online to http://steam.steampowered.com and buy garrysmod for ten dollars.

Is it worth it? Hell yes.

So stop whining about the price and get it over and done with; you will probably make ten dollars in a day's amount of work. Gmod 9 isn't worth the choppyness. Gmod 10 is.

Isak on May 8, 2008 7:51 AM

can you play gmod for free?

....dfddefe on June 8, 2008 4:00 AM

i would really like to know where to get the garrys mod 9 free version i dont wanna get it from gamespot or fileplanet

tyler on June 10, 2008 5:58 AM

i need help i feel like an idiot for asking this but how do u start gmod i cant get it to work

stupid guy on June 22, 2008 5:53 AM

i have downloaded half life 10 and 9 worked well but when i start 10 it starts normaly but no menu comes up and it closes and i get a message sayin it wont work what can i do?

fourash on July 1, 2008 11:49 AM

I'm trying to put a weapon i downloaded into the game, can u help me?

zathol on October 13, 2008 6:05 AM

GMOD is frikin beast the best game I have ever played. the first time i downloaded gmod (gmod7) i fainted from pure awsomeness. But now since this problem has been going on for a month or 2 the game isnt quite as enjoyable. None of the Npcs(with guns) can inflict damage on me is there a fix for this? If there is please ,oh my friking god ,PLEASE fix this

Concerned Citizen on December 24, 2008 10:18 AM

i would like to have garrys mod for myself beacause it's just......
well awesome

jason on January 21, 2009 1:10 AM

This is truly one of the best mods on the market. You only need to pay ten dollars once, and you have the world of Valve at your fingertips without having to pay another cent except for more Valve games to add to Gmods spawn list). The nice part is that this mod isnt limited by what the games give you. You can download free stuff for it, like tools, spawnable npcs and ragdolls, all sorts of crap! The only downside is that you can only purchase this online. If it had offline purchase available, entire stores would be swarmed!

Brian on February 2, 2009 12:08 PM

Oh, Gmod, I love it so...to speak in annoyingly dramatic terms. TBH, it's a real cool game, but, like anything that runs on Source, it lags my computer like crazy. Sadly, I can never find a GOOD server these days, one with people who play minigames every so often, one with no mingebags, one you might find in the midwest or Europe.

Maxaxle on March 29, 2009 2:10 AM

Filter the server list by names, look for Darkland's servers. They always have at least 40 people on, and usually have 50+. There is role play, my favorite, which was created from scratch. It's not DarkRP, it's their own gamemode, and you can do all kinds of stuff.

Sassilization's servers are good also, as well as JokerIce, but you have to pay a membership to get full features.

Medevilae on April 10, 2009 5:42 AM

uh.... its just awesome :D

??? on June 30, 2009 9:02 AM

It seems that when he says "I would recommend the iterative method to anyone." he is giving all programmers the best advice they could posibly be given. I have seen many projects fail simply because they were to big to work. The open-source modo "release often, release soon" is a good one to stick to, weather or not you are developing an open-source project.

Arron on February 6, 2010 10:08 PM

Jeff, when are you going to go back to blogging about .NET coding? Thats what brought me to this site, and that is what will get me to stay.

Jon on February 6, 2010 10:08 PM

The comments to this entry are closed.