S  W  A  T   3   M  O  D    H  Q    
ADVANCED TOPIC - CLOSE WINDOW WHEN FINISHED

Creating Throwable Ammunition

With all of the ado about making standard ammunition, it is, at the final analysis, just ammunition. Special properties are limited to buckshot, less than lethal capabilities, and armor piercing/damage potential.

You ask, what about more interesting ammunition? Rubber slugs, tear gas canisters, dart guns (uh, dart guns?)

It's possible, thanks to the efforts of the ever-vigilant SWAT3 programmers. With a little clever data file manipulation, the ability to create such things is a snap! Throwable ammunition is defined as thrown objects (flashbangs and CS gas are a good example) that are fired from weapons. Many things can be thrown and there is a large amount of freedom available as to how the objects can behave.

To illustrate the concept, I'm going to take you step-by-step through the process of creating an M79 "thumper" grenade launcher. As primary ammo, this launcher will fire time delay flashbang grenades. The secondary ammunition will be timed-fuse CS gas grenades. It will have 1 round in the magazine at any time and will eject a shell only when reloaded.

Sounds like a huge job? Not really. It requires one new gun and two new throwable ammo types. Here's the list of files included (check your SWAT3 folder, under the Mods subfolder and look for the M79 mod).

Models

Textures/Sprites Sounds Data Files

40MM_Brass.gsm

40MM_Brass.bmp foomp0.cmp

modsounds.dat

40MM_Shell.gsm

40MM_Shell.bmp foomp1.cmp

modeffects.dat

40MM_Projectile.gsm ui_redical_40MM.bmp  foomp2.cmp

modguns.dat

M79.gsm 

ui_redical_40MM_dim.bmp  

modammodefs.dat 

 

rifl_M79_preview.bmp  

modskins.dat

 

UI_M79.bmp   

modenttemplates.dat

 

THUMP_Urban.bmp   

moditems.dat

 

ui_40mm.bmp   

modstrings.dat

 

   

modswt_data.dat

We'll go through the process step by step.

 

Step 1 - Get The Skins In Order

The first thing to do is get the graphical definitions of both the gun and the ammo ready. This will reside in the modskins.dat file. The process for linking the skins for weapons that fire throwables is exactly the same as standard weapons. The only difference here, and this is important, is that since this is a throwable object, it must have its own skin; standard ammunition does not actually "exist" graphically in the game world and therefore requires no skin. It is not absolutely necessary to define a thrown weapon in a 3d .gsm object; you may use a sprite, in which case no entry in skins.dat is necessary for the actual projectile. If you wish to use a sprite, you must make a special entry in enttemplates.dat, and we'll handle that later. For now, check out the sample modskins.dat:

Skins
{
rifl_M79              M79                     0
40MM_Brass       40MM_Brass       0
40MM_Projectile 40MM_Projectile 0
40MM_Shell        40MM_Shell         0
}

So, we have four actual skin names defined; we will use them in the following steps.

 

Step 2 - Define Sounds

What's different here? Not much, unless you wish to define your own bounce, explosion, and reload sounds. There may be more actual interaction with a thrown object; certainly bounces and explosion sounds when dealing with grenade launches. In terms of actual necessity of specialized fields just for thrown objects, there are none.

Have a look at the m79 modsounds.dat:

Sounds
{
Gunshot_GL0 foomp0 100 250 3000 0 0 0 1 
Gunshot_GL1 foomp1 100 250 3000 0 0 0 1 
Gunshot_GL2 foomp2 100 250 3000 0 0 0 1 
Gunshot_GL3 foomp0 100 250 3000 0 0 0 1 
 
MagIn_rifl_M79 M4MagIn 100 50 300 0 0 0 0
MagOut_rifl_M79 M4MagOut 100 50 300 0 0 0 0
Rack_rifl_M79 M4Rack 100 50 300 0 0 0 0
Tap_rifl_M79 M4Tap 100 50 300 0 0 0 0

 

Step 3 - Setting Up The Ammo

Now that we have the sounds set up, we need to define the actual ammo type. Look inside the modammodefs.dat:

AmmoDefs

{

// AmmoType

PointBlank

APPercent

IsLTL

IsBreaching

IsBuckshot

MuzzleVel

SoundVolume

Name

// --------

----------

---------

-----

-----------

----------

---------

-----------

----

_throw_40flash

1

0

0

0

0

700

100

40mm Flashbang

_throw_40cs

1

0

0

0

0

800

100

40mm CS Canister

}

"That's it?" you might ask. "No AmmovsBody or AmmovsMaterials?" Nope; nothing like that is required here, throwable objects do not penetrate bodies or materials, and therefore only need a few pieces of data in one section. All fields must be filled in here but the PointBlank, APPercent, and IsBreaching fields are ignored. It is important to note that the MuzzleVel for thrown objects is described in inches per second, not feet per second like normal ammunition.

Also, the name of the ammunition MUST BEGIN WITH "_throw_". This tells SWAT3 to treat this ammunition as throwable ammunition, and is absolutely necessary to link effects correctly. Remember these names, you will see them again.

 

Step 4 - Defining The Unique Ammo Entities

This is where we depart from normal ammunition procedure. Notice that there is a file called modenttemplates.dat which you never touched when working with regular ammunition. Open it up now.

Entities

{

// instance name

class

parms

// -------------

-------------

-----

40flash

Flashbang

(skin=40MM_Projectile, bouncesound=bounce*, fuse=2.5, gravity=0.5)

40cs

CSGrenade

(skin=40MM_Projectile, bouncesound=bounce*, fuse=1, gravity=0.5)

}

If you had previously worked with effects.dat, you'll notice that it follows the same format. A name, a class, and a parameter list. The name, you'll notice, is the name defined in ammodefs.dat without the _throw_ prefix. This is important, and is the format all throwable ammunition must follow!

This file defines exactly how the ammo will behave when fired, and what effects it will have on the environment. It can queue effects in effects.dat and play sounds in sounds.dat; it also references models in skins.dat or sprites in sprites.dat. It's a fairly complex setup, but the general format always stays the same: name, class, and parameter list.

It's time to digress and offer you a chart showing all of the entity templates that can represent throwable ammunition, and their parameters.

Throwable Ammo Entity Chart

 

Step 5 - Defining The Weapon To Fire The Ammunition

You have almost everything you need to fully define an ammunition; but of course, what good is an ammunition type without a weapon to fire it? This is where we'll define the M79 weapon and set up its properties. Have a look at the modguns.dat file:

Guns

{

//

// type

length

grip

fire delay

recoil

primary sound

secondary sound

flashA

flashB

primary ammo

secondary ammo

out-of-ammo click

rounds per burst

class

boundradius

renderoffset

muzzlevelmul

suppressed

zoomfactor

inertia

soundmul

muzzleflashmul

flashlight

linktochest

swatguysel

friendlyname

// ----

------

----

----------

------

-------------

---------------

-------

-------

------------

--------------

-----------------

----------------

------

-----------

------------

------------

----------

----------

-------

--------

--------------

----------

-----------

----------

------------

rifl_M79

36

1

0.8

2.5

Gunshot_GL*

Gunshot_GL*

gun_flashA

gun_flashB

(_throw_40flash,10,1)

(_throw_40cs,10,1)

NoAmmo_Rifle

1

1

12.0

(0,0,12)

1.0

0

1.0

1.34

1.0

.25

0

1

1

$rifl_M79_name

}

The deal here is that the M79 is set up to fire the throwable projectiles "40flash" and "40cs". In guns.dat these names must be prefixed by the "_throw_" string.  Notice also that the primary and secondary sounds use the slick trick of random sounds (used by appending a "*" after the base sound name). All other fields look similar to a standard weapon.

Step 6 - Defining Effects

Setting up modeffects.dat to properly handle the incendiary effects of a grenade plus the unique "caseless" shots of the M79 can be a challenge indeed. Let's pick apart the modeffects.dat included in the mod.

Effects
{
// muzzle flash
gunsmoke_rifl_M79 SpriteExp (sprite=gunsmoke_lg,dir=0 1 0, count=7,minrange=3,maxrange=6,minlife=0.5,maxlife=2.0,factor=0.5,drift=0 2 0,spread=45)


// magazines -- one per gun type
//normally it's a magazineeffect, but doing this makes it look a little more interesting.
M79shell ShellCasing (skin=40MM_brass,Elasticity=0.5,BoundRadius=1.0,LifeTime=60,BounceSound=shell_bounce*)
rifl_M79_mag MultiEffects (0=gunsmoke_rifl_M79,1=M79shell)

// shell casings
shell__throw_40flash ShellCasing (skin=40MM_brass,Elasticity=0.5,BoundRadius=1.0,LifeTime=0,BounceSound=shell_bounce*)
shell__throw_40cs ShellCasing (skin=40MM_brass,Elasticity=0.5,BoundRadius=1.0,LifeTime=0,BounceSound=shell_bounce*)
}

Yowza. What's all this? Let's begin with section #1: muzzle flash.

The muzzle flash of the M79 produces a cloud of smoke. The name of the effect is gunsmoke_rifl_M79, this must sync up with modguns.dat which we will cover later. Notice that if you take away the "gunsmoke_" part that you're left with "rifl_M79", this must be the name of the M79 launcher in guns.dat for this effect to properly play automatically when the M79 is fired in the game.

The second part is the M79 "magazine", or, in this case, the empty shell that dumps out when you reload after firing. If the player reloads the weapon after emptying the magazine (one shot, in this case), the "rifl_M79_mag" is actually a multieffect! This allows us to spawn both smoke and a shell casing, which makes it look like the shell is smoking when it comes out of the tube; the shell casing will have the skin specified in the ShellCasing effect called "M79shell", located above the "rifle_M79_mag" effect, and the physical properties and sounds specified in the parameters list. Notice that the name of our gun in modguns.dat is rifl_M79. To make the magazine dropping effect work, you must give the effect a name of your gun with _mag tacked on the end; this will make SWAT3 automatically play your effect when the magazine is dropped.

Lastly, the shell casings. You might ask, "Why do we need these? The M79 doesn't eject shell casings when it fires!" You're right, but if we didn't put a shell casing effect in, we'd get the default effect: sparks flying out the side. So we put in these standard parameters, ripped from the magazine effect above, but we make an important change: we set LifeTime to zero! This makes the shell casings invisible, therefore completing our firing effect!

 

Step 7 - The Final Touches

Three more data files make up this mod, and they are essential. They are modswt_data.dat, modstrings.dat, and moditems.dat. For information on how these three final files work, see the Common Tasks-Creating Weapons section.

There is a preview picture entitled wp_rifl_M79_preview.bmp. The name of the gun in modguns.dat is rifl_M79, and therefore to name a preview picture properly, you must encase it in this fashion:

wp_ guns.dat name _preview.bmp


Once the final files are in, the M79 is ready to rumble. Enjoy!