A tutorial on how to have custom entities such as weapons show up in hammer.

At the end of this tutorial you will know how to implement custom entities into your maps and the basics of making your own FGD.

What to Do If You Run into Issues

If you run into a problem the fastest way is to ask a question on the Steam Source SDK Forums, Reddit, or the Source Engine Discord. But do be sure to search first, often someone else has already had the same problem and solved it!

You can email me directly but I respond the fastest to posts on the Source SDK forums since Steam puts the alert in my face.

Video Version of This Tutorial

Don’t feel like reading or need a visual aid? Check out the video!

Things You Will Need to Download

Garry’s Mod

Notepad++, Visual Studio Code, or any other editor for working with text files that is NOT notepad or Word

Find the Classname of the Entity

In order to spawn the entity you need to know it’s classname, the easiest way to do this is to extract the contents of the workshop file and find the entities main file/folder as that will be the classname for it.

Go to the workshop and subscribe to the weapon/entity you want to implmenet into your map, for me I am going to use this Silenced Ak47 and TTT Famas Navigate to your GarrysMod install directory in steamapps/common Open the bin directory in a new window, you can do this by right cicking on it and choosing “Open in a new window” Keep the bin directory open in the other window and in the original window navigate to garrysmod/addons Find your addon adding in .gma and drag it on top of gmad.exe and it will begin to unpack it into your addons directory Explore the newely unpack addon for the entities lua file, this will be the classname for the entity.

For the Silenced AK47 this was in \addons\silenced_ak47_1857391969\lua\weapons and was called weapon_triage_ak47_s.lua

For the TTT Famas this was in \addons\ttt_famas_337050692\gamemodes\terrortown\entities\weapons and was called weapon_ttt_famas.lua

NOTE: The location can vary depending on what gamemode and how the creator implmented it. Gamemode specific entities tend to be inside of the gamemodes folder.

Placing the Entity in Hammer

Start Garry’s Mod’s hammer inside the bin folder. In your map create a point entity Select the entity and open the entities properties window (alt+enter) Select the class name in the drop down list and write in your new entities name that you found in the previous section without the lua extension . E.g. weapon_triage_ak47_s and weapon_ttt_famas Press Apply, you will now see that you have the “Obsolete” icon. This is normal. Compile the map but do not run the map from hammer. Sometimes when launching through hammer addons don’t get mounted before the map actually loads in causing custom entities to not work. Run Garry’s Mod from Steam and load the map. You should now see your weapon sitting on the ground.

NOTE: If it doesn’t spawn in check the console for an error message related to trying to create an unkown entity

NOTE: Some entities it appears are imposible to use through this method. As an example most NPC’s will not work because they are not truly new entities they are a base npc such as a rebel or combine that has it’s model switched out, so they still have the same classname. If you are working with Nextbots this shouldn’t be an issue however.

Creating a Custom FGD

Manually typing in the classname every time is time consuming and if you have a typo then it will not work. So let’s create our own FGD so that Hammer knows what the entities are.

Before we begin you should understand what an FGD actually is. The simple explanation is that an FGD is like an English to Spanish translation book. It tells Hammer what it should look like in the edtior along with what keyvalues, inputs/outputs, and flags it has that are user friendly while also having what the Source Engine is expecting once it is compiled. Keep in mind that an FGD DOES NOT create entities, just because you define something in it does not make it real the code must also exist.

Let’s begin creating our own FGD.

Navigate to the to Garry’s Mod’s bin folder, you will see it already has several FGD files in it Right click inside the folder and choose New -> Text Document and name it MyFGD.fgd Open your newly created file in whatever text editor you prefer, I’m using Visual Studio Code I’m going to create an entity for the Silenced AK47, my code will look like this

@PointClass base(Weapon) studio("models/weapons/w_triage_ak47_s.mdl") = weapon_triage_ak47_s : "Silenced AK47" []

Let me explain what each part of this is now but if you want a more in depth explanation read the FGD documentation:

@PointClass : This is the class type of the entity, things like weapons, logic entities, etc are all Point Entities. If we were making a custom brush entity it would have the class of SolidClass

base(weapon) : This is the base entity definition, rather then rewrite every single time we can pull from a parent that has the basic setup we need

Here is what the definition for weapon looks like from the halflife2.fgd

@BaseClass color(0 0 200) base(Targetname, Angles, GMODSandbox) sphere(fademindist) sphere(fademaxdist) = Weapon [ spawnflags(Flags) = [ 1 : "Start constrained" : 0 2 : "Deny player pickup (reserve for NPC)" : 0 4 : "Not puntable by Gravity Gun" : 0 ] output OnPlayerUse(void) : "Fires when the player +uses this weapon" output OnPlayerPickup(void) : "Fires when the player picks up this weapon" output OnNPCPickup(void) : "Fires when an NPC picks up this weapon" output OnCacheInteraction(void) : "Fires when the player 'proves' they've found this weapon. Fires on: Player Touch, +USE pickup, Physcannon pickup, Physcannon punt." fademindist(float) : "Start Fade Dist/Pixels" : -1 : "Distance at which the prop starts to fade (<0 = use fademaxdist). If 'Screen Space Fade' is selected, this represents the number of pixels wide covered by the prop when it starts to fade." fademaxdist(float) : "End Fade Dist/Pixels" : 0 : "Maximum distance at which the prop is visible (0 = don't fade out). If 'Screen Space Fade' is selected, this represents the *minimum* number of pixels wide covered by the prop when it fades." fadescale(float) : "Fade Scale" : 1 : "If you specify a fade in the worldspawn, or if the engine is running under dx7, then the engine will forcibly fade out props even if fademindist/fademaxdist isn't specified." + " This scale factor gives you some control over the fade. Using 0 here turns off the forcible fades." + ]

Again, just beceause it is in the FGD does not mean it is going to work. However because we know the Silent AK47 is using the proper base weapon script it is highly likely these will all work.

studio("models/weapons/w_triage_ak47_s.mdl") : This tells hammer what model to use for dispalying in the editor window. If you want an icon you can use iconsprite

weapon_triage_ak47_s : This is the entities classname

: "Silenced AK47" : This is the help text that get’s displayed if you press the help button in Hammer

[] : Additional entity properties would go between these square brackets but because this is a basic weapon we don’t need any

Now then save the FGD and open Hammer.

Click Tools -> Options...

Click Add and select your new FGD

You can now place your entities in Hammer!

If you are wanting to make game logic entities and need a refrence check out TTT’s official FGD file

Remember when you upload your map to the workshop that you add the weapons/entities workshop pages as requirements, do not pack other peoples work into yours without permission!!!

If you have feedback feel free to shoot me an email and if you want to buy me a coffee on Ko-fi it would be really appreciated!