Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Mod = RegisterMod("Challenge Only Trinkets", 1)
- local game = Game()
- local Challenges = {
- CHALLENGE_ONLY_TRINKETS = Isaac.GetChallengeIdByName("Trinkets Only!")
- }
- local roomContains = {
- Famine = false,
- Pestilence = false,
- Death = false,
- War = false,
- Conquest = false,
- Fallen
- }
- local waitForBeggar = false
- local bumFriendTrinket
- -- trinket pool
- function TrinketPools (item, pool, poolBackwards)
- if pool == nil then
- Isaac.ConsoleOutput("That works")
- end
- -- item = the current item
- -- pool = the current main pool.
- -- poolBackwards = the mirrored version of the current main pool. It is used to check which trinkets the player has
- local maxNum = 0 -- keeps track of the max number of trinkets in the current main table/pool
- local curNum = 0 -- used to count down the places in the current main table/pool
- local player = Isaac.GetPlayer(0)
- local hasEffect = player:GetEffects()
- local roomType = game:GetRoom():GetType()
- -- get maxNum first of the main table/pool
- for a = 1, #pool do
- maxNum = maxNum + 1
- end
- -- now go through very entity in the backwards table
- for b = 1, #poolBackwards do
- -- check if the player has a trinket or a trinket effect from the table
- if player:HasTrinket(poolBackwards[b])
- or hasEffect:HasTrinketEffect(poolBackwards[b]) then
- -- remove it from the main Table
- table.remove(pool, (maxNum - curNum))
- end
- -- increase curNum so that the position to remove gets moved by 1 in the next cycle
- curNum = curNum +1
- end
- -- spawn trinket
- if pool[1] ~= nil then -- the table which got check isn't empty yet
- local rng = player:GetCollectibleRNG(CollectibleType.COLLECTIBLE_SMELTER)
- local pickTrinket = rng:RandomInt(#pool)
- -- morph the item to the picked trinket
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool[pickTrinket], false)
- else
- -- the table is already empty. Spawn the error trinket
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_ERROR, false)
- Isaac.ConsoleOutput("That's an error for you")
- end
- end
- function Mod:OnUpdate(player)
- local roomType = game:GetRoom():GetType()
- -- do possible trophy spawning
- -- check if the player plays the challenge
- if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
- -- give the player moar options
- if game:GetFrameCount() == 1 then
- player:GetEffects():AddCollectibleEffect(414)
- end
- -- go through all room entities
- for _, entities in pairs(Isaac.GetRoomEntities()) do
- if entities.Type == EntityType.ENTITY_SLOT then
- if entities.Variant == 4 then
- -- Isaac.ConsoleOutput("Pay Prize")
- if entities:GetSprite():IsPlaying("Prize") then
- waitForBeggar = true
- Isaac.ConsoleOutput("Pay Prize")
- -- go through all room entites
- for _, entity in pairs(Isaac.GetRoomEntities()) do
- if entity.Type == EntityType.ENTITY_PICKUP
- and entity.Variant == PickupVariant.PICKUP_COLLECTIBLE then -- look for items
- local item = entity
- -- get the beggar trinket "pool"
- local pool = {1,24,49,50,51,52,126} -- mostly the penny trinkets
- local poolBackwards = {126,52,51,50,49,24,1}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- waitForBeggar = false
- end
- end
- end
- end
- elseif entities.Type == EntityType.ENTITY_PICKUP then
- if entities.Variant == PickupVariant.PICKUP_COLLECTIBLE then -- look for items
- local item = entities
- -- check for the SpawnerType (if possible) for stuff like beggars, slots, the player etc.
- if item.SpawnerType == EntityType.ENTITY_SLOT then
- -- check for the spawner variant (to differ between the slots)
- if item.SpawnerVariant == 1 then -- Slot Machine (doesn't work)
- -- get the slot machine trinket "pool"
- local pool = {121} -- while it makes no sense for one trinket [...]
- local poolBackwards = {121} -- [...] it allows to extend the trinket pool more easily
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards) -- gives the item itself and the both pools into the pool function
- elseif item.SpawnerVariant == 2 then -- Blood Donation Machine
- -- get the blood donation machine trinket "pool"
- local pool = {34} -- Child's Heart
- local poolBackwards = {34}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == 3 then -- Fortune Teller
- -- get the fortune teller trinket "pool"
- local pool = {102} -- Fragmented Card
- local poolBackwards = {102}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == 4 then -- normal Beggar
- -- get the beggar trinket "pool"
- local pool = {1,24,49,50,51,52,126} -- mostly the penny trinkets
- local poolBackwards = {126,52,51,50,49,24,1}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == 5 then -- Devil Beggar
- -- get the devil beggar trinket "pool"
- local pool = {61,111} -- Left Hand, Bloody Crown
- local poolBackwards = {111,61}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == 6 then -- Shell Game
- Isaac.ConsoleOutput("Shell Game")
- -- get the shell game trinket "pool"
- local pool = {2,93} -- Petrified Poop, Used Diaper
- local poolBackwards = {93,2}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == 7 then -- Key Master (Key Beggar)
- -- get the key master trinket "pool"
- local pool = {19,36,83,124} -- key related trinkets
- local poolBackwards = {124,83,36,19}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- -- nothing for SpawnerVariant 8
- elseif item.SpawnerVariant == 9 then -- Bomb Beggar
- -- get the bomb beggar trinket "pool"
- local pool = {71} -- Bob's Bladder / bomb related trinkets
- local poolBackwards = {71}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- -- nothing for SpawnerVariant 10
- -- nothing for SpawnerVariant 11
- elseif item.SpawnerVariant == 12 then -- Dressing Table
- -- get the dressing table trinket "pool"
- local pool = {16,17,44}
- local poolBackwards = {44,17,16}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- end
- elseif item.SpawnerType == EntityType.ENTITY_PICKUP then
- if item.SpawnerVariant == PickupVariant.PICKUP_LOCKEDCHEST then -- Golden Chest
- -- get the golden chest trinket "pool"
- local pool = {29,54,57}
- local poolBackwards = {57,54,29}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == PickupVariant.PICKUP_REDCHEST then
- -- get the red chest trinket "pool"
- local pool = {40,43,80,107,128}
- local poolBackwards = {128,107,80,43,40}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif item.SpawnerVariant == PickupVariant.PICKUP_ETERNALCHEST then
- -- get the eternal/holy chest trinket "pool"
- local pool = {7,18,38,85,87,92,100,110,121} -- pool is shared with the angel room
- local poolBackwards = {121,110,100,92,87,85,38,18,7}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- end
- elseif item.SpawnerType == EntityType.ENTITY_PLAYER then
- -- for item spawning trinkets/effects (inlucdes Lunch Bag and Wish Bone)
- -- needs thought tho
- end
- -- Look for spcific items via the CollectibleType
- if (item.SubType == CollectibleType.COLLECTIBLE_LUMP_OF_COAL -- spawned from the Krampus fight
- or item.SubType == CollectibleType.COLLECTIBLE_KRAMPUS_HEAD) then
- -- possible needs room type?
- -- get krampu's trinket pool
- local pool = {35,95}
- local poolBackwards = {95,35}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif (item.SubType == CollectibleType.COLLECTIBLE_CUBE_OF_MEAT -- spawned by the horesman fight
- or item.SubType == CollectibleType.COLLECTIBLE_BALL_OF_BANDAGES
- or item.SubType == CollectibleType.COLLECTIBLE_WHITE_PONY) then -- spawned by Conquest
- -- get room data to see which horseman room it is
- if roomType == RoomType.ROOM_BOSS then -- first check the room type
- -- if roomData.IsFaminesRoom == true then
- if roomContains.Famine == true then
- -- morph the item into a locust. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_FAMINE, false)
- -- elseif roomData.IsPestilencesRoom == true then
- elseif roomContains.Pestilence == true then
- -- morph the item into a locust. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_PESTILENCE, false)
- -- elseif roomData.IsDeathsRoom == true then
- elseif roomContains.Death == true then
- -- morph the item into a locust. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_DEATH, false)
- -- elseif roomData.IsWarsRoom == true then
- elseif roomContains.War == true then
- -- morph the item into a locust. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_WRATH, false)
- -- elseif roomData.IsConquestsRoom == true then
- elseif roomContains.Conquest == true then
- -- morph the item into a locust. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_CONQUEST, false)
- end
- end
- elseif (item.SubType == CollectibleType.COLLECTIBLE_POLARIOD -- spawned from the Krampus fight
- or item.SubType == CollectibleType.COLLECTIBLE_NEGATIVE) then
- -- get mom's "pool"
- local pool = {69} -- Faded Polariod
- -- morph the item to the picked trinket
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
- -- elseif item.SubType == CollectibleType.COLLECTIBLE_SKATOLE then -- shell game
- -- get the shell game trinket "pool"
- -- local pool = {2,93} -- Petrified Poop, Used Diaper
- -- local poolBackwards = {93,2}
- -- trinket pool stuff
- -- TrinketPools(item, pool, poolBackwards)
- elseif item.SubType == CollectibleType.COLLECTIBLE_DOLLAR then -- slot machine
- -- get the slot machine trinket "pool"
- local pool = {121}
- -- morph the item to the picked trinket
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
- elseif item.SubType == CollectibleType.COLLECTIBLE_CRYSTAL_BALL then -- fortune teeler
- -- get the fortune teller trinket "pool"
- local pool = {102} -- Fragmented Card
- -- morph the item to the picked trinket
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
- end
- -- go through the different room types
- if roomType == RoomType.ROOM_TREASURE
- or roomType == RoomType.ROOM_DUNGEON then
- -- get the treasure room pool
- local pool = {5,8,14,16,25,30,31,33,53,54,55,57,60,68,70,71,77,81,86,90,93,95,97,98,99,127}
- local poolBackwards = {127,99,98,97,95,93,90,86,81,77,71,70,68,60,57,55,54,53,33,31,30,25,16,14,8,5}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- if item:GetData().ThereIsOptions == nil then
- item:GetData().ThereIsOptions = true
- end
- elseif roomType == RoomType.ROOM_SHOP
- or roomType == RoomType.ROOM_BLACK_MARKET then
- -- get the shop room pool
- local pool = {3,29,34,36,41,44,59,62,63,72,73,74,76,78,82,89,94,103,106,109,120,125}
- local poolBackwards = {125,120,109,106,103,94,89,82,78,76,74,73,72,63,62,59,44,41,36,34,29,3}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- -- asign data to the entity to make it a shop item later down the line
- item:GetData().ShopTrinket = true
- item:GetData().NeedsNewPrize = true
- elseif roomType == RoomType.ROOM_LIBRARY then
- -- get the library room pool
- local pool = {9,10,11,12,21,23,26,27,45,48,64,65,66,96,102}
- local poolBackwards = {102,96,66,65,64,48,45,27,26,23,21,12,11,10,9}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_BOSS
- or roomType == RoomType.ROOM_MINIBOSS then
- if roomContains.Famine == true then -- the boss room contains the Fallen
- -- get the devil room pool
- local pool = {13,17,20,22,35,80,111,118}
- local poolBackwards = {118,111,80,35,22,20,17,13}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- else
- -- get the boss room pool
- local pool = {37,39,42,46,58,101,104,105,108,119}
- local poolBackwards = {119,108,105,104,101,58,46,42,39,37}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- end
- elseif roomType == RoomType.ROOM_SECRET
- or roomType == RoomType.ROOM_SUPERSECRET then
- -- get the secret room pool
- local pool = {15,28,32,83,84,91}
- local poolBackwards = {91,84,83,32,28,15}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_DEVIL then
- -- get the secret room pool
- local pool = {13,17,20,22,35,80,111,118}
- local poolBackwards = {118,111,80,35,22,20,17,13}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_ANGEL
- or roomType == RoomType.ROOM_SACRIFICE then
- -- get the secret room pool
- local pool = {7,18,38,85,87,92,100,110,121}
- local poolBackwards = {121,110,100,92,87,85,38,18,7}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_CURSE then
- -- get the secret room pool
- local pool = {40,43,61,107,128}
- local poolBackwards = {128,107,61,43,40}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_ISAACS
- or roomType == RoomType.ROOM_BARREN then
- -- get the secret room pool
- local pool = {8,46,54,63,67,99}
- local poolBackwards = {99,67,63,54,46,8}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_CHALLENGE then
- -- get the secret room pool
- local pool = {6,40,58}
- local poolBackwards = {58,40,6}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_ERROR then
- -- get the secret room pool
- local pool = {4,6,67,75,79,92}
- local poolBackwards = {92,79,75,67,6,4}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif roomType == RoomType.ROOM_BOSSRUSH
- or roomType == RoomType.ROOM_DEFAULT then
- if waitForBeggar == false then
- -- morph the item into a random trinket. This will always happen regardless if the player has it or not
- item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_NULL, false)
- end
- end
- elseif entities.Variant == PickupVariant.PICKUP_TRINKET then -- look for trinkets
- local trinket = entities
- local sprite = trinket:GetSprite()
- local data = trinket:GetData()
- -- check for There's Options trinkets
- if roomType == RoomType.ROOM_TREASURE then
- if (player.Position - trinket.Position):Length() < player.Size + trinket.Size then
- -- if sprite:IsPlaying("Collect") -- gets collected
- if data.Picked == nil then -- hasn't been picked up yet
- -- and data.ThereIsOptions == true then -- one of the trinkets where you have a choice
- Isaac.ConsoleOutput("Yeahhh")
- data.Picked = true
- -- look for the other There Is Options trinket
- for _, entitis in pairs(Isaac.GetRoomEntities()) do
- if entitis.Type == EntityType.ENTITY_PICKUP
- and entitis.Variant == PickupVariant.PICKUP_TRINKET
- and entitis:GetData().Picked == nil
- and entitis ~= trinket then -- isn't the trinket which plays the collect animation
- entitis:Remove() -- remove the other trinket
- end
- end
- end
- end
- end
- -- check if the trinket is in the shop
- if roomType == RoomType.ROOM_SHOP then
- local price = 10
- if data.ShopTrinket == true then -- it's a shop trinket
- if data.NeedsNewPrize == true then -- is just spawned
- -- give it a new cost/price
- trinket:ToPickup().Price = price
- data.Price = price
- -- doesn't need a new price anymore
- data.NeedsNewPrize = false
- end
- end
- end
- end
- end
- end
- end
- end
- Mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, Mod.OnUpdate)
- function Mod.onNewRoom(_)
- local player = Isaac.GetPlayer(0)
- local roomType = game:GetRoom():GetType()
- -- check if the player plays the challenge
- if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
- if game:GetRoom().IsFirstVisit == true then
- if roomtype == RoomType.ROOM_TREASURE then
- -- check for items
- for _, entities in pairs(Isaac.GetRoomEntities()) do
- if entities.Type == EntityType.ENTITY_PICKUP then
- if entities.Variant == PickupVariant.PICKUP_COLLECTIBLE then -- it's an item!
- local item = entities
- -- get the treasure room pool
- local pool = {5,8,14,16,25,30,31,33,53,54,55,57,60,68,70,71,77,81,86,90,93,95,97,98,99,127}
- local poolBackwards = {127,99,98,97,95,93,90,86,81,77,71,70,68,60,57,55,54,53,33,31,30,25,16,14,8,5}
- -- trinket pool stuff
- TrinketPools(item, pool, poolBackwards)
- elseif entities.Variant == PickupVariant.PICKUP_TRINKET -- it's a trinket!
- and entities:GetData().ThereIsOptions == nil then
- entities:GetData().ThereIsOptions = true
- end
- end
- end
- elseif roomtype == RoomType.ROOM_BOSS then
- -- look for the boss in the boss room
- for _, entitis in pairs(Isaac.GetRoomEntities()) do
- if entitis.Type == EntityType.ENTITY_FAMINE then
- if roomContains.Famine == false then
- roomContains.Famine = true
- end
- elseif entitis.Type == EntityType.ENTITY_PESTILENCE then
- if roomContains.Pestilence == false then
- roomContains.Pestilence = true
- end
- elseif entitis.Type == EntityType.ENTITY_WAR then
- if entitis.Variant == 1 then -- it's Conquest
- if roomContains.Conquest == false then
- roomContains.Conquest = true
- end
- else -- it's War
- if roomContains.War == false then
- roomContains.War = true
- end
- end
- elseif entitis.Type == EntityType.ENTITY_DEATH then
- if roomContains.Death == false then
- roomContains.Death = true
- end
- elseif entitis.Type == EntityType.ENTITY_FALLEN then
- if roomContains.Fallen == false then
- roomContains.Fallen = true
- end
- else
- -- it is none of them so the variables should be reset to false
- roomContains.Famine = false
- roomContains.Pestilence = false
- roomContains.War = false
- roomContains.Death = false
- roomContains.Conquest = false
- roomContains.Fallen = false
- end
- end
- end
- end
- end
- end
- Mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, Mod.onNewRoom)
Advertisement
Add Comment
Please, Sign In to add comment