Ship a KCD2 mod from your server
Stream a KCD2 mod's models, table patches and string patches to every player from a resource, and use the items and recipes it adds.
Since 1.7.2, a server can carry a mod made for the single-player game and send
it to every player who joins. The mod goes in a resource, in two folders:
replace/ for its game files and table patches, and localization/ for its
text. Players download it with the rest of your resources.
resources/better-swords/ package.json replace/ objects/weapons/swords/long_sword_a.mtl libs/tables/item/item__better_swords.xml libs/tables/minigame/blacksmithrecipes__better_swords.xml localization/ english/ text_ui_items__better_swords.xml// server, in a resource that lists better-swords in resourceDependenciesEvents.on("playerSpawned", (player) => { const result = Inventory.add(player, { item: "better_sword_steel", amount: 1 }); if (!result.ok) console.warn(`no sword: ${result.code}`);});Kingdoms Connected no longer loads a player’s own installed mods. The server’s mods are the only ones in a session.
Lay out a mod as a resource
Section titled “Lay out a mod as a resource”A KCD2 mod is a folder with a mod.manifest, its game files in data/*.pak
and its text in localization/<Language>_xml.pak. Each .pak is a zip
archive.
- Create a folder under
resources/with apackage.json. Thenamemust use only lowercase letters, digits,-and_, as for custom assets."mafiahub": {}is enough; the resource needs no scripts. - Extract every
data/*.pakintoreplace/, keeping the paths inside it. - Extract the
<file>__<id>.xmlfiles of each<Language>_xml.pakintolocalization/<language>/, with the language in lowercase:English_xml.pakgoes tolocalization/english/. - Delete everything in What a server refuses. One refused file keeps its whole folder from shipping.
- Run
refresh, thenstart <name>in the server console, or restart the server.
What each folder carries
Section titled “What each folder carries”| Mod content | Goes in |
|---|---|
Models, materials, textures, sounds, .adb |
replace/, at the mod’s paths, as any replaced file |
Table patches, libs/tables/.../<table>__<id>.xml |
replace/, at the mod’s paths |
String patches, <file>__<id>.xml |
localization/<language>/ |
A table can only be patched, never replaced whole. The <id> in a patch’s
name uses lowercase letters, digits and _, as the game’s mod ids do. The
game’s own loaders merge each patch row by row, so a mod can change items,
souls, shops, presets and AI brains as well as plain tables.
A string patch is used for the language the player’s game runs in, with English as the fallback.
Start mod resources together with the server. If you start or change one while players are connected, they get its table changes (items, recipes, shops and the rest) when they reconnect. Text changes show straight away.
What a server refuses
Section titled “What a server refuses”A server never runs a mod’s code and cannot merge what the game reads only at its own start:
| Mod content | Why |
|---|---|
Lua scripts (scripts/) and mod.cfg |
A server never runs Lua or sets console variables |
Quests and Storm rules (libs/storm/) |
The game merges them only when it starts |
| AI trees and UI movies | They are neither asset files nor table patches |
Level edits (modifies_level) |
The game cannot merge them |
Replaced animation clips (.caf) |
The game indexes its own clips at startup; see Custom assets |
Use the mod’s items
Section titled “Use the mod’s items”The item classes a mod adds in libs/tables/item/item__<id>.xml join the
server’s item catalog while the resource runs, and each player’s while they
have its archive. Inventory.add, Inventory.set, player.giveItem and the
rest take them by GUID or by table name, like the game’s own classes, and
Inventory.classes() lists them. See Give and take items.
- Start order. A resource’s classes join once it has started, after its
own scripts and
resourceStarthandlers. A resource that names them while it starts lists the mod inresourceDependencies, so the mod starts first. - Stopping the resource takes its classes out of the server’s catalog.
- Wear and quality follow the same rules as the game’s items. A piece whose clothing component is one of the game’s armor types that never wear (spurs, belts, pouches, horse tack) never changes condition.
- The game’s own classes. A mod row for a class the game ships changes that item in every player’s game, but the server’s catalog keeps the game’s entry for it.
- An
ItemAliasmay name a class from any running resource, or one later in its own file.
Use the mod’s recipes
Section titled “Use the mod’s recipes”Recipe patches, libs/tables/minigame/alchemyrecipe__<id>.xml and
blacksmithrecipes__<id>.xml, join the server’s crafting when the resource
starts and leave when it stops. A row with the id of one of the game’s
recipes replaces that recipe.
Crafting.recipes lists them with source: "mod". See
Custom recipes.
When two resources disagree
Section titled “When two resources disagree”When two resources define the same item GUID or the same recipe id, the one whose name sorts first keeps it, on the server and on every player’s game.
Players’ own mods
Section titled “Players’ own mods”A game started by Kingdoms Connected finds the player’s mods/ folder and
reads mod_order.txt, then turns every mod off before any of it loads: no mod
archive, mod.cfg, Lua script or string patch runs. Nothing in mods/ is
changed. The player’s client log says:
Ignoring local mods: 3 installed, 2 enabledWhen a mod does not show up
Section titled “When a mod does not show up”| Server log | Fix |
|---|---|
'X' replace: <file>: tables can only be patched, as libs/tables/.../<table>__<id>.xml; the lane is not shipped |
Ship only __<id> patches under libs/tables/, never a whole table. |
'X' localization: <file>: localization entries must be <language>/<file>__<id>.xml; ... |
Put each string patch directly in its language folder. |
'X' localization: <file>: a language folder is lowercase letters; ... |
Name the folder after the language only, such as english. |
Resource 'X': <file> keeps its replace lane from shipping (...), so none of its item classes join the catalog |
Fix or delete the file it names. |
Resource 'X': <file>: ...; the server will not craft it |
A recipe row names an item the catalog does not know, or cannot be read. |
A working mod logs Resource 'X': N item class(es) from M table patch(es) join the catalog and Resource 'X': N recipe(s) from its table patches join crafting. The other asset errors are in
Custom assets.
Related
Section titled “Related”- Custom assets: the
stream/andreplace/folders, downloads and limits - Resource manifest and lifecycle:
resourceDependenciesand the console commands - Give and take items: the item catalog
- Custom recipes: recipes from scripts and from mods