Beginner Modding - RighteousRyan1/TanksRebirth GitHub Wiki
Making Your Own Tank
Making your own tank is also made very simple with the Tanks Rebirth modding API.
To make your own tank, make a new class, and have it extend from ModTank, like so:
From here, we can override given methods, such as when the tank fires, lays a mine, or is spawned.
For any tank, the modder will want to define properties of the tank when it is spawned, so we will override PostApplyDefaults. Your file should look something like this:
From here, we can change the properties of the AI tank via the parameter tank. Here is the code that goes into the overridden method, which creates a tank identical to the Ash tank.
aiParams.MaxAngleRandomTurn = MathHelper.ToRadians(30);
aiParams.RandomTimerMaxMove = 15;
aiParams.RandomTimerMinMove = 10;
aiParams.AwarenessFriendlyMine = 120;
aiParams.AwarenessFriendlyShell = 120;
aiParams.AwarenessHostileMine = 40;
aiParams.AwarenessHostileShell = 40;
aiParams.CantShootWhileFleeing = true;
aiParams.AggressivenessBias = 0.03f;
aiParams.MaxQueuedMovements = 4;
aiParams.ObstacleAwarenessMovement = 30;
aiParams.AimOffset = MathHelper.ToRadians(40);
aiParams.DetectionForgivenessSelf = MathHelper.ToRadians(5);
aiParams.DetectionForgivenessFriendly = MathHelper.ToRadians(20);
aiParams.DetectionForgivenessHostile = MathHelper.ToRadians(20);
aiParams.RandomTimerMaxShoot = 45;
aiParams.RandomTimerMinShoot = 30;
aiParams.TurretSpeed = 0.01f;
aiParams.TurretMovementTimer = 45;
aiParams.TankAwarenessShoot = 70;
aiParams.BaseXP = 0.015f;
// Then, the tank parameters
properties.Acceleration = 0.3f;
properties.Deceleration = 0.6f;
properties.MaxSpeed = 1.2f;
properties.TurningSpeed = 0.08f;
properties.MaximalTurn = MathHelper.ToRadians(10);
properties.ShellLimit = 1;
properties.RicochetCount = 1;
properties.ShellCooldown = 180;
properties.ShellSpeed = 3f;
properties.ShootStun = 10;
properties.ShellType = ShellID.Standard;
properties.Invisible = false;
properties.Stationary = false;
properties.ShellHoming = new();
properties.TreadPitch = 0.085f;
The description for each of these parameters are documented via the XML file given in the projrefs folder. Assuming you're in an IDE, you can hover over the properties and they will have a brief description for each.
Before our tank is finalized and ready to be deployed into combat, we must override the properties Songs, Name, HasSong, and Texture, so that our file now looks like this:
The name of the tank is a LocalizedString, which means you can have a different translation for each of the game's languages.
To assign a name for English, do the following:
If you wish to have more languages, you can do this:
For each translation, you add a comma after the string representing each language, and add another dictionary entry, which follows this format:
[LangCode] = "Localized Name",
[LangCode2] = "Localized Name 2",
/* ... and so forth. */
Songs is for how many 'layers' of songs exist for this tank. For example, the green tank has 4 'layers' of songs. Layer 1 for when a green tank is present with no company, layer 2 for when a green tank has one other tank for company, and so on until 4 tanks are achieved on screen, including at least one green tank. Be sure to have a Music folder within your mod, and read the instructions to the Songs property carefully from within the IDE.
If you don't have music at the moment, the game automatically assumes you don't. HasSong defaults to false, meaning that no music will be played or loaded for your tank upon the loading of the mod.
If you want music to be loaded, change this parameter to true.
public override bool HasSong => true;
The Texture property already loads from your mod's directory, so all you need is a texture file within your mod's source files, and put the relative path to that texture (without the extension), and it will be automatically applied to your tank in-game.
All overridable methods can be used and are explained via your IDE.
Non-essential Overridable Properties
AssociatedColor -> Used to give a color to a tank. Used in the campaign success/failure UI, the "Hit!" color effect when your tank destroys something, etc.
Importing Custom Content
Importing content has been made very simple with the ImportContent<T> method. Be aware that this method does load all raw forms of content, such as fonts, 3D models, and shaders. Font loading will be explained further down this section, then 3D models and shaders.
You can import the following types via ImportAsset<T>: Texture2D, Model, Effect
However, Model and Effect require extra steps.
Texture Import
For importing your textures, .png or .jpg are the best files types to import. you just input a relative file path into the ImportAsset<T> method. For example, if your image file is in your mod's directory, just pass "filename", but if you create a folder for your textures (e.g: textures), you will pass "textures/filename" into the method. - notice the lack of a file extension. The method will find the extension itself.
Sound Import
Sounds can be imported or just directly played through the Tanks Rebirth framework.
To play a sound you want to play, you will have to create a new OggAudio. Tanks Rebirth only supports the OGG Vorbis format, since disk space optimization is always great. In order to import your sound, you must get the path to your mod, via your mod's ModPath property.
OggAudio ExampleAudio = new OggAudio(Path.Combine(ModPath, "example_sound.ogg"));
Folders can be prepended, as always.
To play your sounds, we would just call ExampleAudio.Play();.
Font Import
To import your own fonts into the game, you must follow these steps:
- Initialize your own
FontSystemviaFontStashSharp - Register your font's data to the
FontSystemviaFontSystem.AddFont.- Use
File.ReadAllByteson your font's directory as the parameter forAddFont
- Use
- Declare a
SpriteFontBasefor your font to use for in-game rendering. - Assign
FontSystem.GetFontto your declaredSpriteFontBase.- The parameter for
GetFontis the size of your font.
- The parameter for
- You can render this font by using
TankGame.SpriteRenderer.DrawString
Shader/Model Import
For your own shaders and 3D models- you will need to compile them yourself. To do so, the easiest way is to use SuperAndyHero's EasyXNB. This program compiles your own HLSL .fx files/.fbx model files into Tanks Rebirth's supported shader/model format.
Once you have access to your compiled shader/model, you just input the file path WITHOUT the extension into ImportAsset<T>, using either Effect for shaders and Model for 3D models for the generic parameter, T.