Skip to content

Adding Trinkets

AgentCucco edited this page Jan 28, 2021 · 12 revisions

Function syntax.

Encyclopedia.AddTrinket(itemTab)
  • ItemTab: 'table'. A table containing the main arguments for the trinket.

List of arguments in ItemTab:

  • Class: 'string'. The class for your trinket, usually referenced as your mod's name. (optional)
    • Note: On smaller mods, it's recommended to not add this argument, so the trinket gets added to "general mods" instead of occupying a new category in the menu.
  • ID: 'number'. Your trinket's id.
  • WikiDesc: 'table'. Your wiki table for the trinket. (optional)
  • Name: 'string'. The name of your trinket, used in case the name in the xml causes an [ERROR] tag to display in-game. (optional)
  • Desc: 'string'. The description of your trinket, used in case the description in the xml causes an [ERROR] tag to display in-game. (optional)
  • ModName: 'string'. The name of the mod attached to the trinket. (optional)
    • Mod names are already autogenerated, this argument is only used to tweak the names to others.
  • Sprite: 'sprite'. The custom sprite you want to display. (optional)
    • Note that item sprites are autogenerated by the encyclopedia, only use this argument if you want to overwrite the original.
  • Hide: 'boolean': Used in case you want to hide your trinket from the menu. (optional)
    • Trinket will still show up in the Status screen, the tag is primarily used for secret trinkets.
  • UnlockFunc: 'function': Used to display a locked version of the item and a custom name/description. (optional)
    • Used for mods that add unlockable items, like Revelations.
    • Passes (self) as an argument.
    • Note: You need to return a table in this function, if the item is locked.
      • self is a copy of the original table, so you can change it without compromising the original entry.
      • It is recommended to change the description to the unlock condition, for clarity. Name can be changed as well. (Both default to "???")
  • StatusFunc: 'function': Used to display a custom tooltip and change wiki entries on the fly, only during the status menu.
    • Passes (self) as an argument.
    • Runs when the status menu is opened, or the search box is used.
    • Note: You need to return a table in this function.
      • self is a copy of the original table, so you can change it without compromising the original entry.
  • StatusClose: 'function': Used to revert trinkets back to default when the menu is closed.
    • Passes (self) as an argument.
    • Runs when the status menu is closed.

How to add an trinket to the encyclopedia.

You can choose to register your trinket differently depending on how much effort you wanna put into the encyclopedia compatibility.

Just the trinket with no wiki.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")

if Encyclopedia then

Encyclopedia.AddTrinket({ID = FunkyTrinket})

end

The trinket with no wiki, but with a name tweak.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("<Funky Trinket>")

if Encyclopedia then

Encyclopedia.AddTrinket({
  ID = FunkyTrinket,
  Name = "Funky Trinket",
})

end

The trinket with a manual wiki.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")

if Encyclopedia then

local Wiki = {
  Funky = {
    { -- Effect
      {str = "Effect", fsize = 2, clr = 3, halign = 0},
      {str = "Gives you some massive funk boost."},
      {str = "If you get enough funk boost (20), summon Funky Kong."},
      {str = "+1 Funk point when you are funky."},
    },
    { -- Trivia
      {str = "Trivia", fsize = 2, clr = 3, halign = 0},
      {str = "I made this item because I honestly really like funky kong."},
    },
  }
}

Encyclopedia.AddTrinket({
  ID = FunkyTrinket,
  WikiDesc = Wiki.Funky,
})

end

The trinket with an EID wiki.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")

local FunkyDescription = "{{ArrowUp}} Gives you a lot of funk. #If you get enough funk, you will summon Funky Kong."

if EID then

EID:addTrinket(FunkyTrinket, FunkyDescription)

end

if Encyclopedia then

Encyclopedia.AddTrinket({
  ID = FunkyTrinket,
  WikiDesc = Encyclopedia.EIDtoWiki(FunkyDescrption),
})

end

If you have a big mod.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")

local FunkyDescription = "{{ArrowUp}} Gives you a lot of funk. #If you get enough funk, you will summon Funky Kong."

if Encyclopedia then

Encyclopedia.AddTrinket({
  Class = "Funky Kong Pack (25+ Trinkets)",
  ID = FunkyTrinket,
  WikiDesc = Encyclopedia.EIDtoWiki(FunkyDescrption),
})

end

If you have a custom display system.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")

if Encyclopedia then

local ItemConfig = Isaac.GetItemConfig()
local ItemPool = Game():GetItemPool()

Encyclopedia.AddTrinket({
  ID = FunkyTrinket,
  StatusFunc = function(self)
    -- Displays a random item sprite every time the menu is updated.
    local StartSeed = Game():GetSeeds():GetStartSeed()
    local RandomColl = ItemPool:GetCollectible(math.random(1, ItemPoolType.NUM_ITEMPOOLS - 1), false, StartSeed)
    local Item = ItemConfig:GetCollectible(RandomColl)
    
    self.Spr = Encyclopedia.RegisterSprite("gfx/encyclopedia.32x32.anm2", "Idle", nil, Item.GfxFileName)

    return self
  end,
})

end

If you have a custom unlock.

local MyMod = RegisterMod("Super Mod", 1)
local FunkyTrinket = Isaac.GetTrinketIdByName("Funky Trinket")
local FunkyTrinketUnlocked = false

if Encyclopedia then

Encyclopedia.AddTrinket({
  ID = FunkyTrinket,
  UnlockFunc = function(self)
    if not FunkyTrinketUnlocked then
      self.Desc = "Defeat Funky Kong to unlock"
      
      return self
    end
  end,
})

end

Clone this wiki locally