Josh64

BombBugs_FinalVersion?

Apr 24th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. local BombBugs = RegisterMod("BombBugs", 1)
  2. local game = Game()
  3.  
  4. -- reference item, bomb and the Tick
  5.  
  6. local bombBugs = Isaac.GetItemIdByName("Bomb Bugs")
  7. local hasTick = false
  8. local bombs = {} -- empty array of bombs
  9.  
  10.  
  11. -- getting a bug on a bomb explosion
  12.  
  13. function BombBugs:onExplosion()
  14.  
  15. -- reference player
  16.  
  17. local player = Isaac.GetPlayer(0)
  18. local entities = Isaac.GetRoomEntities()
  19.  
  20. -- detect a bomb explosion
  21.  
  22. if player:HasCollectible(bombBugs) then
  23. for j = 1, #entities do -- we check all entities in the room
  24. if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then -- should be a bomb
  25. if(entities[j]:GetData().Exploded == nil) then -- a fresh bomb
  26. entities[j]:GetData().Exploded = false -- property that the bomb hasn't exploded yet
  27. table.insert(bombs, entities[j]) --insert the found bomb into the aray
  28. end
  29. end
  30. end
  31. for j = 1, #bombs do -- iterate through every bomb
  32. if(bombs[j]:IsDead() and bombs[j]:GetData().Exploded == false) then -- if bomb is dead (has exloded)
  33. bombs[j]:GetData().Exploded = true -- property that the bomb is exploded
  34. local rng = player:GetCollectibleRNG(bombBugs)
  35. local roll = rng:RandomInt(100)
  36. if roll < 85 then
  37. Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player) -- add blue spider if a bomb explodes
  38. elseif roll < 95 then
  39. local tick = rng:RandomInt(100)
  40. if tick < 50 then
  41. if hasTick == false then
  42. player:ToPlayer():AddTrinket(TrinktType.TRINKET_TICK)
  43. hasTick = true
  44. else
  45. Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player)
  46. end
  47. else
  48. Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player)
  49. end
  50. else
  51. Isaac.Spawn(EntityType.ENTITY_SPIDER, 2, 1, bombs[j].Position, Vector(0,0), player) -- spawn a red spider at a 5% chance
  52. end
  53. end
  54. end
  55. for j = 1, #entities do
  56. if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then
  57. if(entities[j]:GetData().Exploded == true) then -- the bomb, which is exploded
  58. entities[j]:Remove() --remove the original bomb?
  59. end
  60. end
  61.  
  62. end
  63. end
  64. end
  65.  
  66. BombBugs:AddCallback(ModCallbacks.MC_POST_UPDATE, BombBugs.onExplosion)
Advertisement
Add Comment
Please, Sign In to add comment