Building Custom Weapons

Custom weapons are 3D weapon files, that can be fired, dropped, or be used as pylons. It is a pretty simple task once you know how to do it, but on your first try, it might be difficult to understand how it works. This tutorial is focused on getting your first weapon file to work properly.


You'll need the following tools to do this properly.

You need to know the following to understand this tutorial

That isn't much, but it is needed to safely navigate through this tutorial. In addition, the following is generally welcomed

Now, you're ready to take the plunge into actually building the weapon. This will be separated into 3 parts.

  1. Actually building the model in FSDS, and exporting to FS
  2. Decompiling the exported MDL using MdlDisAs and making the necessary changes, and then recompiling the file into a BGL weapon file.
  3. Making the necessary files for CFS2, and changing the DP file for the aircraft.

This tutorial will mainly be focused on No.2. Others will not be explained so thoroughly.

Ready? Here we go!


1. Building the weapon in FSDS

I'll take an Aim-9B I have built for a new weapons pack coming soon as an example.

Before you go on, you'll have to set FSDS to properly compile models suitable for weapons.

  1. Go to File-Project Properties.
  2. Change the Scale to 0.02

Build the weapon as you would any ordinary aircraft. Apply any textures now.

*Note*

In order to have good frame-rates with a reasonable amount of weapons mounted, I generally try to keep the number of polygons for each model below 150 polygons. It depends on the weapon, as complex weapons such as Air-Launched-Cruise-Missiles or Paveway type bombs may need a few more polygons to properly shape the object. There is no limit to the number of polygons you can use, but keep in mind a large number of polygons can take a heavy toll on the FPS on slower systems.

The Aim-9B above is 97 polygons with an 8-sided tube for the main body and a box for each of the fins.

Save your FSC file.

Select all your parts and join them into one object.

*Note*

You do not necessarily have to join all the parts into one object, but it will be easier to make the changes to the SCX file later on if you do so.

Export your object into FS


2. Decompiling the MDL file into an SCX file

1. Start MdlDisAs. Click on OK when the start-up screen comes up.

This is what you'll see now.

2. Go to "Open File" and select the MDL file you just exported your model into.

You will get a message asking you where your textures are if you assigned them in FSDS. Just click on "No Txtr Check" to bypass.

3. Click on "CheckMDL" to see if your MDL file is ready to be decompiled into an SCX file.

You may see 1 of the following windows. Beside each image is what you should do when you see that window.

Click on "Reset Length to First Terminator" to fix the MDL. It is now ready to be decompiled. Go on to Step 4.
This MDL is OK as it is. Click on "OK" and you are now ready to decompile the MDL file into an SCX file. Go to Step 4.
This MDL will not work properly in CFS2. Please see the "How to fix common MDL problems" section for instructions on how to fix this.
MdlDisAs will not properly decompile this MDL file. Please see the "How to fix common MDL problems" section for instructions on how to fix this.

4. Go to the "Source Files" tab in MdlDisAs, and click on "Save File"

MdlDisAs will now ask you where to save the SCX file. Save the file to a directory of your preference.

Go on to Editing the SCX File


How to fix common MDL problems

When you try to decompile your MDL file using MdlDisAs, it may give you error reports and fail to do so. In that case, here are a few things to look out for.

  1. Error message in CheckMDL saying "***Command Not Recognized as valid MDL code***"
  2. Error message in CheckMDL saying "Invalid Terminal Code" more than once
  3. Forgetting to "Reset Length to First Terminator" when "Invalid Terminal Code" error comes up once.

How to fix.

For problem #3, just click on the "Reset Length to First Terminator" button and save again.

For problems #1 and #2, things get a bit more exciting, and confusing.
After asking Daisuke Iga about these errors, he kindly told me these were caused by FSDS placing "Unknown variables" in the MDL file. FSDS does this only in a few specific file sizes (For reasons I do not know). To fix, it involves adding a few polygons to match a few "Safe sizes" I have mapped out for you. Here are the "Safe Sizes" I have found out so far.

  • 89 Polygons (Does not work sometimes. In that case, use 102)
  • 102 Polygons
  • 112 Polygons
  • 120 Polygons

The rule is, if your model in FSDS has the same number of polygons as the "Safe Sizes", MdlDisAs seems to have no trouble giving you a proper MDL file (You'll still have to do CheckMDL for any "invalid terminal code" errors though).

Say, for example, your model has 99 polygons. This is not in any of the "Safe Sizes" so well will go on too add a few polygons to fit in the "102 polygon" category. It can be anything, like tubes or individual polygons as long as the final polygon count is 102. In this case, you'll want to add 3 polygons.

As an added note, MdlDisAs does not seem to like simple objects. If you can't seem to get MdlDisAs to decompile no matter what you do, try adding a couple more extra parts hidden behind your "real" object to add some more vertex points and polygons.

After you're done editing your FSC file, export again and go through steps 1 to 3 again. If all is OK and you get a good MDLfile, go on to step 4.


Editing the SCX file

Open the SCX file using a text program of your choice. I use WordPad to do it. Here is what you might see:

Now, delete everything until you see ";*** Start of Main Aircraft Code ***"



Now add this Header at the very top of the document.


Header( 1 90 -89 180 -179 )
LibID( XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX )
LibObj(
SCALE 0.002
NAME wep_nameofyourchoice )


Edit ONLY the parts in RED

The LibID is a 32bit Hex code.
This means a 32-digit line using: 1,2,3,4,5,6,7,8,9,0 and A,B,C,D,E,F
This code can be anything as long as it's a 32bit Hex code, but IT MUST BE UNIQUE FROM ANY OTHER WEAPON

For example, one's code might be

0000000A 00010012 000F00AC 3489AFDE

The NAME is the name CFS2 calls for. This name will be used in the DP files for the weapon and aircraft using it. This name can be anything, as long as you keep to the Windows File Naming rule. Also, DO NOT USE A PERIOD

Next, you will go on to "comment out" all unneeded lines. When you "comment out" a line, SCASM ignores it. It can be done by typing a semi-colon (;) before the line you want to comment out.

When you see this forming of lines, comment out the "IfVarAnd" and "Jump" commands.

IfVarAnd( :L001140 0x7E 0x0001 )
; *** View Control Variable ***
Jump( :L0023F4 )


Like this



Look through your SCX files for other parts like this, and do it to all. If you had joined all the parts into 1 object in FSDS, there will only be 1 of them so it will be easy doing so.

Scroll down to the end of your SCX file. You see a line saying "EndA". You will delete this, and add "EndObj" in place.



This completes the editing phase. Save your SCX file as an SCA file.

Drag your SCA file to SCASM.EXE (In your SCASM directory) and release. A DOS window will pop up and then quickly disappear. A BGL file will appear in the same folder SCASM.EXE is.


This completes the editing phase. Next we go on to actually getting CFS2 to visually show the weapon.


Making the necessary files for CFS2, and changing the DP file for the aircraft.

Copy your BGL file to CFS2/SCENEDB/WEAPONS/SCENERY
Copy any textures to CFS2/SCENEDB/WEAPONS/TEXTURES

Go to CFS2/OBJECTS_DP and find a .DP file for a weapon of similar performance/usage. Since the Aim-9B used in this example is a 5-in Zuni Rocket with a "brain", I'll be using the DP file from the default US Rocket.

Create a duplicate file of the one you found to be the best suited to be used as a "base".

Rename the file to the name you used in the Header. In my example, it will be wep_aim9b

Now you have created all the files needed for the Weapon. We will now edit the DP file for the aircraft to carry it. Any aircraft would be OK, but you should stick to the default aircraft for testing purposes. I used the Hellcat to test out my weapon.

Here is a pic of what I did to load my new weapon on the Hellcat.



Basically, the name you entered in the Header for the weapon is used to call it from the aircraft's DP file. I won't go in depth about how to edit DP files as this is not the meaning of my tutorial.

Save your changes, and start CFS2.

Select your aircraft, and with any luck, you should see your new weapon!!!



Other great tutorials about weapon building:

CFS2 Loadouts By Martin Wright and Daisuke Iga
CFS2 Payloads By Simon Porter

Both available at http://www.freeflightdesign.com