Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Creating custom weapons - basics: Difference between revisions

From TF2 Classified Wiki
mNo edit summary
mNo edit summary
 
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{stub}}
{{stub}}
{{todo|Complete every current section and add new ones if applicable.}}
{{todo|Complete every current section and add new ones if applicable.


Adjust image sizes and potentially add captions.


'''This guide is currently incomplete, but it should suffice if you just need the basics!
Demonstrate using a c_model with attach_to_hands 2 and possibly a v_model with attach_to hands 1.


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].
Adjust the positions of the examples and text to look less messy.
 
If you're going to add information, put it in [[Creating custom weapons#Creating your first weapon|Creating your first weapon]] only if it's '''very''' important to creating weapons, and otherwise put it in [[Creating custom weapons - advanced]]. Do NOT overwhelm beginners!
 
Don't try to fix the wonky indentation in the examples. It's inconsequential and fixing it here will make it look bad in Notepad ++, so it's best to leave it as is. Yeah, I'm annoyed by it too lol}}
 
 
'''This guide is currently incomplete, but it should suffice if you just need the very 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 help you to start out with creating custom weapons. If it doesn't, consider asking for help in the '''#modding-discussion''' channel in the [https://discord.gg/tf2classified official TF2C Discord].


= Creating a custom item schema =
= Creating a custom item schema =
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 [https://developer.valvesoftware.com/wiki/VDF 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.
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 add all of your items into, and is responsible for defining everything about them. It uses [https://developer.valvesoftware.com/wiki/VDF 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.


== custom_items_game.txt ==
== custom_items_game.txt ==
To begin, create a file named {{code|custom_items_game.txt}} in the {{code|<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 {{code|tf2classified\custom\disabled}} to allow the new custom item schema to load.
To begin, create a file named {{code|custom_items_game.txt}} in your {{code|<SteamUserDir>\Team Fortress 2 Classified\tf2classified\custom\<Mod Name>\scripts\items}} directory. This is the file that contains all the information regarding your custom weapons. Please note that you cannot have multiple {{code|custom_items_game.txt}} files loaded simultaneously, so any other mod folders that contain them should be placed in {{code|tf2classified\custom\disabled}} to allow the new custom item schema to load.
 
It should be noted that the {{code|custom_items_game.txt}} method is the simplest and objectively best option for defining custom weapons, as it automatically inherits data from the newest version of the vanilla {{code|items_game.txt}} file. It is possible to override the vanilla item schema with one that contains custom weapons, but this method is not recommended as the overriding file must be manually updated each patch for parity with the vanilla {{code|items_game.txt}} file. For you and your players' sake, use the {{code|custom_items_game.txt}} method ''only''.


== Setting up parameters ==
== Setting up parameters ==
Shown below are the main parameters that should ideally be included in every single item schema. Copy this exactly into your {{code|custom_items_game.txt}} file.
Shown below are the main parameters that should ideally be included in every single item schema. Copy this exactly into your {{code|custom_items_game.txt}} file.


[[File:example_02_emptyschema.png]]
<pre>
#base "items_game.txt"
 
"items_game"
{
"items"
{
}
"prefabs"
{
}
"attributes"
{
}
}
</pre>


=== Explanation ===
=== Explanation ===
{{code|preset=3|base "items_game.txt"}}
{{code|preset=3|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.
: This line is responsible for merging the data from the custom item schema into TF2C's main item schema. Without this, TF2C's items, prefabs and attributes will fail to load.
{{code|preset=3|"items_game"}}
{{code|preset=3|"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.
: The parameter that contains everything unique to the item schema. Whilst not particularly interesting, it's vital for the item schema to run.
Line 33: Line 60:


== The basics ==
== The basics ==
To function, item entries must be placed under the {{code|preset=3|"items"}} parameter, with the exact indentation shown in the upcoming template.
To function, item entries must be placed in the {{code|preset=3|"items"}} parameter.


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


[[File:example_03_bns.png]]
<pre>
"items_game"
{
"items"
{
"<item id>"
{
"name" "<internal name>"
"item_name" "<item name>"
"item_type_name" "<item type name>"
"item_quality" "<item name colour>"
"item_logname" "<dev console name>"
"item_iconname" "<icon name>"
"item_class" "<item class>"
"item_slot" "<backpack slot>"
"anim_slot" "<player model and c_model animations>"
 
"bucket" "<inventory slot override>"
"bucket_position" "<inventory subslot override>"
"model_player" "<view model>"
"model_world" "<world model>"
"image_inventory" "<backpack icon>"
"attach_to_hands" "<view model animation type>"
 
"used_by_classes"
{
"<class>" "<backpack slot>"
}
 
"attributes"
{
"<attribute name>"
{
"attribute_class" "<attribute class>"
"value" "<value>"
}
}
"static_attrs"
{
"<attribute class>" "<value>"
}
"visuals"
{
"<parameter>" "value"
}
 
"mouse_pressed_sound" "<backpack select sound>"
"drop_sound" "<backpack deselect sound>"
}
}
}
</pre>


=== Explanation ===
=== Explanation ===
{{code|"<item id>"}}
{{code|"<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.
: The unique ID used by the weapon. This can be any integer from 0 to 65535. Be careful: if shared with another item entry, the custom item schema will fail to load. Try to use random high values (ideally >= 10000) to prevent clashes with vanilla item entries.
{{code|preset=3|"name"}}
{{code|preset=3|"name"}}
: The unique internal identifier used by the weapon. Like {{code|"<item id>"}}, the custom item schema will fail to load if it's shared with another entry.
: The unique internal identifier used by the weapon. Like {{code|"<item id>"}}, the custom item schema will fail to load if it's shared with another entry.
Line 56: Line 140:
{{code|preset=3|"item_slot"}}
{{code|preset=3|"item_slot"}}
: The loadout slot that the weapon is located in. Below is a list of functional {{code|preset=3|"item_slot"}} values:
: The loadout slot that the weapon is located in. Below is a list of functional {{code|preset=3|"item_slot"}} values:
:: {{code|primary}}
<pre>
:: {{code|secondary}}
primary
:: {{code|melee}}
secondary
:: {{code|pda}}
melee
:: {{code|pda2}}
pda
:: {{code|building}}
pda2
:: {{code|action}} {{note|Not visible in the loadout menu}}
building
:: {{code|utility}} {{note|Not visible in the loadout menu}}
action
utility
</pre>
{{code|preset=3|"anim_slot"}}
{{code|preset=3|"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 {{code|preset=3|"anim_slot"}} values:
: 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 {{code|preset=3|"anim_slot"}} values:
:: {{code|primary}}
<pre>
:: {{code|primary2}}
primary
:: {{code|secondary}}
primary2
:: {{code|secondary2}}
secondary
:: {{code|melee}}
secondary2
:: {{code|melee_allclass}}
melee
:: {{code|pda}}
melee_allclass
:: {{code|pda2}}
pda
:: {{code|building}}
pda2
:: {{code|item1}}
building
:: {{code|item2}}
item1
:: {{code|item3}}
item2
:: {{code|item4}}
item3
:: {{code|passtime_ball}}
item4
:: {{code|force_not_used}}
passtime_ball
force_not_used
</pre>
{{code|preset=3|"model_player"}}
{{code|preset=3|"model_player"}}
: The model used in first person.
: The model used in first person.
Line 103: Line 191:


=== Example ===
=== Example ===
Below is an example item entry for a custom [[Pistol]] with a clip size bonus, a damage penalty and the [[tf:Winger|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 [https://developer.valvesoftware.com/wiki/Half-Life_Model_Viewer%2B%2B HLMV++] and/or [https://developer.valvesoftware.com/wiki/Hammer%2B%2B Hammer ++], or look at item entries in TF2 and TF2C's item schemas.
Below is an example item entry for a custom [[Pistol]] with a clip size bonus, a damage penalty and the [[tf:Winger|Winger]]'s fire sounds. Copy it and give modifying it a go to get a feel for making items. If you're looking for models and soundscripts, try using [https://developer.valvesoftware.com/wiki/Half-Life_Model_Viewer%2B%2B HLMV++] and/or [https://developer.valvesoftware.com/wiki/Hammer%2B%2B Hammer ++], or look at item entries in TF2 and TF2C's item schemas.


[[File:example_04_custompistol.png]]
<pre>
"items_game"
{
"items"
{
"10000" // Custom Pistol
// You can add comments to your item schema with double slashes!
{
"name" "CUSTOM_PISTOL_TEST"
"item_name" "Custom Pistol"
"item_type_name" "#TF_Weapon_Pistol"
"item_logname" "pistol_test"
"item_iconname" "pistol"
"item_class" "tf_weapon_pistol"
"item_slot" "secondary"
"anim_slot" "secondary"
"model_player" "models/weapons/v_models/v_pistol_scout.mdl"
"model_world" "models/weapons/w_models/w_pistol.mdl"
"image_inventory" "backpack/weapons/w_models/w_pistol"
"attach_to_hands" "1"


"used_by_classes"
{
"scout" "1"
}
"attributes"
{
"clip size bonus"
{
"attribute_class" "mult_clipsize"
"value" "2"
}
"damage penalty"
{
"attribute_class" "mult_dmg"
"value" "0.67"
}
}
"static_attrs"
{
"min_viewmodel_offset" "10 0 -10"
}
"visuals"
{
"sound_single_shot" "Weapon_Winger.Single"
"sound_burst" "Weapon_Winger.SingleCrit"
}
"mouse_pressed_sound" "ui/item_light_gun_pickup.wav"
"drop_sound" "ui/item_light_gun_drop.wav"
}
}
}
</pre>


Here's how the description looks in game:
Here's how the description looks in game:
Line 116: Line 262:
As mentioned above, the Custom Pistol has two attributes: a clip size bonus and a damage penalty, which gives it a clip size of 24 and a base damage of 10. It's a bit boring, so how about we spice things up a bit?
As mentioned above, the Custom Pistol has two attributes: a clip size bonus and a damage penalty, which gives it a clip size of 24 and a base damage of 10. It's a bit boring, so how about we spice things up a bit?


[[File:example_07_canheadshot.png]]
<pre>
 
"items_game
{
"items"
{
"<item ID>"
{
<...>
"attributes"
{
"damage bonus"
{
"attribute_class" "mult_dmg"
"value" "1.33"
}
"clip size penalty"
{
"attribute_class" "mult_clipsize"
"value" "0.5"
}
"can headshot"
{
"attribute_class" "can_headshot"
"value" "1"
}
}
<...>
}
}
}
</pre>


Now, the Custom Pistol instead has a damage bonus and a clip size penalty, resulting in 20 base damage and a clip size of 6. More importantly though, the {{code|"can headshot"}} attribute has given it the ability to deal crits on headshot. Pretty cool, eh?
Now, the Custom Pistol instead has a damage bonus and a clip size penalty, resulting in 20 base damage and a clip size of 6. More importantly though, the {{code|"can headshot"}} attribute has given it the ability to deal crits on headshot. Pretty cool, eh?
Line 130: Line 305:
Remember the {{code|preset=3|"attributes"}} parameter explained [[Creating custom weapons#Setting up the custom item schema|here]]? Well, it's time to put it to good use!
Remember the {{code|preset=3|"attributes"}} parameter explained [[Creating custom weapons#Setting up the custom item schema|here]]? Well, it's time to put it to good use!


[[File:example_08_headshotvisible.png]]
<pre>
"items_game"
{
<...>
"attributes"
{
"40000"
{
"name" "can headshot VISIBLE"
"attribute_class" "can_headshot"
"description_format" "value_is_additive"
"stored_as_integer" "1"


"description_string" "#Attrib_RevolverUseHitLocations"
}
}
}
</pre>


In your {{code|preset=3|"attributes"}} parameter (the one with the same indentation as {{code|preset=3|"items"}} and {{code|preset=3|"prefabs"}} - I know, it's confusing), copy the above attribute. This is a copy of the {{code|"can headshot"}} attribute that's been simplified for this tutorial.
In your {{code|preset=3|"attributes"}} parameter (the one with the same indentation as {{code|preset=3|"items"}} and {{code|preset=3|"prefabs"}} - I know, it's confusing), paste the above attribute. This is a copy of the {{code|"can headshot"}} attribute that's been simplified for this tutorial.


The {{code|"description_string"}} parameter is responsible for the stats displayed in an item's description. Here, it's been set to the plaintext "Crits on headshot", which means that it won't be affected by language. Thankfully, in this instance, there's a suitable localised string that can be used instead to ensure that it's understandable to a wider range of people.
The {{code|"description_string"}} parameter is responsible for the stats displayed in an item's description. Here, it's been set to the plaintext "Crits on headshot", which means that it won't be affected by language. Thankfully, in this instance, there's a suitable localised string that can be used instead to ensure that it's understandable to a wider range of people.
Line 148: Line 339:
The first problem is the position of the attribute in the description. In order from top to bottom, item descriptions should always list neutral (white) stats first, then positive (blue) stats, and finally negative (red) stats, with informational text like "This weapon will reload when not active" and "Can be defused by the Wrench" being positioned at the very end.
The first problem is the position of the attribute in the description. In order from top to bottom, item descriptions should always list neutral (white) stats first, then positive (blue) stats, and finally negative (red) stats, with informational text like "This weapon will reload when not active" and "Can be defused by the Wrench" being positioned at the very end.


 
<pre>
'''IMAGE GOES HERE'''
"items_game"
{
"items"
{
"<item ID>"
{
<...>
"attributes"
{
"can headshot VISIBLE"
{
"attribute_class" "can_headshot"
"value" "1"
}
"damage bonus"
{
"attribute_class" "mult_dmg"
"value" "1.33"
}
"clip size penalty"
{
"attribute_class" "mult_clipsize"
"value" "0.5"
}
}
<...>
}
}
}
</pre>


By moving the {{code|"can headshot VISIBLE"}} attribute to the top, it also moves it to the top of the item's description.
By moving the {{code|"can headshot VISIBLE"}} attribute to the top, it also moves it to the top of the item's description.


[[File:example_09_backpack.png]]


'''IMAGE GOES HERE'''


The second problem is the text colour. Crits on headshot is undeniably an upside, so it should be coloured blue to reflect that.
The second problem is the text colour. Crits on headshot is undeniably an upside, so it should be coloured blue to reflect that.


<pre>
"items_game"
{
<...>
"attributes"
{
"40000"
{
"name" "can headshot VISIBLE"
"attribute_class" "can_headshot"
"description_format" "value_is_additive"
"stored_as_integer" "1"
"description_string" "#Attrib_RevolverUseHitLocations"
"effect_type" "positive"
}
}
}
</pre>


'''IMAGE GOES HERE'''
By adding {{code|"effect_type" "positive"}} to the {{code|"can headshot VISIBLE"}} attribute, we can set the colour to the same blue as other positive attributes. If you want an attribute to be displayed as negative, simply replace {{code|"positive"}} with {{code|"negative"}}. The same goes for neutral attributes - replace {{code|"positive"}} with {{code|"neutral"}}.
 
Here's the result:


By adding {{code|"effect_type" "positive"}} to the {{code|"can headshot VISIBLE"}} attribute, we can set the colour to the same blue as other positive attributes. If you want an attribute to be displayed as negative, simply replace {{code|"positive"}} with {{code|"negative"}}. The same goes for neutral attributes - replace {{code|"positive"}} with {{code|"neutral"}}.
[[File:example_10_backpack.png]]


== Models ==
== Models ==
Line 167: Line 408:
What's that? You want to change the model too? Well, with the base selection of models in Classified, 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?
What's that? You want to change the model too? Well, with the base selection of models in Classified, 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?


[[File:example_05_wingermodel.png]]
<pre>
"items_game"
{
"items"
{
"<item ID>"
{
<...>
"item_logname" "pistol_test"
"item_iconname" "winger"


"item_class" "tf_weapon_pistol"
"item_slot" "secondary"
"anim_slot" "secondary"
"model_player" "models/workshop/weapons/c_models/c_winger_pistol/c_winger_pistol.mdl"
"image_inventory" "backpack/workshop/weapons/c_models/c_winger_pistol/c_winger_pistol"
"attach_to_hands" "1"
"used_by_classes"
{
"scout" "1"
"engineer" "1"
}
<...>
}
}
}
</pre>


Here, the parameters have been adjusted for c_model animations. With {{code|preset=3|"attach_to_hands"}} set to 1, the Custom Pistol will use the secondary animations from the class' c_arms - in this case, the Scout's pistol animations. This allows for pistol c_models like the [[tf:Winger|Winger]]'s to be used without visual bugs.
Here, the parameters have been adjusted for c_model animations. With {{code|preset=3|"attach_to_hands"}} set to 1, the Custom Pistol will use the secondary animations from the class' c_arms - in this case, the Scout's pistol animations. This allows for pistol c_models like the [[tf:Winger|Winger]]'s to be used without visual bugs.
Line 182: Line 452:
The answer lies with the {{code|preset=3|"model_player_per_class"}} parameter.
The answer lies with the {{code|preset=3|"model_player_per_class"}} parameter.


[[File:example_06_modelperclass.png]]
<pre>
"items_game"
{
"items"
{
"<item ID>"
{
<...>
"model_player_per_class"
{
"engineer" "models/weapons/v_models/v_pistol_engineer.mdl"
"scout" "models/weapons/v_models/v_pistol_scout.mdl"
}
<...>
}
}
}
</pre>


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.
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.
Line 192: Line 479:
=== Making changes ===
=== Making changes ===
If you make changes to the custom item schema, use the command {{code|cl_reload_item_schema}} to show the changes in game. {{code|sv_reload_item_schema}} can also be used to update the custom item schema for the whole server in multiplayer.
If you make changes to the custom item schema, use the command {{code|cl_reload_item_schema}} to show the changes in game. {{code|sv_reload_item_schema}} can also be used to update the custom item schema for the whole server in multiplayer.
= Advanced weapon creation =
== Prefabs ==
=== Creating prefabs ===
TEMPTEXT
=== Using prefabs ===
TEMPTEXT
== Advanced parameters ==
=== Tags ===
TEMPTEXT
=== Taunts ===
TEMPTEXT
=== Bucket ===
TEMPTEXT
=== List of visual parameters ===
TEMPTEXT
=== Team-specific visuals ===
TEMPTEXT
=== Animation replacements ===
TEMPTEXT
=== Custom text colours ===
TEMPTEXT
== Custom models and effects ==
=== Custom models ===
TEMPTEXT
=== Custom sounds ===
TEMPTEXT
=== Custom particles ===
TEMPTEXT
== VScript ==
VScript allows you to create weapons with completely custom functionality.


= See also =
= See also =
* [[Creating custom weapons - advanced]]
* [[Creating custom weapons - VScript]]
* [[List of TF2C item attributes]]
* [[List of TF2C item attributes]]
* [[List of TF2C item classes]]
* [[List of TF2C item classes]]
* [[List of TF2C weapon assets]]
* [[List of TF2C conditions]]
* [[List of TF2C conditions]]
* [[List of TF2C projectile IDs]]


[[Category:Guides]]
[[Category:Guides]]