Josh64

naruralorder

Dec 29th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. local Mod = RegisterMod"naturalOrder", 1)
  2. local game = Game()
  3.  
  4. local minBugNum = 3
  5.  
  6. function Mod:onUpdate(player)
  7.  
  8. for _, entity in pairs(Isaac.GetRoomEntities()) do
  9. if entity.Type == EntityType.ENTITY_SPIDER then
  10. local spider = entity
  11. for _, entities in pairs(Isaac.GetRoomEntities()) do
  12. if entities.Type == EntityType.ENTITY_EFFECT then
  13. if entities.Variant == EffectVariant.TINY_BUG
  14. or entities.Variant == EffectVariant.TINY_FLY
  15. or entities.Variant == EffectVariant.WORM
  16. or entities.Variant == EffectVariant.BEETLE
  17. or entities.Variant == EffectVariant.WISP
  18. or entities.Variant == EffectVariant.WALL_BUG
  19. or entities.Variant == EffectVariant.BUTTERFLY then
  20. local bug = entities
  21. if (bug.Position - spider.Position):Length() <= bug.Size + spider.Size then
  22.  
  23. -- kill the bug/effect
  24. bug:Die()
  25. bug:Remove()
  26. local tinyBlood = Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.BLOOD_SPLAT, 0, Vector(0,0), bug.Position, bug):ToEffect()
  27. -- make it invisible for a couple of frames
  28. tinyBlood.SpriteScale = Vector(0.1,0.1)
  29. tinyBlood:Update()
  30.  
  31. -- increase the kill count of the spider
  32. local spiderData = spider:GetData()
  33. if spiderData.IncreasedCounter == nil then
  34. if spiderData.EatenBugs == nil then
  35. spiderData.EatenBugs = 0
  36. end
  37. spiderData.EatenBugs = spiderData.EatenBugs + 1
  38. spiderData.IncreasedCounter = true
  39. end
  40. end
  41. end
  42. end
  43. end
  44. end
  45. end
  46. end
  47.  
  48. function Mod:onSpiderUpdate(entity)
  49.  
  50. local spider = entity
  51. local spiderData = spider:GetData()
  52.  
  53. if spiderData.JustGotInitialized == nil then
  54. -- get max number of bugs which are needed for the spider to envolve into a big spider
  55. local spiderRNG = spider:GetDropRNG()
  56. local hungerRoll = (spiderRNG:RandomInt(2)) + minBugNum
  57. if spiderData.NeededBugs == nil then
  58. if hungerRoll == 3 then
  59. spiderData.NeededBugs = 3
  60. elseif hungerRoll == 4 then
  61. spiderData.NeededBugs = 4
  62. elseif hungerRoll == 5 then
  63. spiderData.NeededBugs = 5
  64. end
  65. end
  66. if spiderData.EatenBugs == nil then
  67. spiderData.EatenBugs = 0
  68. end
  69. spiderData.JustGotInitialized = true
  70. end
  71.  
  72. if spiderData.EatenBugs == spiderData.MaxBugNum then
  73. spider:ToNPC():Morph(EntityType.ENTITY_BIG_SPIDER, 1, 0, false)
  74. end
  75. end
Add Comment
Please, Sign In to add comment