====== About Addons ====== Addons are additional s&box content packs loadable in the context of a game. In this tutorial, we'll create an addon for Trouble of Terrorist Town so you can add code that changes the behavior of the game - whether it be custom weapons, custom roles, or something else entirely. ====== If we're making an addon, let's get started! ====== Before creating an addon, you'll need: - **At least some knowledge of C#.** s&box and the game's addons are written in C#. C# tutorials are available at the [[https://learn.microsoft.com/en-us/dotnet/csharp/|MSDN]]. - **A copy of the game redeemed to your Steam account and installed.** - **Your favorite IDE set up.** Full-fat Visual Studio is usually the preference here as it provides the best Intellisense and the most features, but you can also use Visual Studio Code (if you hate yourself) or JetBrains Rider. Instructions on setting up your IDE with s&box are available on the [[https://wiki.facepunch.com/sbox/Coding-Overview|s&box wiki]]. ===== Open the game in tools mode ===== By default, Steam will prompt you to select which mode to launch s&box in when you start the game from your Library. If Steam does not prompt you to start in "Game Editor" mode, follow these steps to enable it again: - Right click s&box in your Steam library, and then click **Properties**. {{ :addon_image0.png?400 |}} - Under **General**, find **Launch Options**, and ensure that the dropdown has **Ask when starting game** selected. {{ :addon_image1.png?400 |}} - Now, you'll be able to click Play as normal and see **Launch Game Editor**. {{ :addon_image2.png?400 |}} ===== Creating your addon ===== Once you have tools mode open and can see the Welcome screen, you can create your first addon. - Click **Content Mode** at the top left of the screen. {{ :addon_image3.png?400 |}} - You'll now see the game's normal menu screen with a bunch of information panels around it. For more information about what these panels are and what they're used for, see [[https://wiki.facepunch.com/sbox/Editor|the s&box wiki]]. For now, we're just interested in creating a new project, so click **File** at the top left and then **New Project...** {{ :addon_image4.png?400 |}} - Select **Addon** at the top left of the top left of the screen that pops up, and fill out the information that is asked for. {{ :addon_image5.png?400 |}} - The **Title** is a user-visible title for your addon. For example, you might want to call this "My Cool Overpowered Gun (TTT)" - The **Ident** is a machine-visible title for your addon. For example, you might want to put "overpowered_gun" here. - The **Location** is where your addon's files will be stored. Where you decide to place your addon is largely up to you. - The **Create .gitignore** option controls whether a file for used with the [[https://git-scm.com/|Git version control system]] is created. The file tells Git which files should not be checked into version control. You probably want to keep this checked, unless you know what you're doing. - Click **Create**. Your new project will show up on the left in the **Projects** pane. In order to your addon work with TTT, we'll need to make a quick change - first, right click the addon in the Projects pane and then click **Project Settings...** - Under the **Project Setup** menu, under the **Target Game** option, click the folder icon, and then click **From asset.party** to pick an addon from asset.party. - Find **Trouble in Terrorist Town! (TTT)** by **Three Thieves** in the menu. You may need to search for it. Then select it and click **OK**. This will select **Trouble in Terrorist Town! (TTT)** as the Target Game. {{ :addon_image6.png?400 |}} - Click **Save** and close the window - your addon is now set up for TTT. Finally, we'll set up a **Launch Configuration** to make loading the game with your addon easy. - Above the game menu, at the top left, you'll see a dropdown next to a Play button, Stop button, and a Menu button. Click it and select **Edit Launch Configurations** to add a launch configuration for your addon. {{ :addon_image7.png?400 |}} - On the left, at the bottom, click **Create New Config**. Then fill out the form as follows: {{ :addon_image8.png?400 |}} - The **Configuration Name** field controls what the configuration is titled in your editor. - The **Game** field controls what game this launch configuration is for. Click the folder icon to the right of the dropdown, then click **From asset.party**. Find **Trouble in Terrorist Town! (TTT)** by **Three Thieves** in the menu. You may need to search for it. Then select it and click **OK**. This will select **Trouble in Terrorist Town! (TTT)** as the Game. - The **Map** field controls what map is loaded when running this launch configuration. Popular maps for debugging include **dev/preview_flat** (local) or **Rooftops** (from asset.party). Use the folder icon to select a map, or keep the default of **Square**. - The **Maximum Players** field controls the number of players that can join games launched with this launch configuration. It is recommended to set this to at least 8, so that bots are allowed to join the game (they consume player slots like real players). - The **Pre Launch Command** allows you to specify concommands to run before launching the game. We can leave this blank for now. - The **Post Launch Command** allows you to specify concommands to run after launching the game. You may want to disable the **automoderator** and **idle spectator timeout** - you can do this by entering ''ttt_idle_timeout 999999; ttt_automoderator 0'' in this field. - The **Addons** field controls which addons are loaded when the game is launched from this configuration - this is the most important part. Click the folder on the right and select your newly-created addon from the list. - Click **Save** and close - now we're ready to launch the game and start coding! Select the launch configuration you just created from the dropdown and then click the **Play** button. The game will load and your addon will be enabled! ====== Writing your addon's code ====== You can open the addon in your preferred code editor by right clicking it in the Projects pane. From there, you'll be able to create C# files and write code as usual. Two things that you might want to do (but anything is possible in theory): * [[custom_weaponry|Add custom weapons to the game]] * [[custom_teams_and_roles|Add custom teams and roles to the game]] When you save your code, s&box will **automagically** compile it and load it in the game. With a few exceptions, your changes will be visible **immediately**. ====== Publishing your addon to asset.party ====== Once you've finished writing and testing your code, you can upload it to asset.party in order to allow players to select it when creating a lobby or dedicated server. - Right click your project in the Project Settings pane, and then click **Project Settings** to open the project settings menu. - Select **Upload To Asset Party** in the menu on the left. - Confirm your ident as created earlier in this guide, and select the organization you want to publish it under. If you haven't already created an organization, do so by selecting the "Create New Organisation" option and restart the game before continuing. {{ :addon_image9.png?400 |}} - Confirm that all of the files that you want to upload show in this screen, then click **Upload Files**. - Provide a change title and optional description, then click **Publish New Revision**. - Congratulations, your addon is now on asset.party! You can click **View and Edit on Web** to view and edit the addon on asset.party.