Josh64

Untitled

Apr 27th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. local BombBugs = RegisterMod("BombBugs", 1)
  2. local game = Game()
  3.  
  4. -- reference item and bomb
  5.  
  6. local bombBugs = Isaac.GetItemIdByName("Bomb Bugs")
  7. local bombs = {} -- empty array of bombs
  8.  
  9.  
  10. -- getting a bug on a bomb explosion
  11.  
  12. function BombBugs:onExplosion()
  13.  
  14. -- reference player
  15.  
  16. local player = Isaac.GetPlayer(0)
  17. local entities = Isaac.GetRoomEntities()
  18.  
  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. if player:GetTrinket(0) ~= TrinketType.TRINKET_TICK
  40. and player:GetTrinket(1) ~= TrinketType.TRINKET_TICK then -- the game tries to give the player a tick
  41. Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_TICK, player.Position, Vector(0,0), player)
  42. -- player:ToPlayer():AddTrinket(TrinketType.TRINKET_TICK)
  43. else
  44. Isaac.Spawn(EntityType.ENTITY_FAMILIAR, FamiliarVariant.BLUE_SPIDER, 0, bombs[j].Position, Vector(0,0), player)
  45. end
  46. else
  47. Isaac.Spawn(EntityType.ENTITY_SPIDER, 2, 1, bombs[j].Position, Vector(0,0), player) -- spawn a red spider at a 5% chance
  48. end
  49. end
  50. end
  51. for j = 1, #entities do
  52. if(entities[j].Type == EntityType.ENTITY_BOMBDROP) then
  53. if(entities[j]:GetData().Exploded == true) then -- the bomb, which is exploded
  54. entities[j]:Remove() --remove the original bomb?
  55. end
  56. end
  57.  
  58. end
  59. end
  60. end
  61.  
  62. BombBugs:AddCallback(ModCallbacks.MC_POST_UPDATE, BombBugs.onExplosion)
Advertisement
Add Comment
Please, Sign In to add comment