S&box Wiki

Revision Difference

Making_Gamemode#543866

<cat>Code.Game</cat> <title>Creating A Gamemode</title> <warning>As the API is prone to changes, this guide might go out of date often - it will be updated often. It is not recommended to use this unless you currently have access to S&box and know what you are doing.</warning> To start creating your gamemode you'll have to set up a few files and folders in the game's `addons` directory, the easiest way to do this is to download the [minimal gamemode](https://github.com/Facepunch/sbox-minimal) and rename it to your liking. S&box loads all files in your addon folder regardless of their location so it shouldn't matter where you put them but it's considered good practice to keep your code in it's own `code` folder and your content in separate folders by type (models, textures, ect.) # Generating your solution Every time you add or remove a project from your addons folder you'll want to run the `GenerateProjects.bat` file that's in there. It'll create/update csproj files for each of your addons and add them to a single solution file so that everything is easily accessible from within Visual Studio. <warning>.NET 5.0 (or 6.0) is required for `GenerateProjects.bat` to work. If running it doesn't seem to be doing anything, run it through command prompt and follow the link that shows up when it errors out.</warning> Once it's done running, open the `Addons.sln` solution in Visual Studio and code away. # Running your gamemode Assuming that everything works as it should you'll be able to launch the game and see your gamemode pop up right there in the menu under installed addons, if it doesn't (or shows the incorrect name) you'll want to check and make sure your .addon file is set up properly. You can use [the official sandbox gamemode](https://github.com/Facepunch/sandbox/blob/master/.addon) as an example. Assuming that everything works as it should you'll be able to launch the game and see your gamemode pop up right there in the menu under installed addons, if it doesn't (or shows the incorrect name) you'll want to check and make sure your .addon file is set up properly. You can use [the official sandbox gamemode](https://github.com/Facepunch/sandbox/blob/master/.addon) as reference.