Josh64

BombBugs_New

Apr 21st, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 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. -- give the player 5 bombs
  11.  
  12. function BombBugs
  13.  
  14.  
  15. -- getting a bug on a bomb explosion
  16.  
  17. function BombBugs:onExplosion()
  18.  
  19. -- reference player
  20.  
  21. local player = Isaac.GetPlayer(0)
  22. local entities = Isaac.GetRoomEntities()
  23.  
  24. -- detect a bomb explosion
  25.  
  26. if player:HasCollectible(bombBugs) then
  27. for j = 1, #entities do -- we check all entities in the room
  28. if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then -- should be a bomb
  29. if(entities[j]:GetData().Exploded == nil) then -- a fresh bomb
  30. entities[j]:GetData().Exploded = false -- property that the bomb hasn't exploded yet
  31. table.insert(bombs, entities[j]) --insert the found bomb into the aray
  32. end
  33. end
  34. end
  35. for j = 1, #bombs do -- iterate through every bomb
  36. if(bombs[j]:IsDead() and bombs[j]:GetData().Exploded == false) then -- if bomb is dead (has exloded)
  37. bombs[j]:GetData().Exploded = true -- property that the bomb is exploded
  38. local rng = player:GetCollectibleRNG(bombBugs)
  39. local roll = rng:RandomInt(100)
  40. if roll < 90 then
  41. Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player) -- add blue spider if a bomb explodes
  42. else
  43. if hasTick == false then
  44. player:ToPlayer():AddTrinket(TrinktType.TRINKET_TICK)
  45. hasTick = true
  46. end
  47. end
  48. end
  49. end
  50. for j = 1, #entities do
  51. if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then
  52. if(entities[j]:GetData().Exploded == true) then -- the bomb, which is exploded
  53. entities[j]:Remove() --remove the original bomb?
  54. end
  55. end
  56.  
  57. end
  58. end
  59. end
  60.  
  61. BombBugs:AddCallback(ModCallbacks.MC_POST_UPDATE, BombBugs.onExplosion)
Advertisement
Add Comment
Please, Sign In to add comment