Skip to content
KCKingdoms Connected Scripting APIScripting guides and API
GuideMaintainer authored

Furnish a tavern with World Builder

Place seats, a bed, a dice table and an alchemy table in World Builder, export them to a server and find them again from a script.

You will furnish a tavern corner in World Builder: a dice table, a bench, a bed and an alchemy table. You export it as a world resource, and the server builds it for every player. Players sit, sleep, play dice and brew there the same way they use the level’s own furniture. A short script then finds the pieces by name.

The game calls these interactive pieces smart objects. World Builder lists them in the Library’s interactive folder.

  • Finding seats, beds, the dice table and crafting stations in the Library.
  • Placing, turning and naming them, and taking out the level’s own.
  • Exporting a world resource and loading it from server.json.
  • Finding what the export placed with WorldResource, and placing the same pieces from a script.
server/
server.json
worlds/tavern.world.json exported from World Builder
resources/tavern-furniture/
package.json
tsconfig.json from Use TypeScript
src/server/index.ts lists the furniture by name

In the main menu, choose World Builder, pick the level your server runs, and click New project. The editor opens once the level has loaded.

Press F7 at any time to walk around as your character, and F7 again to return to the editor. Your work stays in the world while you walk.

Open the Library tab. The interactive folder holds every smart object you can place:

Folder What it holds
interactive/seats Benches, chairs and stools.
interactive/beds Beds.
interactive/games The dice table.
interactive/stations Alchemy tables, the smithy, the drying rack and the smokehouse.

You can also type interactive/ into the search box. Search, favorites and Recently placed work for these rows as they do for meshes.

  1. Click the dice table’s row. A see-through copy follows the cursor. It is blue over a surface and red in the air.
  2. Turn it with Shift+mouse wheel or R.
  3. Left-click to put it down. Another copy stays in your hand, so you can place several in a row.
  4. Press Escape to put the copy away.

Do the same for a bench, a bed and the alchemy table. Each piece stands assembled, as players will see it.

Smart objects always keep their own size. Ctrl+mouse wheel, random size and the Placement physics setting do nothing for them.

Click a placed piece to select it. Use the gizmo to move or turn it: 1 moves and 2 rotates.

Then open the Object tab and fill in Name: tavern-dice for the dice table, and tavern-bench, tavern-bed and tavern-alchemy for the others. Names can be up to 64 bytes long. Scripts use the name to find a piece again, because its ID changes every time the server starts. The Object tab does not show Scale or Physics for smart objects, because the server decides both.

Every change is one undo step. Ctrl+Z undoes it and Ctrl+Y redoes it.

5. Take out the level’s own furniture (optional)

Section titled “5. Take out the level’s own furniture (optional)”

To remove one of the level’s own dice tables or crafting stations, click it and press Delete. When the server loads your export, it takes that station out for every player too. The station and the furniture around it can be separate objects in the level. If something is left standing, select it and delete it as well.

To bring it back, open Level > Deleted, find it in the list and click Restore.

Press Ctrl+S, or use Save in the Project tab. This writes a .project.json file that you open again to keep editing. The server cannot load this file; the export makes the one it can.

  1. In the Project tab, set Resource name to tavern.

  2. Click Choose export directory… and pick a folder.

  3. Click Export world resource. This writes tavern.world.json.

  4. Copy the file to your server, for example to worlds/tavern.world.json.

  5. List it in server.json, merged into your existing mod object. Paths are relative to the folder the server runs in.

    server.json
    {
    "mod": {
    "level": "kutnohorsko",
    "world_resources": ["worlds/tavern.world.json"]
    }
    }
  6. Restart the server.

The server checks the file before it finishes starting. A problem stops startup with an error that names the file and the entry, such as Invalid door at doors[0]: ....

Create resources/tavern-furniture, copy the server tsconfig.json from Use TypeScript, and add this manifest:

package.json
{
"name": "tavern-furniture",
"version": "1.0.0",
"scripts": { "build": "tsc -p tsconfig.json" },
"devDependencies": {
"@kingdomsconnected/types": "latest",
"typescript": "^5.9.2"
},
"mafiahub": { "serverScripts": ["dist/server/index.js"] }
}

A server script reads what the export placed through WorldResource. The export loads after scripts start, so wait for it:

src/server/index.ts
const EXPORT = "tavern";
function listTavern(): void {
const tavern = WorldResource.find(EXPORT);
if (!tavern) {
console.log(`Add ${EXPORT}.world.json to mod.world_resources and restart the server.`);
return;
}
for (const piece of tavern.smartObjects) {
console.log(`${piece.name}: ${piece.kind}, station ${piece.stationId || "none"}`);
}
// A placed dice table joins Dice.tables() under its station ID, like one of the level's own.
const dice = tavern.smartObjects.find((piece) => piece.name === "tavern-dice");
const table = dice ? Dice.tables().find((candidate) => candidate.id === dice.stationId) : undefined;
console.log(table ? `tavern-dice is dice table ${table.id}` : "The export has no tavern-dice.");
}
if (WorldResource.ready) listTavern();
else Events.once("worldResourcesReady", listTavern);
  • kind is seat, bed, dice, alchemy, smithing, drying or smoking.
  • stationId is the ID that Dice.tables() and SmartObject.stations() list. Seats and beds have none.
  • The WorldResource.ready check works both when the server starts and when you reload the resource with ensure.

SmartObject.spawn places the same pieces at runtime. It takes a blueprint name such as Table/table_dice, and SmartObject.blueprints() lists them all:

const dice = SmartObject.spawn({
blueprint: "Table/table_dice",
position: [3102.0, 820.5, 57.3],
name: "tavern-dice",
});
console.log(`${dice.blueprint} placed, station ${dice.stationId}`);

A piece a script places belongs to that resource, and disappears when the resource stops. A world resource rebuilds its pieces on every server start.

  1. Join the server and walk to the tavern corner.
  2. Use the game’s own prompt to sit on the bench or sleep in the bed. Other players see you sitting and lying down.
  3. Look at the dice table. In the default gamemode, the Play dice (join lobby) prompt appears within about two seconds of the server starting. On another gamemode, dice depends on that gamemode’s rules.
  4. Use the alchemy table as you would one of the level’s own. The server checks every step, as it does at the level’s tables.
  5. Run npm install and npm run build in tavern-furniture, then ensure tavern-furniture in the server console. It lists the four pieces by name, and the dice table’s station ID.

If nothing appears in the game, check that the path in world_resources is right, that mod.level matches the level you built on, and that you restarted the server after copying the file. If the server stops at startup, read the error: it names the file and the entry that is wrong. If there is no dice prompt, remember that the default gamemode checks for new tables every two seconds and offers a table only to players in the same world as the table.