Openrct2

From CodeAtCode/oss-ai-skills · View interactive version

Openrct2 is an AI agent skill from the GitHub repository CodeAtCode/oss-ai-skills. Use when developing OpenRCT2 plugins in TypeScript - plugin registration and game actions, window and widget UI, event hooks, park, map, ride and entity access, network API, storage, or ES5 runtime constraints

How to use this skill

Skill file

Objective: Use this skill to reduce desynced multiplayer actions, ES5-transpilation failures, event-hook leak incidents, and game-action rejection bugs by enforcing action-validation discipline, ES5-compatible patterns, and hook-cleanup rules below.

OpenRCT2 Plugin Development

Develop plugins (scripts) for OpenRCT2 using JavaScript/TypeScript to extend the game with custom windows, game actions, event hooks, and multiplayer features.

Overview

OpenRCT2 plugins run in Duktape (ES5 runtime). Key capabilities:

Plugin Directory

Place .js files in the plugin directory:

Access via game: Red toolbox button → Open custom content folder

Plugin Types

Do not mutate game state in local plugins because the server rejects direct mutations in multiplayer. Use game actions instead.

// Local plugin - info windows only
registerPlugin({
    name: 'Local Info Plugin',
    version: '1.0',
    type: 'local',  // Available to all players in multiplayer
    main: function() {
        // Can only use game actions, not direct mutations
        // Good for: info windows, tools, dashboards
    }
});

Remote plugins load only on server and distribute to clients. Mutate game state only in the execute context of custom game actions because that is the only server-side entry point.

// Remote plugin - server-side state mutation
registerPlugin({
    name: 'Remote Game Plugin',
    version: '1.0',
    type: 'remote',  // Server-side, synced to clients
    main: function() {
        // Can mutate game state in custom game action execute()
    }
});

Intransient plugins stay loaded across park changes and in title screen. Use context.sharedStorage for persistence because park storage clears on park load.

// Intransient plugin - persistent across parks
registerPlugin({
    name: 'Global Plugin',
    version: '1.0',
    type: 'intransient',  // Never unloaded
    main: function() {
        // Active in title screen and across parks
        // Use context.sharedStorage for persistence
    }
});

Game Actions

Game actions are the recommended way to mutate game state, ensuring multiplayer synchronization.

Validate Game Action Args Before Execute Because the Server Rejects Invalid Actions and Desyncs Multiplayer

Custom game actions must implement both query (validation) and execute (mutation). The query phase runs client-side to check permissions and args; execute runs server-side to mutate state.

context.registerAction({
    id: 'myplugin.award_cash',
    query: function(args) {
        // Validation - return error object if invalid
        if (args.amount < 0) {
            return { error: 'Amount must be positive' };
        }
        if (args.amount > 100000) {
            return { error: 'Amount too large' };
        }
        // Check permissions in multiplayer
        if (network.mode !== 'none') {
            var player = network.getPlayer(args.playerId);
            if (!player || !player.hasPermission('modify_park')) {
                return { error: 'No permission' };
            }
        }
        return {};  // Success
    },
    execute: function(args) {
        // Actual game state mutation - only runs on server
        park.cash += args.amount;
        return {};  // Success
    }
});

See references/game-actions.md for built-in action type tables and argument schemas.

Best Practices

Check UI Availability Because Headless Servers Lack the UI API

Do check typeof ui !== 'undefined' before using UI APIs because headless servers crash on undefined API access.

Use Game Actions for Mutations Because Direct State Changes Fail in Multiplayer

Do use context.executeAction() for all state mutations because direct property assignments like park.cash = are rejected by the server in multiplayer.

Namespace Your Data Because Unnamespaced Keys Conflict Across Plugins

Do use namespaced keys like MyPlugin.Settings.Enabled instead of Settings.Enabled because multiple plugins writing to the same key will overwrite each other's data.

Handle Errors Because Action Failures Must Be Logged

Do check result.error in every action callback because failed actions silent without error handling make debugging impossible.

Clean Up On Unload Because Event Hooks Leak Memory

Do track all context.setInterval() IDs and call clearInterval() on the plugin.unloaded event because unsubscribed hooks continue running after plugin reload, causing memory leaks and duplicate executions.

ES5 Limitations

OpenRCT2 uses Duktape (ES5). ES6+ features require transpilation. Avoid arrow functions because the ES5 runtime transpilation fails on them.

Not Supported

// Arrow functions - transpilation fails
var func = () => {};

// Classes - transpilation fails
class MyClass {}

// let/const - transpilation fails
let x = 1;

// Template literals - transpilation fails
`Hello ${name}`

// Spread operator - transpilation fails
[...arr]

// Destructuring - transpilation fails
var { x } = obj;

// find/includes - transpilation fails
arr.find(x => x > 0);
arr.includes(5);

ES5 Alternatives

// Function expressions - works
var func = function() {};

// Constructor functions - works
function MyClass() {}

// var - works
var x = 1;

// String concatenation - works
'Hello ' + name

// Array methods - works
arr.filter(function(x) { return x > 0; })[0];
arr.indexOf(5) !== -1;

Distribution

Publishing

  1. GitHub Releases - Recommended, attach compiled .js
  2. openrct2plugins.org - Community plugin repository

Versioning

registerPlugin({
    name: 'My Plugin',
    version: '1.2.3',  // Semantic versioning
    minApiVersion: 34,  // Minimum OpenRCT2 API version
    targetApiVersion: 34,  // Target API for behavior
});

Deep Dives

Load these reference files on demand for detailed API information:

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.