Tutorial: Weapon reconfiguration (Part 2)

Once the basic sections in you config.cpp have been set up, you need to begin actually creating the soldiers and vehicles.

If you want to use weapons that have sights or other attachments on them, they most likely don't initially exist. To add sights, go must actually create a new weapon and add the parameters for the LinkedItems.

In order to do this, you must understand how inheriting other classes works. If there is another gun, say "RH\_m4\_Ris" that you want to change, you do not want to have to reprogram the entire weapon and just change a couple things. Instead, you can inherit a class, and just change the things you want to change. First you must declare the class, and then, when creating your new class, tell the game it is a "child" of the original class. It would look like:

class RH\_m4\_Ris;

class RH\_m4\_RIS\_M68\_PEQ15: RH\_m4\_Ris

{

...

};

In this case, the original class is declared, "RH\_m4\_Ris" then the new class is created, followed by a colon, and then the original class. This is read as "RH\_m4\_RIS\_M68\_PEQ15 inherits RH\_M4\_RIS." Any changes created inside the brackets will override any settings in the original item. Note that if you use a weapon from another .pbo, that .pbo must be listed as a requiredAddon, either in the same .pbo, or in one of the dependencies sections of a .pbo already listed as a requirement. This ensures that those files are loaded before this one, meaning it will never load before the class has been created.

The changes that go into the the weapons are as follows:

class RH\_m4\_Ris;

class RH\_m4\_RIS\_M68\_PEQ15: RH\_m4\_Ris

{

scope = 2;

class LinkedItems

{

class LinkedItemsOptic

{

slot = "CowsSlot";

item = "RH\_compM2";

};

class LinkedItemsAcc

{

slot = "PointerSlot";

item = "RH\_peq15b";

};

};

};

This example shows adding a Aimpoint CompM2 red dot sight and a PEQ15 IR laser to the RH\_M4\_RIS. Here, scope = 2 tells the mod not to display the weapon anywhere. Scope = 0 in a weapon means show in arsenal and everywhere else, 1 means only in arsenal, and 2 means show nowhere. Next you enter the linkedItems section. Inside that, you can declare the LinkedItemsOptic section. Inside you change two parameters, the slot which should always be the same (CowsSlot, which is the name for the slot where all optics go on every gun), and the name of the item used. The same goes for the LinkedItemsAcc, which always goes in the PointerSlot slot, and then define the attachment. Note that some weapons may not have a PointerSlot, such as guns that do not have rails on the sides. Also remember to put the classname of your new weapon into the weapons[] section of the cfgPatches section in your config.cpp.

Now, you can't just plop this code anywhere in the config.cpp. This code must be placed in the cfgWeapons class. It is also standard practice to split the sections into different files, using an include command. If the above code were in the file, "USArmy\_weap.hpp", the section in the config.cpp to include it already inside the cfgWeapons section would look like:

class cfgWeapons

{

  #include "USArmy\_weap.hpp"

};

#include is a command that tells the game to basically take whatever is in the file directed, and put it in the place of the command. Based on the rules of filenames that I talked about last time, we know that this file is already in the same folder as config.cpp. Note that no semicolon is required at the end of this line, so long as the code inside the other file is correct and ends in a semicolon. Also note that you must always include files of the type .hpp. All file types that have code in them can be edited with something as simple as notepad, and then just renamed to the new filename, or using a specific coding environment, such as what I use, Atom, with a plugin to allow the editor to recognize the Arma coding syntax.