This UNOFFICIAL documentation provides a comprehensive overview of the TypeScript modding API for the BF6 Portal. It covers the core concepts of the API, the available modules and classes, and how to connect your Godot scene to your TypeScript code.
The TypeScript modding API is an event-driven API that allows you to create custom game modes and logic for your Godot project. All the API functions and types are available under the mod
namespace.
OnPlayerJoinGame
, OnPlayerDied
).mod
Namespace: All API functions, classes, and enums are accessible through the mod
namespace.Here are some of the most commonly used events:
OnGameModeStarted()
: Called when the game mode starts. This is a good place to initialize your game logic.OnGameModeEnding()
: Called when the game mode is about to end. This is a good place to do any cleanup.OnPlayerJoinGame(player: mod.Player)
: Called when a player joins the game.OnPlayerLeaveGame(player: mod.Player)
: Called when a player leaves the game.OnPlayerDeployed(player: mod.Player)
: Called when a player deploys into the game world.OnPlayerDied(player: mod.Player, killer: mod.Player, deathType: mod.DeathType, weaponUnlock: mod.WeaponUnlock)
: Called when a player dies.OnPlayerInteract(player: mod.Player, interactPoint: mod.InteractPoint)
: Called when a player interacts with an InteractPoint
in the scene.Here are some of the most commonly used functions:
mod.GetPlayer(playerId: number): mod.Player
: Returns the player with the specified ID.mod.GetTeam(teamId: number): mod.Team
: Returns the team with the specified ID.mod.GetHQ(objId: number): mod.HQ
: Returns the HQ with the specified ObjId
.mod.GetCapturePoint(objId: number): mod.CapturePoint
: Returns the capture point with the specified ObjId
.mod.GetAreaTrigger(objId: number): mod.AreaTrigger
: Returns the area trigger with the specified ObjId
.mod.DisplayNotificationMessage(message: mod.Message, player?: mod.Player, team?: mod.Team)
: Displays a notification message to the specified player or team.mod.Teleport(player: mod.Player, position: mod.Vector, rotation: number)
: Teleports a player to the specified position and rotation.mod.SpawnObject(objectType: any, position: mod.Vector, rotation: mod.Vector, scale?: mod.Vector): any
: Spawns an object in the world.mod.UnspawnObject(object: any)
: Despawns an object from the world.mod.Wait(seconds: number): Promise<void>
: Pauses the execution of an async
function for the specified number of seconds.The modlib/index.ts
file provides a set of useful helper functions to simplify common tasks.
Concat(s1: string, s2: string): string
: Concatenates two strings.And(...rest: boolean[]): boolean
: Returns true
if all the boolean arguments are true
.getPlayerId(player: mod.Player): number
: A shorthand for mod.GetObjId(player)
.getTeamId(team: mod.Team): number
: A shorthand for mod.GetObjId(team)
.ConvertArray(array: mod.Array): any[]
: Converts a mod.Array
to a standard TypeScript array.FilteredArray(array: mod.Array, cond: (currentElement: any) => boolean): mod.Array
: Filters a mod.Array
based on a condition and returns a new mod.Array
.IfThenElse<T>(condition: boolean, ifTrue: () => T, ifFalse: () => T): T
: Executes one of two functions based on a condition.IsTrueForAll(array: mod.Array, condition: (element: any, arg: any) => boolean, arg: any = null): boolean
: Checks if a condition is true for all elements in a mod.Array
.IsTrueForAny(array: mod.Array, condition: (element: any, arg: any) => boolean, arg: any = null): boolean
: Checks if a condition is true for any element in a mod.Array
.SortedArray(array: any[], compare: (a: any, b: any) => number): any[]
: Sorts a TypeScript array.WaitUntil(delay: number, cond: () => boolean): Promise<void>
: Waits for a condition to become true, checking periodically.ConditionState
)The ConditionState
class helps manage state transitions, ensuring that an action is triggered only once when a condition becomes true.
new ConditionState()
: Creates a new condition state tracker.update(newState: boolean): boolean
: Updates the state and returns true
only on the transition from false
to true
.You can get a specific ConditionState
instance for different game objects:
getPlayerCondition(player: mod.Player, n: number): ConditionState
getTeamCondition(team: mod.Team, n: number): ConditionState
getCapturePointCondition(obj: mod.CapturePoint, n: number): ConditionState
getMCOMCondition(obj: mod.MCOM, n: number): ConditionState
getVehicleCondition(obj: mod.Vehicle, n: number): ConditionState
getGlobalCondition(n: number): ConditionState
The API provides a powerful system for creating and manipulating UI widgets.
mod.UIWidget
: The base class for all UI widgets.mod.AddUIText(...)
: Adds a text widget to the UI.mod.AddUIImage(...)
: Adds an image widget to the UI.mod.AddUIButton(...)
: Adds a button widget to the UI.mod.AddUIContainer(...)
: Adds a container widget to the UI.mod.FindUIWidgetWithName(name: string): mod.UIWidget
: Finds a UI widget by its name.mod.SetUIWidgetVisible(widget: mod.UIWidget, visible: boolean)
: Sets the visibility of a UI widget.OnPlayerUIButtonEvent(player: mod.Player, widget: mod.UIWidget, event: mod.UIButtonEvent)
: Event that is triggered when a player interacts with a UI button.ParseUI
)The ParseUI
function allows you to build complex UI hierarchies from a declarative, JSON-like structure. This is the recommended way to create UIs.
Example:
const myUI = ParseUI({
type: "Container",
name: "my_container",
size: [500, 100],
anchor: mod.UIAnchor.TopCenter,
children: [
{
type: "Text",
name: "my_text",
textLabel: "Hello, World!",
size: [200, 50],
anchor: mod.UIAnchor.Center,
},
],
});
The API provides several functions for displaying messages to players.
ShowEventGameModeMessage(event: mod.Message, target?: mod.Player | mod.Team)
: Displays a large, central game mode message.ShowHighlightedGameModeMessage(event: mod.Message, target?: mod.Player | mod.Team)
: Displays a highlighted message in the world log.ShowNotificationMessage(msg: mod.Message, target?: mod.Player | mod.Team)
: Displays a standard notification message.DisplayCustomNotificationMessage(msg: mod.Message, custom: mod.CustomNotificationSlots, duration: number, target?: mod.Player | mod.Team)
: Displays a notification in a custom slot for a specific duration.ClearCustomNotificationMessage(custom: mod.CustomNotificationSlots, target?: mod.Player | mod.Team)
: Clears a custom notification message.ClearAllCustomNotificationMessages(target: mod.Player)
: Clears all custom notification messages for a player.The connection between the Godot scene and the TypeScript code is established through the ObjId
property.
ObjId
The ObjId
is a unique integer that you can assign to any node in your Godot scene. This ID is then used to reference the node from your TypeScript code.
To assign an ObjId
to a node, simply add an integer property named ObjId
to the node in the Godot editor.
The modding API provides a set of custom Godot nodes that you can use to create your game logic. These nodes are the bridge between the game world and your TypeScript code.
Here are some of the most commonly used game logic objects:
HQ_PlayerSpawner
: A node that defines a headquarter and its spawn points. You can get a reference to this object in your script using mod.GetHQ(objId)
.CapturePoint
: A node that represents a capture point. You can get a reference to this object in your script using mod.GetCapturePoint(objId)
.AreaTrigger
: A node that represents a trigger volume. You can get a reference to this object in your script using mod.GetAreaTrigger(objId)
. The OnPlayerEnterAreaTrigger
and OnPlayerExitAreaTrigger
events are triggered when a player enters or leaves the volume.InteractPoint
: A node that represents a point that players can interact with. The OnPlayerInteract
event is triggered when a player interacts with the point.VehicleSpawner
: A node that spawns vehicles. You can get a reference to this object in your script using mod.GetVehicleSpawner(objId)
.AI_Spawner
: A node that spawns AI soldiers. You can get a reference to this object in your script using mod.GetSpawner(objId)
.ObjId
s: Assign a unique ObjId
to each game logic object that you want to access from your script.mod.Get...
functions to get references to the objects in your scene.Hi! I’m krazyjakee 🎮, creator and maintainÂer of the NodotProject - a suite of open‑source Godot tools (e.g. Nodot, Gedis, GedisQueue etc) that empower game developers to build faster and maintain cleaner code.
I’m looking for sponsors to help sustain and grow the project: more dev time, better docs, more features, and deeper community support. Your support means more stable, polished tools used by indie makers and studios alike.
Every contribution helps maintain and improve this project. And encourage me to make more projects like this!
This is optional support. The tool remains free and open-source regardless.
Created with ❤️ for Godot Developers
For contributions, please open PRs on GitHub