Garry's Mod

Garry's Mod

335 ratings
SWEP Construction Kit user guide
By Clavus
The SWEP Construction Kit is a Garry's Mod developer utility to create weapon designs without having to find completely new weapon models. The tool allows you to position models, sprites and other scripted visuals on both the viewmodel and the worldmodel of a SWEP. Additionally, you can finetune ironsights. Integrating designs in you SWEP code is quite simple as long as you know your way around GMod Lua.
3
   
Award
Favorite
Favorited
Unfavorite
Introduction to the SCK
Let's get this straight first: the SWEP Construction Kit (SCK) is a developer utility for experienced scripters. If you want to use your SCK designs on your own weapons, you are REQUIRED to know how to script weapons in Garry's Mod. There is no scripting knowledge needed to use the tool itself, but then it'd be nothing more than a weapon dress-up game for you :P

Now that is out of the way, let's get to it. First grab the SCK from the Garry's Mod workshop:

http://sp.zhabite.com/sharedfiles/filedetails/?id=109724869
What is the SCK exactly? It's a tool that allows you to decorate your weapons with all sorts of models, sprites and scripted visuals by parenting these to your weapon viewmodel or worldmodel.

Here are some examples:



These were all made by combining models and sprites with an existing weapon model, without having to use an external modelling program.


Creating a design
In this section I'll cover the basic steps of making a weapon design with the SCK. I won't be able to cover all features, so feel free to experiment and check out what buttons do what. Let's get started.



The SCK tool can be found in the spawn menu, under Weapons -> Other.



Open the menu by right clicking. The Tool tab allows you to save / load designs. The animation buttons are mainly useful for third person (press Toggle thirdperson at the top if you want to check it out).

Go to the Weapon tab. Here you'll define the viewmodel and worldmodel that you'll be building your design on. You can change the hold type (which affects your world animations, look in third person) and toggle some other parameters.

I won't cover the Ironsights tab, it's pretty straightforward.

For this tutorial we're going to use the grenade model as base.



There is an inbuild model browser you can use. Alternatively, you can copy the model path straight into the text field. HL2 / CSS viewmodels and worldmodels can be found in the models/weapons/ directory.

Be sure to also change the world model to reflect the viewmodel you're using.



For this tutorial I'm replacing the grenade in this viewmodel. I do this by scaling down the ValveBiped.Grenade_body bone all the way. Different viewmodels have different bones. It's often a matter of trial and error to find the right ones.

Now we move to the juicy bit. Adding our own models! Go to the View Models tab. In the right picture you can see I created a Model element and parented this to the ValveBiped.Grenade_body bone. If you can't see your element at first, make sure it's parented to the right bone.



A small reminder: you can use the spawn menu to copy the model paths and paste these in the model fields of the SCK. Downside is that you'll have to close the SCK menu first, open the spawn menu, copy the model path, and re-open the SCK menu, then paste it in.



To spice things up I'm adding various elements. Sprites are always oriented towards the camera, and can be used to add effects like glows (most sprites can be found in the aptly named 'sprites' directory). Note that I don't parent the sprite to a bone, but to the 'cactus' Model element I made earlier. This way if I move the cactus, the sprite moves with it. This has another added benefit when we construct the worldmodel design.

In the right picture I added another model parented to the cactus. I also added a quad (the red square with debug text). A quad allows you to easily add scripted visuals, like for example, an ammo counter. To do this, override the SWEP.VElements["<quad name>"].draw_func and SWEP.WElements["<quad name>"].draw_func variables with a custom draw function in your weapon script. Like this:



Here it'll draw an ammo counter on the quad element with the name "myquad".



To finish our design, we need to convert the viewmodel design we made to the worldmodel. Go to the World Models tab. Using the "Import Viewmodels" button you can easily copy over all the elements you made for the viewmodel. Their positions will be all messed up, because the positioning just doesn't translate 1:1 (viewmodels have different sets of bones), so you'll have to fix that manually. Also notice how the elements that were parented to the cactus element stayed in place, making our life a bit easier.

Here the SCK has another neat feature: you can create additional elements for the worldmodel and parent these to different bones on the ragdoll. For example, you can add a fuel reservoir on the back of the player for a flamethrower SWEP. The possibilities are endless.

Adding a SCK design to your SWEP
Now we get to the scripting. It's not that hard. First you merge the SCK's SWEP base code with your own weapon script. You can copy the SWEP base code to your clipboard in the Tool menu, or you can grab it from GitHub here:

https://github.com/Clavus/SWEP_Construction_Kit/blob/master/lua/weapons/swep_construction_kit/base_code.lua

Now that your SWEP is ready to use SCK designs, just copy over the configurations from the different tabs to your script. It'll look something like this:



Tip: another great thing to do is adding animation. You can change to values of the elements in the self.VElements and self.WElements tables on the fly. For example, by simply translating and rotating elements when firing your weapon, you can create awesome stuff like this (the rotating gear and piston):



Another great demonstration of various weapon (and character) designs made with the SCK is the Garry's Mod gamemode "Darkest Days":

FAQ and final comments
How do I make it shoot?
This tool is only used to create weapon designs. Weapon functionality is something you have to script yourself.

-----------------------------------------------------------------------------------------------------------------------------
Do you want to help improve the SCK? The source code is available on GitHub. You're free to fork it.
https://github.com/Clavus/SWEP_Construction_Kit/

If you have questions, support ended years ago. Hope you'll still find it useful!
194 Comments
LλMBDA Huge SCP / Gmod Fan 17 Mar @ 9:51am 
5/10
LλMBDA Huge SCP / Gmod Fan 15 Feb @ 3:20pm 
:I
GabeIsHere 27 Mar, 2024 @ 8:31pm 
is anyone still willing to answer questions around here, if so, can i ask one?
V1 17 Aug, 2023 @ 11:46pm 
support ended years ago
Szpieg2000 8 Aug, 2023 @ 10:38am 
Does this still work?
Subwern✙ 30 Jul, 2023 @ 9:29am 
where do i put the

SWEP.VElements = {
["battery"] = { type = "Model", model = "models/items/combine_rifle_cartridge01.mdl", bone = "ValveBiped.base", rel = "", pos = Vector(-0.519, 0.518, -7.792), angle = Angle(0, -8.183, -15.195), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["bread"] = { type = "Model", model = "models/items/combine_rifle_ammo01.mdl", bone = "ValveBiped.base", rel = "", pos = Vector(-0.519, -0.519, 10.909), angle = Angle(0, 0, 0), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name"] = { type = "Model", model = "models/items/battery.mdl", bone = "ValveBiped.base", rel = "", pos = Vector(0.518, -0.519, 0), angle = Angle(0, 0, 0), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}
end
cozmo 12 Mar, 2023 @ 6:28pm 
oh ok
rabbitfart39 11 Mar, 2023 @ 6:44pm 
you put it under "if client then"
cozmo 11 Mar, 2023 @ 3:42pm 
Where do I put the code from the viewmodel if my swep's base is the default weapon_base??
rabbitfart39 5 Feb, 2023 @ 11:17am 
never mind