Lessons from Garry's Mod

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.


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2007/07/lessons-from-garrys-mod.html

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=

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/

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

iterate

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.

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

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… :slight_smile:

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

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.

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.

That mod interface reminds me so much of Expression Blend.

“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.

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

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)

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.

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

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.

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.

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.