Custom Keybinds and Settings - polytrackmods/PolyModLoader GitHub Wiki

PolyModLoader has a few built in functions to make it easier for mod makers to add their own settings and keybinds to the base game.
NOTE: all these calls are positional, meaning the way it looks depends on the order they are called.

Custom Settings

Adding your own settings is fairly easy: First, add your own category

pml.registerSettingCategory("<category name>");

Then, you can register settings in one simple function:

pml.registerSetting("<name>", "<unique id>", SettingType.<type>, <default option>, optionalArgs);
  • Please note you will have to import SettingType from PolyModLoader.js.

Types of settings:

  • BOOL: A simple true/false (on/off) ex: anti aliasing toggle
  • SLIDER: A slider between 0 and 1, do math accordingly for the values you want. ex: sound stuff
  • CUSTOM: a setting with as many options as you want. ex: language setting, render scale For CUSTOM, you are going to need some optional options. Those come in this format:
[ // optionalArgs takes a list of these
    {
        title: "<title here>", // what actually shows on the UI
        value: <value here (stringified)> // the value that your setting has when this option is selected
    { ,
    // add more options at will
]

Accessing your (and the game's) settings

Getting a setting's value, yours or the game's, is a sime as:

pml.getSetting("<unique id>")

I don't really know what it returns, just make sure to parse it properly.
Here are the game's setting IDs

Setting ID Type
ImperialUnitsEnabled Boolean
ResetHintEnabled Boolean
GhostCarEnabled Boolean
DefaultCameraMode Boolean (true is cockpit)
CockpitCameraToggle Boolean (true is toggle)
Checkpoints Custom (string, top/bottom/off)
Timer Same asCheckpoints
Speedometer Same asCheckpoints
Language Custom (string, language codes like en-US)
CarShadowQuality Custom (int, 0/1024/2048/4096)
TrackShadowEnabled Boolean
CloudsEnabled Boolean
ParticlesEnabled Boolean
SkidmarksEnabled Boolean
RenderScale Custom (float, 0.25/0.5/1/1.5/2)
Antialiasing Boolean
SoundEffectVolume Slider
MusicVolume Slider
CheckpointVolume Slider

Custom Keybinds

Custom keybinds are even easier than the custom settings.
Create a category:

pml.registerBindCategory("<category name>");

Adding a keybind:

pml.registerKeybind("<name>", "<unique id>", "<keyboard event (ex: keydown, keyup, etc.)>", "<defaultBind (ex: KeyW, ArrowRight...)>", "<second bind (optional)>", callBackFunc = (event) => {});

The callback doesn't care what state the game is in, you will always receive it. It is your job to determine if the user is in the right context and call event.preventDefault() if needed.

⚠️ **GitHub.com Fallback** ⚠️