EDIT: IF YOU HAVE CRASHING PROBLEMS, REMOVE EVERYTHING IN THE "customization" TAG!Since the Pre-Beta was released I thought it might be nice to do a little tutorial for the Custom Weapons System.
First of all, your viewmodel and worldmodel NEED to have the "muzzle" attachment in order to work properly, so if you see random bullets all over the place you know why.
Got that? Good, let's roll!
In the scripts/example folder you can find a file called "weapon_customexample.txt". Copy it to the root of the "scripts" folder and change the "example" part of the name to be any number you want (up to 30)
Inside, you will see the following:
// Pistol
WeaponData
{
// Weapon data is loaded by both the Game and Client DLLs.
"printname" "Example Gun" //Name.
"viewmodel" "models/weapons/v_pistol.mdl" //Viewmodel.
"playermodel" "models/weapons/w_pistol.mdl" //Worldmodel.
"anim_prefix" "pistol" //Animations for NPCs.
"weapon_type" "pistol" //Weapon Type.
"bucket" "1" //The category this will go into.
"bucket_position" "0" //The slot this will go into.
"bucket_360" "0"
"bucket_position_360" "0"
"clip_size" "18" //Clip 1 size
"clip2_size" "-1" //Clip 2 size
"default_clip" "18" //The amount this will have in Clip 1 when spawned by default.
"default_clip2" "-1" //The amount this will have in Clip 2 when spawned by default.
"primary_ammo" "Pistol" //Primary ammo type.
"secondary_ammo" "None" //Secondary ammo type.
"weight" "2" //How much NPCs want to pick this up.
"rumble" "1" //Rumble setting for controllers.
"item_flags" "0" //Flags for the weapon.
"BuiltRightHanded" "1" //Check to see if this is Left-Handed. Useful for CSS weapons.
"AllowFlipping" "1" //Check to see if we can use flipping.
"MagazineStyledReloads" "1" //Check to see if we can use Magazine-Styled Reloads.
"UseMuzzleSmoke" "1" //Check to see if we can use Muzzle Smoke.
"useironsights" "1" //Check if we can use Ironsights.
"LowerWeapon" "1" //Check if we can lower the weapon while sprinting. Disable this if your viewmodel does not have a lowering animation.
//Ironsight settings
IronSight
{
"right" "-6.010000"
"up" "4.050000"
"forward" "-10"
"pitch" "-0.1"
"yaw" "-1.050000"
"fov" "-5"
}
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)
SoundData
{
"reload" "Weapon_Pistol.Reload"
"reload_npc" "Weapon_Pistol.NPC_Reload"
"empty" "Weapon_Pistol.Empty"
"single_shot" "Weapon_Pistol.Single"
"single_shot_npc" "Weapon_Pistol.NPC_Single"
"special1" "Weapon_Pistol.Special1"
"special2" "Weapon_Pistol.Special2"
"burst" "Weapon_Pistol.Burst"
}
// Weapon Sprite data is loaded by the Client DLL.
TextureData
{
"weapon"
{
"font" "WeaponIcons"
"character" "d"
}
"weapon_s"
{
"font" "WeaponIconsSelected"
"character" "d"
}
"weapon_small"
{
"font" "WeaponIconsSmall"
"character" "d"
}
"ammo"
{
"font" "WeaponIconsSmall"
"character" "p"
}
"crosshair"
{
"font" "Crosshairs"
"character" "Q"
}
"autoaim"
{
"file" "sprites/crosshairs"
"x" "0"
"y" "48"
"width" "24"
"height" "24"
}
}
//The "meat" of the weapon.
"WeaponSpec"
{
"WeaponOptions"
{
"CanReloadSingly" "1" //Check if we can reload 1 round at a time.
"DualWeapons" "0" //Check if we can use dual welding. This only works on primary fire unless you want "FireBothGuns" on secondary fire.
}
//Stuff that we will do on primary fire. Remove if you do not need primary fire (if you want night vision binoculars).
"PrimaryFire"
{
"FireRate" "1.0" //How fast this fires
"IronsightFireRate" "1.0" //How fast this fires when ironsighted.
"ZoomFireRate" "1.0" //How fast this fires when zoomed in.
"InfiniteAmmoPerk" "1" //Check to see if we can use this with the Infinite Ammo Perk. Disable "InfiniteAmmo" to stop conflicts.
"InfiniteAmmo" "0" //Check to see if we can use this with Infinite Ammo by default. Disable "InfiniteAmmoPerk" to stop conflicts.
"MinRange" "0" //The minimum amount of range that this weapon would fire at.
"MaxRange" "1400" //The maximum amount of range that this weapon would fire at.
"CanFireUnderwater" "1" //Can we use this underwater?
"FireBothGuns" "0" //Can we fire both guns? Only works if "Dual Weapons" is on.
//Bullet Settings. Remove if you do not want bullets.
"Bullet"
{
"Damage" "4" //Amount of damage we will do.
"ShotCount" "1" //How many shots we will fire at once.
"Spread"
{
//Spread (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"IronsightSpread"
{
//Spread when ironsighted (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"ZoomSpread"
{
//Spread when zoomed in (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
}
//RPG Missle Settings. Remove if you do not want RPG Missles.
"Missle"
{
"UseRecoil" "1" //Should we use recoil when firing this?
}
//SMG Grenade Settings. Remove if you do not want SMG Grenades.
"SMGGrenade"
{
"Damage" "4" //Amount of damage we will do.
"UseRecoil" "1" //Should we use recoil when firing this?
}
//Combine Energy Ball Settings. Remove if you do not want Combine Energy Balls.
"AR2EnergyBall"
{
"Radius" "10" //The radius that this will spawn at.
"Mass" "150" //The amount of mass that this will have.
"Duration" "2" //How long this will be live for.
}
//Recoil Settings.
"Recoil"
{
"EasyDampen" "0.5" //How much we will dampen the recoil on the Easy difficulty.
"Degrees" "1" //How many degrees.
"Seconds" "2" //How long this will be.
}
}
//Stuff that we will do on Secondary Fire. Remove if you do not need Secondary Fire.
"SecondaryFire"
{
"FireRate" "1.0" //How fast this fires
"IronsightFireRate" "1.0" //How fast this fires when ironsighted.
"ZoomFireRate" "1.0" //How fast this fires when zoomed in.
"UsePrimaryAmmo" "0" //Check if we can use primary ammo on secondary fire
"InfiniteAmmoPerk" "1" //Check to see if we can use this with the Infinite Ammo Perk. Disable "InfiniteAmmo" to stop conflicts.
"InfiniteAmmo" "0" //Check to see if we can use this with Infinite Ammo by default. Disable "InfiniteAmmoPerk" to stop conflicts.
"MinRange" "0" //The minimum amount of range that this weapon would fire at.
"MaxRange" "1400" //The maximum amount of range that this weapon would fire at.
"CanFireUnderwater" "1" //Can we use this underwater?
"FireBothGuns" "0" //Can we fire both guns? Only works if "Dual Weapons" is on.
//Bullet Settings. Remove if you do not want bullets.
"Bullet"
{
"Damage" "4" //Amount of damage we will do.
"ShotCount" "1" //How many shots we will fire at once.
"Spread"
{
//Spread (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"IronsightSpread"
{
//Spread when ironsighted (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"ZoomSpread"
{
//Spread when zoomed in (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
}
//RPG Missle Settings. Remove if you do not want RPG Missles.
"Missle"
{
"UseRecoil" "1" //Should we use recoil when firing this?
}
//SMG Grenade Settings. Remove if you do not want SMG Grenades.
"SMGGrenade"
{
"Damage" "4" //Amount of damage we will do.
"UseRecoil" "1" //Should we use recoil when firing this?
}
//Combine Energy Ball Settings. Remove if you do not want Combine Energy Balls.
"AR2EnergyBall"
{
"Radius" "10" //The radius that this will spawn at.
"Mass" "150" //The amount of mass that this will have.
"Duration" "2" //How long this will be live for.
}
//Recoil Settings.
"Recoil"
{
"EasyDampen" "0.5" //How much we will dampen the recoil on the Easy difficulty.
"Degrees" "1" //How many degrees.
"Seconds" "2" //How long this will be.
}
}
//Stuff that we will do on Zoom. Remove if you do not need Zoom.
"Zoom"
{
"UsesSound" "0" //Check to use a sound when zooming (SPECIAL1 is the default)
"UsesColor" "0" //Check to change the color of the screen when zoomed in.
"UseOnPrimaryFire" "0" //Check to see if we can use this on Primary Fire instead on secondary fire.
//Color (Only works when "UsesColor" is enabled". Uses the RGBA format.)
"ZoomColor"
{
"Red" "0"
"Green" "0"
"Blue" "0"
"Alpha" "0"
}
}
A LOT of code there, isn't it? Well, let's go over it.
Most of this top code can be explained here:
http://bsnooch.com/forums/index.php?topic=92.0 However, here's a few little things I should point out:
"rumble"
The rumble value for controllers. Since this version of Source has full controller support, you CAN use this if you want to.
"MagazineStyledReloads"
Toggles Magazine-styled reloads for the weapon. Can be explained here:
Quote from here: https://developer.valvesoftware.com/wiki/Magazine_style_reloads
Say you want to make each shot and each reload count? In CS you can reload anytime you feel like. Some bullets will be deducted and that is all. However, in real life, you will not start to load the half-empty mag, you pull out a new one, and toss the used one. This system can be found in BF2, and some other games.
"UseMuzzleSmoke"
Toggles L4D-styled muzzle smoke on the weapon after firing.
NOTE: You have to have the "muzzle" attachment (and "muzzle2" if you want dual weapons) in order for this to work!"useironsights"
Toggles if we can use Ironsights on the weapon. ENABLE THIS if you want ironsights or they will not work.
"LowerWeapon"
A toggle to see if we can lower the weapon while sprinting/waiking. If you don't have a lowering animation on your viewmodel,
DISABLE THIS."weapon_small"
{
"font" "WeaponIconsSmall"
"character" "d"
}
This is a new one in the TextureData key. It seems to display a small version of the weapon icon for your weapon. Be sure you have a small one.
Before we go to the good stuff, here's a list of custom ammotypes you can use in the mod.
"CustomBullet1_Normal"
"CustomBullet2_NormalBurn"
"CustomBullet3_NormalBurnGib"
"CustomBullet4_NormalAlwaysGib"
"CustomBullet5_NormalDissolve"
"CustomBullet6_NormalDissolveGib"
"CustomBullet7_Buckshot"
"CustomBullet8_BuckshotBurn"
"CustomBullet9_BuckshotBurnGib"
"CustomBullet10_BuckshotAlwaysGib"
"CustomBullet11_BuckshotDissolve"
"CustomBullet12_BuckshotDissolveGib"
"CustomBullet13_Sniper"
"CustomBullet14_SniperBurn"
"CustomBullet15_SniperBurnGib"
"CustomBullet16_SniperAlwaysGib"
"CustomBullet17_SniperDissolve"
"CustomBullet18_SniperDissolveGib"
"CustomBullet19_BuckshotSniper"
"CustomBullet20_BuckshotSniperBurn"
"CustomBullet21_BuckshotSniperBurnGib"
"CustomBullet22_BuckshotSniperAlwaysGib"
"CustomBullet23_BuckshotSniperDissolve"
"CustomBullet24_BuckshotSniperDissolveGib"
"CustomBullet25_NormalKnockback"
"CustomBullet26_BuckshotKnockback"
"CustomBullet27_SniperKnockback"
"CustomBullet28_BuckshotSniperKnockback"
Now it is time to go into the "meat of the weapon"!
//The "meat" of the weapon.
"WeaponSpec"
{
"WeaponOptions"
{
"CanReloadSingly" "1" //Check if we can reload 1 round at a time.
"DualWeapons" "0" //Check if we can use dual welding. This only works on primary fire unless you want "FireBothGuns" on secondary fire.
}
//Stuff that we will do on primary fire. Remove if you do not need primary fire (if you want night vision binoculars).
"PrimaryFire"
{
"FireRate" "1.0" //How fast this fires
"IronsightFireRate" "1.0" //How fast this fires when ironsighted.
"ZoomFireRate" "1.0" //How fast this fires when zoomed in.
"InfiniteAmmoPerk" "1" //Check to see if we can use this with the Infinite Ammo Perk. Disable "InfiniteAmmo" to stop conflicts.
"InfiniteAmmo" "0" //Check to see if we can use this with Infinite Ammo by default. Disable "InfiniteAmmoPerk" to stop conflicts.
"MinRange" "0" //The minimum amount of range that this weapon would fire at.
"MaxRange" "1400" //The maximum amount of range that this weapon would fire at.
"CanFireUnderwater" "1" //Can we use this underwater?
"FireBothGuns" "0" //Can we fire both guns? Only works if "Dual Weapons" is on.
//Bullet Settings. Remove if you do not want bullets.
"Bullet"
{
"Damage" "4" //Amount of damage we will do.
"ShotCount" "1" //How many shots we will fire at once.
"Spread"
{
//Spread (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"IronsightSpread"
{
//Spread when ironsighted (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"ZoomSpread"
{
//Spread when zoomed in (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
}
//RPG Missle Settings. Remove if you do not want RPG Missles.
"Missle"
{
"UseRecoil" "1" //Should we use recoil when firing this?
}
//SMG Grenade Settings. Remove if you do not want SMG Grenades.
"SMGGrenade"
{
"Damage" "4" //Amount of damage we will do.
"UseRecoil" "1" //Should we use recoil when firing this?
}
//Combine Energy Ball Settings. Remove if you do not want Combine Energy Balls.
"AR2EnergyBall"
{
"Radius" "10" //The radius that this will spawn at.
"Mass" "150" //The amount of mass that this will have.
"Duration" "2" //How long this will be live for.
}
//Recoil Settings.
"Recoil"
{
"EasyDampen" "0.5" //How much we will dampen the recoil on the Easy difficulty.
"Degrees" "1" //How many degrees.
"Seconds" "2" //How long this will be.
}
}
//Stuff that we will do on Secondary Fire. Remove if you do not need Secondary Fire.
"SecondaryFire"
{
"FireRate" "1.0" //How fast this fires
"IronsightFireRate" "1.0" //How fast this fires when ironsighted.
"ZoomFireRate" "1.0" //How fast this fires when zoomed in.
"UsePrimaryAmmo" "0" //Check if we can use primary ammo on secondary fire
"InfiniteAmmoPerk" "1" //Check to see if we can use this with the Infinite Ammo Perk. Disable "InfiniteAmmo" to stop conflicts.
"InfiniteAmmo" "0" //Check to see if we can use this with Infinite Ammo by default. Disable "InfiniteAmmoPerk" to stop conflicts.
"MinRange" "0" //The minimum amount of range that this weapon would fire at.
"MaxRange" "1400" //The maximum amount of range that this weapon would fire at.
"CanFireUnderwater" "1" //Can we use this underwater?
"FireBothGuns" "0" //Can we fire both guns? Only works if "Dual Weapons" is on.
//Bullet Settings. Remove if you do not want bullets.
"Bullet"
{
"Damage" "4" //Amount of damage we will do.
"ShotCount" "1" //How many shots we will fire at once.
"Spread"
{
//Spread (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"IronsightSpread"
{
//Spread when ironsighted (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
"ZoomSpread"
{
//Spread when zoomed in (in degrees)
"x" "2"
"y" "2"
"z" "2"
}
}
//RPG Missle Settings. Remove if you do not want RPG Missles.
"Missle"
{
"UseRecoil" "1" //Should we use recoil when firing this?
}
//SMG Grenade Settings. Remove if you do not want SMG Grenades.
"SMGGrenade"
{
"Damage" "4" //Amount of damage we will do.
"UseRecoil" "1" //Should we use recoil when firing this?
}
//Combine Energy Ball Settings. Remove if you do not want Combine Energy Balls.
"AR2EnergyBall"
{
"Radius" "10" //The radius that this will spawn at.
"Mass" "150" //The amount of mass that this will have.
"Duration" "2" //How long this will be live for.
}
//Recoil Settings.
"Recoil"
{
"EasyDampen" "0.5" //How much we will dampen the recoil on the Easy difficulty.
"Degrees" "1" //How many degrees.
"Seconds" "2" //How long this will be.
}
}
//Stuff that we will do on Zoom. Remove if you do not need Zoom.
"Zoom"
{
"UsesSound" "0" //Check to use a sound when zooming (SPECIAL1 is the default)
"UsesColor" "0" //Check to change the color of the screen when zoomed in.
"UseOnPrimaryFire" "0" //Check to see if we can use this on Primary Fire instead on secondary fire.
//Color (Only works when "UsesColor" is enabled". Uses the RGBA format.)
"ZoomColor"
{
"Red" "0"
"Green" "0"
"Blue" "0"
"Alpha" "0"
}
}
"WeaponOptions"{
"CanReloadSingly"
Check if we can reload 1 round at a time.
"DualWeapons"
Check if we can use dual welding. This only works on primary fire unless you want "FireBothGuns" on secondary fire.
NOTE: your weapon model needs to have the following animation events:
ACT_VM_PRIMARYATTACK_R
ACT_VM_PRIMARYATTACK_R_RECOIL1
ACT_VM_PRIMARYATTACK_R_RECOIL2
ACT_VM_PRIMARYATTACK_R_RECOIL3
ACT_VM_PRIMARYATTACK_L
ACT_VM_PRIMARYATTACK_L_RECOIL1
ACT_VM_PRIMARYATTACK_L_RECOIL2
ACT_VM_PRIMARYATTACK_L_RECOIL3}
Stuff that we will do on primary fire. Remove if you do not need primary fire (if you want night vision binoculars).
"PrimaryFire"{
"FireRate"
How fast this fires
"IronsightFireRate"
How fast this fires when ironsighted.
"ZoomFireRate"
How fast this fires when zoomed in.
"InfiniteAmmoPerk"
Check to see if we can use this with the Infinite Ammo Perk. Disable "InfiniteAmmo" to stop conflicts.
"InfiniteAmmo"
Check to see if we can use this with Infinite Ammo by default. Disable "InfiniteAmmoPerk" to stop conflicts.
"MinRange"
The minimum amount of range that this weapon would fire at.
"MaxRange"
The maximum amount of range that this weapon would fire at.
"CanFireUnderwater"
Can we use this underwater?
"FireBothGuns"
Can we fire both guns?
Only works if "Dual Weapons" is on.Bullet Settings. Remove if you do not want bullets."Bullet"{
"Damage"
Amount of damage we will do.
"ShotCount"
How many shots we will fire at once."Spread"
{
"x" "2"
"y" "2"
"z" "2"
}
Spread (in degrees)"IronsightSpread"
{
"x" "2"
"y" "2"
"z" "2"
}
Spread when ironsighted (in degrees)"ZoomSpread"
{
"x" "2"
"y" "2"
"z" "2"
}
Spread when zoomed in (in degrees)}
RPG Missle Settings. Remove if you do not want RPG Missles."Missle"{
"UseRecoil"
Should we use recoil when firing this?
}
SMG Grenade Settings. Remove if you do not want SMG Grenades."SMGGrenade"{
"Damage"
Amount of damage we will do.
"UseRecoil"
Should we use recoil when firing this?
}
Combine Energy Ball Settings. Remove if you do not want Combine Energy Balls."AR2EnergyBall"{
"Radius"
The radius that this will spawn at.
"Mass"
The amount of mass that this will have.
"Duration"
How long this will be live for.
}
Recoil Settings."Recoil"{
"EasyDampen"
How much we will dampen the recoil on the Easy difficulty.
"Degrees"
How many degrees.
"Seconds"
How long this will be.
}
}
Stuff that we will do on Secondary Fire. Remove if you do not need Secondary Fire."SecondaryFire"{
Everything is about the same except there is one more option to talk about:
"UsePrimaryAmmo"
This is used to see if we can use the weapon's primary ammo instead of the weapon's secondary ammo.
}
Stuff that we will do on Zoom. Remove if you do not need Zoom."Zoom"{
"UsesSound"
Check to use a sound when zooming (SPECIAL1 is the default)
"UsesColor"
Check to change the color of the screen when zoomed in.
"UseOnPrimaryFire"
Check to see if we can use this on Primary Fire instead of secondary fire.
Color (Only works when "UsesColor" is enabled". Uses the RGBA format.)"ZoomColor"
{
"Red" "0"
"Green" "0"
"Blue" "0"
"Alpha" "0"
}
}
Once you have finished your custom weapon, you can either place it in the root of your scripts directory, or you can create a folder in the addons directory, then create a script folder in there, then place your weapon file in. Read more here:
http://bsnooch.com/forums/index.php?topic=1551.0