-
Notifications
You must be signed in to change notification settings - Fork 2
Examples
Valentin Lamprière edited this page Nov 29, 2021
·
7 revisions
Here is an example of a full upgraded familiar. This is just an example, the familiar itself is useless (and his upgrades as well).
local CactusMod = RegisterMod("Cactus", 1);
CactusMod.CollectibleID = Isaac.GetItemIdByName("Cactus")
CactusMod.FamiliarVariant = Isaac.GetEntityVariantByName("Cactus")
-- Default cactus behaviour
function CactusMod:CactusUpdate(cactus)
if cactus.FrameCount % 60 == 0 then
Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.PLAYER_CREEP_GREEN, 0, cactus.Position, Vector(0, 0), cactus)
end
end
-- Cactus behaviour when upgraded (super and ultra)
function CactusMod:CactusUpdateUpgraded(cactus)
if cactus.FrameCount % 90 == 0 then
local amountOfTears = 6
if Sewn_API:IsUltra(cactus:GetData()) then
amountOfTears = 10
end
for i = 1, amountOfTears do
local velocity = Vector(6, 6)
velocity = velocity:Rotated((360 / amountOfTears ) * i)
local tear = Isaac.Spawn(EntityType.ENTITY_TEAR, TearVariant.BLOOD, 0, cactus.Position, velocity, cactus)
end
end
end
-- Cactus get out of Sewing Machine
function CactusMod:CactusGetFromMachine(cactus, player, sewingMachine, isUpgraded, newLevel)
if isUpgraded and newLevel == Sewn_API.Enums.FamiliarLevel.ULTRA then
-- Spawn a blue spider when upgraded
Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, cactus.Position, Vector(0, 0), cactus)
end
end
-- On new room for Ultra cactus
function CactusMod:CactusNewRoom(cactus)
local sprite = cactus:GetSprite()
-- Play the dance animation on new room
sprite:Play("Dance", true)
end
-- Standard "familiar update" callback
CactusMod:AddCallback(ModCallbacks.MC_FAMILIAR_UPDATE, CactusMod.CactusUpdate, CactusMod.FamiliarVariant)
if Sewn_API then -- If Sewing Machine is enabled
-- Make the familiar available for Sewing Machine
Sewn_API:MakeFamiliarAvailable(CactusMod.FamiliarVariant, CactusMod.CollectibleID)
-- Add an EID description
Sewn_API:AddFamiliarDescription(
CactusMod.FamiliarVariant,
"Fire tears in all directions every 3 seconds",
"Fire more tears every 3 seconds#Dance when clearing a room"
)
-- Add Encyclopedia support
Sewn_API:AddEncyclopediaUpgrade(
CactusMod.FamiliarVariant,
nil, -- nil to add the default EID description for super upgrade
"Fire 10 tears instead of 6 every 3 seconds#Dance when clearing a room for no reasons",
"This is a test familiar, no mods use it...for now"
)
-- Add more callbacks
-- This isn't required, you can do all the logic in the standard "MC_FAMILIAR_UPDATE" callback
-- This callback will be called for SUPER and ULTRA by default
Sewn_API:AddCallback(Sewn_API.Enums.ModCallbacks.FAMILIAR_UPDATE, CactusMod.CactusUpdateUpgraded, CactusMod.FamiliarVariant)
Sewn_API:AddCallback(Sewn_API.Enums.ModCallbacks.POST_GET_FAMILIAR_FROM_SEWING_MACHINE, CactusMod.CactusGetFromMachine, CactusMod.FamiliarVariant)
-- This callback will be called for ULTRA only
Sewn_API:AddCallback(Sewn_API.Enums.ModCallbacks.POST_FAMILIAR_NEW_ROOM, CactusMod.CactusNewRoom, CactusMod.FamiliarVariant, Sewn_API.Enums.FamiliarLevelFlag.FLAG_ULTRA)
end
For more on how to use the Sewing Machine API, you can see the code in the mod folder.
Every familiars can be found in Sewing machine/sewn_scripts/entities/familiar/upgrades/vanilla
For more info, DM me on Discord : valentinL#3711 You can also join the Discord : https://discord.gg/56HzHdAKKG