Advertisement
matrefeytontias

Binding of Isaac AB+ mod : destroyable devil statue

Jan 31st, 2017
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. -- Written by Matrefeytontias
  2. -- This code is free to use in your own mod.
  3. -- The only thing I will ask is that you keep at least those three lines and also credit me in your mod.
  4.  
  5. local statueDeleted = false
  6. local statueReplaced = false
  7.  
  8. function "your mod here":checkDevilRoom()
  9.     local room = Game():GetRoom()
  10.     if room:GetType() == RoomType.ROOM_DEVIL then
  11.         local devilIndex = room:GetGridIndex(room:GetCenterPos()) - room:GetGridWidth()
  12.         -- only works in "normal" devil deals (no tiny room or double statue rooms); intentional but you can change that easily by using Isaac.GetRoomEntities()
  13.         -- and searching for the entity that matches the conditions on line 38
  14.        
  15.         if not statueDeleted then
  16.             -- Remove the statue
  17.             -- First, retrieve the devil statue's entity
  18.             local devilStatue = room:GetGridEntity(devilIndex)
  19.             if devilStatue ~= nil then
  20.                 -- 0 is the devil statue variant ; angel statues can still spawn in the devil deal
  21.                 if devilStatue.Desc.Type == GridEntityType.GRID_STATUE and devilStatue.Desc.Variant == 0 then
  22.                     -- Remove the statue
  23.                     room:RemoveGridEntity(devilIndex, 0, false) -- any idea what the pathtrail argument (0 here) is for ?
  24.                     -- Spawn a rock in its place when the room has processed the statue's deletion, that is, on the next frame
  25.                     statueDeleted = true
  26.                 end
  27.             end
  28.         else
  29.             if not statueReplaced then
  30.                 -- At this point, the statue has been removed and a dummy rock needs to be spawned in its place
  31.                 room:SpawnGridEntity(devilIndex, GridEntityType.GRID_ROCK, 0, room:GetSpawnSeed(), 0)
  32.                 statueReplaced = true
  33.             else
  34.                 -- Check if the rock is still there ; if it's not, it has been destroyed so we also remove the devil statue
  35.                 if room:GetGridCollision(devilIndex) == GridCollisionClass.COLLISION_NONE then
  36.                     local ents = Isaac.GetRoomEntities()
  37.                     for i = 1, #ents do
  38.                         if ents[i].Type == EntityType.ENTITY_EFFECT and ents[i].Variant == EffectVariant.DEVIL then
  39.                             ents[i]:Remove()
  40.                             -- ##################
  41.                             -- do your stuff here, the statue just got destroyed
  42.                             -- ##################
  43.                             break
  44.                         end
  45.                     end
  46.                     statueDeleted = false
  47.                     statueReplaced = false
  48.                 end
  49.             end
  50.         end
  51.     end
  52. end
  53.  
  54. "your mod here":AddCallback(ModCallbacks.MC_POST_UPDATE, "your mod here".checkDevilRoom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement