Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BombBugs = RegisterMod("BombBugs", 1)
- local game = Game()
- -- reference item, bomb and the Tick
- local bombBugs = Isaac.GetItemIdByName("Bomb Bugs")
- local hasTick = false
- local bombs = {} -- empty array of bombs
- -- getting a bug on a bomb explosion
- function BombBugs:onExplosion()
- -- reference player
- local player = Isaac.GetPlayer(0)
- local entities = Isaac.GetRoomEntities()
- -- detect a bomb explosion
- if player:HasCollectible(bombBugs) then
- for j = 1, #entities do -- we check all entities in the room
- if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then -- should be a bomb
- if(entities[j]:GetData().Exploded == nil) then -- a fresh bomb
- entities[j]:GetData().Exploded = false -- property that the bomb hasn't exploded yet
- table.insert(bombs, entities[j]) --insert the found bomb into the aray
- end
- end
- end
- for j = 1, #bombs do -- iterate through every bomb
- if(bombs[j]:IsDead() and bombs[j]:GetData().Exploded == false) then -- if bomb is dead (has exloded)
- bombs[j]:GetData().Exploded = true -- property that the bomb is exploded
- local rng = player:GetCollectibleRNG(bombBugs)
- local roll = rng:RandomInt(100)
- if roll < 85 then
- Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player) -- add blue spider if a bomb explodes
- elseif roll < 95 then
- local tick = rng:RandomInt(100)
- if tick < 50 then
- if hasTick == false then
- player:ToPlayer():AddTrinket(TrinktType.TRINKET_TICK)
- hasTick = true
- else
- Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player)
- end
- else
- Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player)
- end
- else
- Isaac.Spawn(EntityType.ENTITY_SPIDER, 2, 1, bombs[j].Position, Vector(0,0), player) -- spawn a red spider at a 5% chance
- end
- end
- end
- for j = 1, #entities do
- if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then
- if(entities[j]:GetData().Exploded == true) then -- the bomb, which is exploded
- entities[j]:Remove() --remove the original bomb?
- end
- end
- end
- end
- end
- BombBugs:AddCallback(ModCallbacks.MC_POST_UPDATE, BombBugs.onExplosion)
Advertisement
Add Comment
Please, Sign In to add comment