Skip to content

ax.util

Source: gamemode/framework/util/util_bots.lua

Utility helpers used across the Parallax framework (printing, file handling, text utilities, etc.).

Section: bot_utilities

Documented functions: 4

Functions


ax.util:CreateBotCharacter(client)

Creates a temporary in-memory character for a bot and loads it immediately.

Selects a random eligible faction via GetRandomBotFaction and a random model via GetRandomFactionModel, then constructs a character metatable instance populated with default variable values. The character is registered in ax.character.instances but is never written to the database — it exists only for the lifetime of the server session.

If the faction defines a GetDefaultName function, that name takes priority over the randomly generated one. A temporary inventory is created via ax.inventory:CreateTemporary if available; otherwise the inventory slot is set to 0 with a warning.

Returns false (with a printed warning) if the bot is invalid, has no eligible faction, or has no available models.

After loading, ax.character:SyncBotToClients is called so connected clients receive the new character's variables.

Realm: server

Parameters

Name Type Description
client Player The bot player to create a character for.

Returns

  • boolean: True on success, false on any failure.

Usage

ax.util:CreateBotCharacter(bot)

ax.util:GenerateBotName()

Generates a random full name for a bot player.

Picks one entry at random from AX_BOT_FIRST_NAMES and one from AX_BOT_LAST_NAMES, then concatenates them with a space.

The name tables are defined as globals at the top of this file and can be extended by other modules before bots are created.

Realm: shared

Returns

  • string: A randomly generated "Firstname Lastname" string.

Usage

local name = ax.util:GenerateBotName() -- e.g. "Jordan Walker"

ax.util:GetRandomBotFaction()

Returns a random faction that bots are allowed to join.

Iterates all registered factions and filters to those where either faction.isDefault is true, or faction.allowBots is not explicitly set to false. Returns nil when no eligible factions exist (e.g. every faction is whitelisted or explicitly bans bots).

Realm: shared

Returns

  • table|nil: A random eligible faction table, or nil if none qualify.

Usage

local faction = ax.util:GetRandomBotFaction()
if ( faction ) then print(faction.name) end

ax.util:GetRandomFactionModel(faction)

Returns a random model from a faction's model list.

Calls faction:GetModels() and picks a random entry. Entries are resolved in this order: if the selected entry is a function it is called and its return value is used; if it is a table whose first element is a string, that string path is used directly. Any other value (plain string or {model, skin} table) is returned as-is.

Returns nil if the faction has no GetModels method or its list is empty.

Realm: shared

Parameters

Name Type Description
faction table The faction table to query.

Returns

  • string|table|nil: A model path string, a {model, skin} table, or nil when no models are available.

Usage

local model = ax.util:GetRandomFactionModel(faction)
local path = istable(model) and model[1] or model