Skip to content

Using Modifiers

Sanio edited this page Oct 5, 2024 · 10 revisions

With modifiers, you can further adjust sprites based on any conditions of your choosing.


Assigning/Removing Modifiers

Modifiers are great ways to update a Unique Object for any reason you may have, notably if you plan on making multiple different sprites for the same character. The structure for modifiers here is built very similarly to how External Item Descriptions (EID) handles modifiers.

UniqueItemsAPI.AssignObjectModifier(string modifierName, function condition, function callback, UniqueObjectType objectType)

Assigns a modifier to the specified object group. For both functions, they have a single argument params that contain all the same params you may have assigned in AssignUniqueObject in addition to three more:

UniqueObjectParams additions

  • Player EntityPlayer: The player that is being used for the current Unique Object.
  • ModName string: Name of the mod/pack that is being used for the current Unique Object.
  • ObjectEntity Entity The entity being used for the unique sprite. This can be a collectible, knife, familiar, player, or tear (for Spirit Sword)

Function arguments

  • modifierName: Name of your modifier, used as an identifier.
  • condition: Function for containing whatever conditions you wish. Return true in order to activate your callback function.
  • callback: Is called whenever condition returns true. Return the params table when you're finished modifying it.
  • objectType: Follows the UniqueItemsAPI.ObjectType enum.

UniqueItemsAPI.RemoveObjectModifier(string modifierName, UniqueObjectType objectType)

For removing modifiers by name.

  • modifierName: Name of the modifier to remove.
  • objectType: Follows the UniqueItemsAPI.ObjectType enum.

Example

-- The only thing the code checks for is if "true" is returned. Anything else returned will result in the condition failing.
local function IsMyDeleted(itemParams)
    return theDeletedMode ~= nil
        and itemParams.PlayerType == Isaac.GetPlayerTypeByName("Deleted", false)
        and itemParams.ObjectID == CollectibleType.COLLECTIBLE_BIRTHRIGHT
end

local function DeletedBirthrightForms(params)
    params.SpritePath = {string.gsub(params.SpritePath[1], "birthright.png", "birthright_" .. theDeletedMode .. ".png")}
    return itemParams
end

UniqueItemsAPI.AddObjectModifier("THE DELETED Birthright Forms", IsMyDeleted, DeletedBirthrightForms, UniqueItemsAPI.ObjectType.COLLECTIBLE)