Creating custom weapons: Difference between revisions

From TF2 Classified Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{stub}}
{{stub}}
{{todo|Add literally any information that is useful. I'll trim the fat and clean up the remaining stuff afterwards.}}
{{todo|Complete every current section and add new ones if applicable.}}




'''This guide is currently incomplete, so please look for a better one while this is being worked on!
'''This guide is currently incomplete, but it should suffice if you just need the basics!


If you're here, chances are you're looking to create your own weapons for ''TF2 Classified''. Whether for use against bots or other players, this guide should hopefully cover the majority of your questions regarding custom weapon creation. If it doesn't, ask for help in the #modding-discussion channel in the [https://discord.gg/tf2classified official TF2C Discord].
If you're here, chances are you're looking to create your own weapons for ''TF2 Classified''. Whether for use against bots or other players, this guide should hopefully cover the majority of your questions regarding custom weapon creation. If it doesn't, ask for help in the '''#modding-discussion''' channel in the [https://discord.gg/tf2classified official TF2C Discord].


= Getting Started =
= Getting Started =
Line 107: Line 107:
[[File:example_04_custompistol.png]]
[[File:example_04_custompistol.png]]


Here is how the description looks in game:
 
Here's how the description looks in game:


[[File:example_04_backpack.png]]
[[File:example_04_backpack.png]]


What's that? You want to change the model too? Well, with the base selection, there's only one that works with {{code|preset=3|"attach_to_hands" "2"}} - the Pistol model that we're currently using. However, what about TF2's c_models?
Here, the parameters have been adjusted to compensate for the new model, which is the Winger's c_model for this demonstration. Now that {{code|preset=3|"attach_to_hands"}} is set to 1, the Custom Pistol will use the c_arms animations that TF2 uses.
[[File:example_05_wingermodel.png]]
Here's how it looks in game:
[[File:example_05_world.jpg|540px]]
You might've noticed that the Engineer was added to {{code|preset=3|"used_by_classes"}}. Due to the way c_models work, you don't need to set different models for each class for the animations to work properly, which is why the change was made. However, v_models have the animations baked into the models themselves, so how do you get them to change between classes?
The answer lies with the {{code|preset=3|"model_player_per_class"}} parameter.
[[File:example_06_modelperclass.png]]
By adding this to the first version of the Custom Pistol, you can change the v_model used by each class, allowing you to have the weapon on both Scout and Engineer without making them share animations.


== Adding attributes ==
== Adding attributes ==

Latest revision as of 21:10, 24 June 2026


This guide is currently incomplete, but it should suffice if you just need the basics!

If you're here, chances are you're looking to create your own weapons for TF2 Classified. Whether for use against bots or other players, this guide should hopefully cover the majority of your questions regarding custom weapon creation. If it doesn't, ask for help in the #modding-discussion channel in the official TF2C Discord.

Getting Started

Before going over how to create custom weapons, we first need a functional custom item schema to put them into. The item schema is basically a big list that you append all of your weapons into, and is arguably the single most important file for that reason. It uses VDF, which is the standard format for storing game-related metadata in Source. If you don't know VDF, don't worry - it won't take long to understand the syntax.

Creating the custom item schema

To begin, create a file named custom_items_game.txt in the <SteamUserDir>\Team Fortress 2 Classified\tf2classified\custom\<Mod Name>\scripts directory. This is the file that will contain all of the information regarding your custom weapons. Please note that you cannot have multiple custom_items_game.txt files loaded simultaneously, so any other mod folders that contain them should be placed in tf2classified\custom\disabled to allow the new custom item schema to load.

Setting up the custom item schema

Shown below are the main parameters that should ideally be included in every single item schema. Copy this exactly into your custom_items_game.txt file.

Explanation

base "items_game.txt"

This line is responsible for merging the data from the custom item schema into TF2C's main item schema. Without this, none of TF2C's items, prefabs or attributes will load, which isn't very ideal.

"items_game"

The parameter that contains everything unique to the item schema. Whilst not particularly interesting, it's vital for the item schema to run.

"items"

The parameter that contains items. They must be defined here in order for them to appear in game.

"prefabs"

The parameter that contains prefabs, which will be explained later.

"attributes"

The parameter that contains attributes, which will also be explained later.

Creating your first weapon

The basics

To function, item entries must be placed under the "items" parameter, with the exact indentation shown in the upcoming template.

Shown below is a template item entry that contains the essential parameters for most custom weapons. Values in <> brackets are placeholder values that should be replaced by suitable ones.

Explanation

"<item id>"

The unique ID used by the weapon. Be careful: if shared with another item entry, the custom item schema will fail to load. Try to use high values (ideally >= 10000) to prevent clashes with vanilla item entries.

"name"

The unique internal identifier used by the weapon. Like "<item id>", the custom item schema will fail to load if it's shared with another entry.

"item_name"

The displayed name of the item, which can either be plaintext or a localised string (e.g. #TF_Weapon_Pistol). If you want to add "The" to the beginning of the name, add the "propername" parameter to the item entry and set the value to 1.

"item_type_name"

The item's type, which is displayed under the name in the description.

"item_logname"

The name used by the weapon when reported in the developer console.

"item_iconname"

The name of the weapon's main killicon. If an invalid icon is pointed to, then the default skull icon will be used instead. Supports SVG icons in resource\svgs\deathnotice and VTF icons defined in scripts\mod_textures.txt and scripts\mod_textures_tf2c.txt.

"item_class"

The item class to be used as a base for your weapon. A list of available item classes can be found here.

"item_slot"

The loadout slot that the weapon is located in. Below is a list of functional "item_slot" values:
primary
secondary
melee
pda
pda2
building
action [note]
utility [note]

"anim_slot"

The third-person and (if applicable) c_model animations to use. If absent, the item will use the default animations for its class. Below is a list of functional "anim_slot" values:
primary
primary2
secondary
secondary2
melee
melee_allclass
pda
pda2
building
item1
item2
item3
item4
passtime_ball
force_not_used

"model_player"

The model used in first person.

"model_world"

The model used in third person. If this parameter is absent from the item entry, the game will automatically use the model defined in the "model_player" parameter.

"image_inventory"

The icon used in the loadout menu and bucket.

"attach_to_hands"

This parameter controls what model's animations are used. If set to 1, the class' c_arms will be used for the animations. If set to 2, the item model's animations will be used instead.

"used_by_classes"

This controls which classes can use the item. Set to 1 to use the loadout slot defined under "item_slot", or set it to a specific loadout slot to get it to appear in that slot for a specific class.

"attributes"

The list of attributes that modify the weapon's behaviour. You can add as many attributes as you'd like, just as long as the attribute class isn't repeated. Some attributes can be condensed into a single line if you wish (e.g. <attribute name> "<value>"), which is helpful for meta-attributes like "hidden separator" and "provide on active" that are repeated often. A list of item attributes can be found here.

"static_attrs"

A variant of "attributes" that should only be used for attributes like "min_viewmodel_offset".

"visuals"

This parameter allows you to change the item's effects, like sounds and tracers. This will be explained in more detail later.

"mouse_pressed_sound"

The sound to play when the item is selected in a loadout grid.

"drop_sound"

The sound to play when the item is selected in a class' loadout screen.

Example

Below is an example item entry for a custom pistol with a clip size bonus, a damage penalty and the Winger's fire sounds. Copy it and try modifying it to get a feel for making items. If you're looking for models and soundscripts, try using HLMV++ and/or Hammer ++, or look at item entries in TF2 and TF2C's item schemas.


Here's how the description looks in game:


What's that? You want to change the model too? Well, with the base selection, there's only one that works with "attach_to_hands" "2" - the Pistol model that we're currently using. However, what about TF2's c_models?

Here, the parameters have been adjusted to compensate for the new model, which is the Winger's c_model for this demonstration. Now that "attach_to_hands" is set to 1, the Custom Pistol will use the c_arms animations that TF2 uses.


Here's how it looks in game:


You might've noticed that the Engineer was added to "used_by_classes". Due to the way c_models work, you don't need to set different models for each class for the animations to work properly, which is why the change was made. However, v_models have the animations baked into the models themselves, so how do you get them to change between classes?

The answer lies with the "model_player_per_class" parameter.

By adding this to the first version of the Custom Pistol, you can change the v_model used by each class, allowing you to have the weapon on both Scout and Engineer without making them share animations.

Adding attributes

TEMPTEXT

Changing the model(s) and sounds

TEMPTEXT

Testing the weapon

TEMPTEXT

Advanced weapon creation

Creating custom models, effects and sounds

TEMPTEXT

Making custom attributes

TEMPTEXT

VScript

TEMPTEXT Link to a separate VScript page

See also

Misc info to be added to the finished sections (TEMP!)

  • It should be noted that custom weapons don't currently show up in the loadout on the main menu. To view them, you need to load into a map first.[note]
  • It's a good idea to go over the basic parameters that most weapons should have. Failing to include these can either break the weapon in some way or completely prevent the whole pack from loading.
  • Duplicate name parameters in a single weapon entry will prevent the custom item schema from loading. Same goes for duplicate entry IDs.
  • Duplicating certain parameters, attributes for example, does work, but it's advised not to do this to keep your weapon entries tidy.
  • Prefab info
    • Prefabs work as templates. Load order is important; Prefab at the top means you want to overwrite the prefab, Prefab at the bottom means you want prefab to overwrite you
    • List based parameters (like visuals and static attrs) will get merged. Single value parameters (like bucket or attach to hands) will get overwritten.
    • Prefabs cannot have spaces in the name. This is because spaces are used as a delimiter to apply multiple prefabs. (eg, prefab "prefab1 prefab2" will make the weapon inherit the parameters from both prefab1 and prefab2)
  • item_name, item_type_name, item_description and description_string support localized strings.
  • item_name_color and custom_color allow weapon names and attributes respectively to be coloured with RGB values.
  • custom_level_sounds.txt can be used to create custom soundscripts for weapons. Please correct this if there's a better way of doing this!
  • Localization strings in tf2c_english.txt
  • baseitem sets an item as the default in its slot. Rather finicky, so avoid using.
  • Attribute info
    • Weapon attributes are set in the attributes and rarely static_attrs parameters.
    • Attributes are defined in the attributes section of the schema using a similar system to item entries.
    • Though attributes with custom code aren't possible without VScript (correct this if wrong), variants of existing attributes can be created by making a new attribute with the same attribute class. [note]
    • Quite a few weapon attributes have interesting behavior if set to additive mode

Important note!

Aside from parameter or model/sound/etc names, please don't allow people to directly copy and paste things from here into their schemas. It's important that people actually take the time to understand how the schema works rather than just copying and pasting things and having no clue of what individual bits do.