DefineItem
Makes an item of your own - a named item on one of the game’s, with its own price, weight, condition and look.
Your item is made of one of the game’s items, def.base (the item catalogue): it works the way that item
does - a weapon fights with its stats, armour protects, food is eaten - but it has its own:
nameandtext- what the game shows in the inventory, the item panel, on the ground and in shops (""/ left out = the base’s)weightandprice- kilograms and Groschen per piece (left out = the base’s); the game, the carried weight and the server’s shops and weight checks all use themhealth(0..100) andquality(1..4) - what its pieces are made at when nothing asks for anothermodel- another item whose look and inventory picture its pieces showstack-falsekeeps every piece in a row of its own (by default pieces stack when the base does)
From then on its name is an item like any other: give it with GivePlayerItem (GivePlayerItem(pid, "ironore", 20)), list it
in SetPlayerInventory, a chest (SetContainerItems), a horse’s bags, a body’s loot or a shop (SetShopItem), lay it with
CreatePickup. GetPlayerInventory and every other list name its pieces by it, so a mode that saves what players carry saves
them as they are. Its pieces stack only with each other - never with the plain base item or another of your items - and a removal
by its name (GivePlayerItem with a negative amount) takes only them.
Calling it again with the same name changes the item for every piece of it at once, wherever it is - everything but its base.
Define your items in OnGameModeInit, before anything gives them: a player’s saved items come back as plain base items while their
name is not defined. A name is 1-36 of a-z, 0-9, _, - and ., starting with a letter, and may not be one the game’s catalogue
already knows. At most 4096 items.
Syntax
Section titled “Syntax”DefineItem(name, def)| Parameter | Type | |
|---|---|---|
name |
string | your item’s name - the key every function takes for it |
def |
table | {base =, name =, text =, weight =, price =, health =, quality =, model =, stack =} - only base is needed |
Returns
Section titled “Returns”boolean, string - true, or false and the reason (a bad name, a name the game has, an unknown base, a changed base, a value out of range)
Example
Section titled “Example”function OnGameModeInit() DefineItem("ironore", {base = "bsmt_ironGood", name = "Iron ore", text = "Rock from the Kuttenberg mines.", weight = 2, price = 4}) DefineItem("woodcutter_axe", {base = "axeBattle01", name = "Woodcutter's axe", price = 35, health = 70}) local ok, why = DefineItem("royal_seal", {base = "andelStrazny_riddles", name = "The royal seal", weight = 0.1, price = 500}) if not ok then print("royal_seal: " .. why) endend
-- a mine pays in oreGivePlayerItem(pid, "ironore", 5)See also
Section titled “See also”RemoveItemDefinition · GetItemDefinition · GetItemDefinitions · GivePlayerItem · SetShopItem · GivePlayerTaggedItem · the Items and inventory group of the index
