The Inventory object [E/M/W]
It was hard to customize items and such in Unitale, right? Plus, items wouldn't go away when you used them,
because they are the only ones that will ever love you. But now, nobody loves you at all, because items
can be deleted and the Inventory System has been simplified! Here are the functions that are created to
help you with this hellish mechanism that added items.
Note: All of Undertale's consumable items, weapons and armors are already implemented in CYF!
You can use them in your mod if you want to, all you need to do is:
Inventory.AddItem( name, index = 8)
Attempts to add the item name to the player's inventory.
Inventory.RemoveItem( index)
Removes the item in position index from the player's inventory.
index = Index to remove the item from. The first item is position 1.
Inventory.GetItem( index)
Returns the name of the item in the inventory at the given index.
index = Index of the chosen item. The first item is number 1.
Inventory.GetType( index)
Returns the type of the item in the inventory at the given index.
index = Index of the chosen item. The first item is number 1.
Types:
Inventory.SetItem( index, name)
Sets the inventory item at index to the item Name.
index = Index to put the item in. The first item is position 1.
name = Name of the item to put in the inventory.
Inventory.UseItem( index)
Uses the inventory item at index index. Will throw an error if you have no item at the given index, so check if it exists before using this function.
index = Index of the item to use, starting from 1.
Inventory.AddCustomItems( names,
types)
If you want to add custom items, this has to be used before SetInventory.
This adds all items in names to the inventory, where each item matches up with a
type in types. If you don't do this, the engine
will not recognise your newly created items.
Usage: Inventory.AddCustomItems({"item1", "item2"}, {1, 0})
names = The names of your custom items.
types = The item types of your custom items. This array must be same size as names.
Types:
Inventory.SetInventory( names)
Sets the player's inventory. To use custom items, this must be used after AddCustomItems.
This function is used like this: Inventory.SetInventory({"item1", "item2"});
names = The names of the items.
To empty the player's inventory, use Inventory.SetInventory({}).
Inventory.ItemCount
Returns the number of items the player has in their inventory. Read-only.
Inventory.NoDelete
In the encounter function HandleItem only, setting this to true will make the
last used item stay in the inventory.
Inventory.SetAmount( amount)
Used with Weapon and Armor items. If the item is a Weapon, this sets its ATK. If the item is armor,
this sets its DEF.
amount: the amount of ATK/DEF the item will have.
function EncounterStarting()
Inventory.AddCustomItems({"Starfait"}, {0})
Inventory.SetInventory({"Starfait"})
end
function HandleItem(ItemID)
if ItemID == "STARFAIT" then
Player.Heal(14)
BattleDialog({"You eat the Starfait.[w:10]\nYou recovered 14 HP!"})
end
end
function EncounterStarting()
Inventory.AddCustomItems({"Shotgun"}, {1})
Inventory.SetInventory({"Shotgun"})
end
function HandleItem(ItemID)
if ItemID == "SHOTGUN" then
Inventory.SetAmount(16777215)
BattleDialog({"You equipped the Shotgun."})
end
end
function EncounterStarting()
Inventory.AddCustomItems({"Shield"}, {2})
Inventory.SetInventory({"Shield"})
end
function HandleItem(ItemID)
if ItemID == "SHIELD" then
Inventory.SetAmount(8)
BattleDialog({"You equipped the rusty shield."})
end
end
function EncounterStarting()
Inventory.AddCustomItems({"Music Box"}, {3})
Inventory.SetInventory({"Music Box"})
end
function HandleItem(ItemID)
if ItemID == "MUSIC BOX" then
BattleDialog({"[noskip]You wind up the music box.[w:10]\nA haunting melody fills the room.", "The enemy's DEF drops!"})
enemies[1].SetVar("def", enemies[1].GetVar("def") / 2)
end
end
function EncounterStarting()
Inventory.AddCustomItems({"Test"}, {0})
Inventory.SetInventory({"Test"})
end
function HandleItem(ItemID)
if ItemID == "TEST" then
Inventory.NoDelete = true
BattleDialog({"This item won't be\rdeleted!"})
end
end
function EncounterStarting()
Inventory.AddCustomItems({"Test", "Test2", "Shotgun", "Shield", "PsnPotion", "Life Roll", "Nothing"}, {0, 0, 1, 2, 0, 0, 3})
Inventory.SetInventory({"Test", "Test2", "Shotgun", "Shield", "PsnPotion", "Life Roll", "Nothing"})
end
function HandleItem(ItemID)
if (ItemID == "TEST") then
Inventory.NoDelete = true
BattleDialog({"This is a persistent item.[w:5]\nThe item will be in the\rinventory in the next turn!"})
elseif (ItemID == "TEST2") then
BattleDialog({"This is a normal item.[w:10]\nThe item will be gone\rby the next turn!"})
elseif (ItemID == "SHOTGUN") then
Inventory.SetAmount(16777215)
BattleDialog({"You equipped the Shotgun."})
elseif (ItemID == "SHIELD") then
Inventory.SetAmount(30)
AllowPlayerDef(true)
BattleDialog({"You equipped the shield."})
elseif (ItemID == "PSNPOTION") then
BattleDialog({"You drank the Poison Potion.","[noskip][waitall:10]...[waitall:1][w:20]\rThat was a bad idea.[w:20][health:kill]"})
elseif (ItemID == "LIFE ROLL") then
BattleDialog({"Your HP goes to 1[waitall:10]...[waitall:1][health:1,set]now.[w:20]\nNow, byebye![w:20][health:-1, killable]"})
elseif (ItemID == "NOTHING") then
BattleDialog({"You use Nothing. [w:10]Did you really\rthink that something would\rhappen?"})
end
end