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

Change weapon and armour stats

Rewrite the attack, defense, requirements and other combat numbers of a weapon, armour or ammunition class for every player, and read back what you changed.

The game keeps combat numbers on the item class, not on each item: every longswordBroad shares one row, which the hit calculation reads on every swing. Inventory.setItemStats rewrites that row on every player’s game, now and for whoever joins later, until the server stops.

// Every broad longsword hits harder, for everyone.
Inventory.setItemStats("longswordBroad", { attack: 120, attackModSlash: 1.5 });
Inventory.getItemStats("longswordBroad"); // { attack: 120, attackModSlash: 1.5 }
Inventory.setItemStats("longswordBroad", null); // the game's own numbers again

item is a class GUID or its exact table name. Which stats a class takes depends on its table element, the groups Item classes lists them under:

Element Stats
MeleeWeapon attack, attackModStab, attackModSlash, attackModSmash, defense, strReq, agiReq
Armor, Helmet, Hood defenseStab, defenseSlash, defenseSmash, noise, strReq
MissileWeapon power, limbResistance, defense, strReq, agiReq
Ammo attackStab, attackSlash, attackSmash, powerMod
  • A change reaches every copy of the class at once and applies from the next hit. Nobody has to re-equip anything.
  • Stats you leave out stay as the game authored them, and each call replaces the class’s previous set whole, so pass everything you want changed. null hands the class its authored numbers back.
  • Values are finite and within 100000 of zero. strReq and agiReq are whole stat levels, rounded, and cannot be negative.
  • Classes that a running resource’s KCD2 mod adds take changes like the game’s own.
  • Nothing is saved. Set your changes in your resource’s startup code.

setItemStats returns true once the numbers are written. Inventory.getItemStats(item) returns your changes by stat name, or null for a class you left alone. It cannot show the authored numbers: the server does not carry the game’s tables.

Cause Example
Unknown class A misspelled name.
The class carries none of these stats Food, a herb, a document.
A name that is not a stat, or one the element lacks noise on a sword.
A value that is not a finite number within 100000 of zero attack: Infinity
A negative requirement strReq: -1
Stats that are neither an object nor null setItemStats("longswordBroad")

Catch it when the class or the numbers come from a player or a config file.

These numbers belong to the class, so one player’s sword cannot differ from another’s. For one body, register a custom buff with weaponAttack, weaponDefense or attackSpeed and put it on them. Swing speed has no column in the item tables, so attackSpeed is the only way to change it.

const frenzy = Buffs.register("arena:frenzy", {
name: "Frenzy",
visual: "potion_marigold_decoction",
duration: 60,
modifiers: {
attackSpeed: { operation: "multiply", value: 1.2 },
weaponAttack: { operation: "multiply", value: 1.25 },
},
});
player.addBuff(frenzy);

Two other class-wide calls sit beside these:

Inventory.setItemName("longswordBroad", "Guild blade"); // every player's game; returns the GUIDs renamed
const price = Inventory.getItemPrice("longswordBroad"); // { pristine, current } or null

setItemName renames every class the game shows under the same name (every kite shield is a Kite Shield), up to 128 bytes, untranslated, until the server stops; null gives the game’s name back. getItemPrice works a unit’s worth out the way the game does, at full and at current health; pass a row’s metadata to price that row.