Guest User

revenge WIP

a guest
May 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.08 KB | None | 0 0
  1. local revengemod = RegisterMod("REVENGE! challenge",1.0);
  2. local killed = false
  3. local started = false
  4. local unspawned = true
  5. local continuedrun = false
  6. local playerEntity;
  7. local playerID = -9;
  8. local playerType = -9;
  9. local playerVariant = 0;
  10. local playerSub = 0;
  11. local pos
  12. local vel = Vector(0,0)
  13. local isplayeratdoor = false
  14. local tearvel = Vector(0,0)
  15. local invincibletime = 0
  16.  
  17. debug_text = ""
  18.  
  19. function revengemod:PostPlayerInit(player)
  20.     if Isaac.GetChallenge() == Isaac.GetChallengeIdByName("Revenge!") then
  21.         playerVariant = 0;
  22.         playerSub = 0;
  23.         unspawned = true
  24.         if Game():GetFrameCount() < 2 then
  25.             playerID = -9
  26.             playerType = -9
  27.             killed = false
  28.             started = false
  29.             Isaac.SaveModData(revengemod, playerType)
  30.         end
  31.         playerType = tonumber(Isaac.LoadModData(revengemod))
  32.         if playerType ~= -9 then
  33.             started = true
  34.             killed = true
  35.             unspawned = false
  36.             continuedrun = true
  37.         end
  38.     end
  39. end
  40.  
  41. function revengemod:tick()
  42.     if Isaac.GetChallenge() == Isaac.GetChallengeIdByName("Revenge!") then
  43.         local player = Isaac.GetPlayer(0);
  44.         local currentLevel = Game():GetLevel()
  45.         playerType = tonumber(Isaac.LoadModData(revengemod))
  46.         if playerType ~= -9 then
  47.             killed = true
  48.             if started then
  49.                 if unspawned then
  50.                     unspawned = false
  51.                     player.Position = pos
  52.                     playerEntity = Isaac.Spawn(playerType, playerVariant, playerSub, pos, vel, player);
  53.                     playerEntity:AddCharmed(-1);
  54.                     playerID = playerEntity.Index
  55.                     local maxhealth = playerEntity.MaxHitPoints/3.5
  56.                     maxhealth = math.floor(maxhealth + 0.5)
  57.                     player:AddMaxHearts(-player:GetMaxHearts(), true)
  58.                     player:AddMaxHearts(maxhealth, true)
  59.                     if maxhealth % 2 == 1 then
  60.                         player:AddMaxHearts(1, true)
  61.                     end
  62.                     player:AddHearts(maxhealth)
  63.                     player:AddSoulHearts(-player:GetSoulHearts())
  64.                 end
  65.                 if continuedrun then
  66.                     continuedrun = false
  67.                     local entities = Isaac.GetRoomEntities()
  68.                     for ent = 1, #entities do
  69.                         local entity = entities[ent]
  70.                         if playerType == entity.Type and entity:HasEntityFlags(256) then
  71.                             playerEntity = entity
  72.                             playerID = entity.Index
  73.                             playerVariant = entity.Variant
  74.                             playerSub = entity.SubType
  75.                             break
  76.                         end
  77.                     end
  78.                 end
  79.                 player:SetColor(Color(1,1,1,0,1,1,1),0,0,false,false)
  80.                 playerEntity.TargetPosition = player.Position
  81.                 playerEntity.Position = player.Position
  82.                 playerEntity.MaxHitPoints = 99999
  83.                 playerEntity.HitPoints = 99999
  84.                 player.FireDelay = 9999
  85.                 --player.MaxFireDelay = 99999999
  86.                 if player:GetFireDirection() > -1 then
  87.                     if playerEntity:ToNPC().ProjectileCooldown == 0 then
  88.                         player.FireDelay = 0
  89.                         playerEntity:ToNPC().ProjectileDelay = 0
  90.                         playerEntity:ToNPC().ProjectileCooldown = 5
  91.                     end
  92.                    
  93.                     local entities = Isaac.GetRoomEntities()
  94.                     for ent = 1, #entities do
  95.                         local entity = entities[ent]
  96.                         if entity.Type == 2 and entity:GetLastParent().Index == player.Index and entity.Variant ~= TearVariant.BOBS_HEAD and entity.Variant ~= 21 then
  97.                             tearvel = entity.Velocity
  98.                             entity:Remove()
  99.                             break
  100.                         end
  101.                     end
  102.                     for ent = 1, #entities do
  103.                         local entity = entities[ent]
  104.                         if entity.Type == 9 and entity:GetLastParent().Index == playerEntity.Index then
  105.                             entity.Velocity = tearvel
  106.                         end
  107.                     end
  108.                 else
  109.                     if playerEntity:ToNPC().ProjectileCooldown < 1 then
  110.                         playerEntity:ToNPC().ProjectileCooldown = 1
  111.                     end
  112.                 end
  113.             else
  114.                 checkisplayeratdoor()
  115.                 if isplayeratdoor then
  116.                     started = true
  117.                 end
  118.             end
  119.         end
  120.     end
  121. end
  122.  
  123. function revengemod:NPCtick(entity)
  124.     if Isaac.GetChallenge() == Isaac.GetChallengeIdByName("Revenge!") then
  125.         local player = Isaac.GetPlayer(0);
  126.         playerType = tonumber(Isaac.LoadModData(revengemod))
  127.         if playerType == -9 then
  128.             if killed == false then
  129.                 if entity:IsDead() then
  130.                     if entity:ToNPC():IsBoss() == false and entity:ToNPC():IsChampion() == false then
  131.                         playerType = entity.Type
  132.                         playerVariant = entity.Variant
  133.                         playerSub = entity.SubType
  134.                         pos = entity.Position
  135.                         Isaac.SaveModData(revengemod, playerType)
  136.                         killed = true
  137.                     end
  138.                 end
  139.             end
  140.         end
  141.     end
  142. end
  143.  
  144. function revengemod:takeDamage(target,amount,flag,source,num)
  145.     if Isaac.GetChallenge() == Isaac.GetChallengeIdByName("Revenge!") then
  146.         if started then
  147.             if target.Type == EntityType.ENTITY_PLAYER then
  148.                 if source.Type > 9 and source.Type ~= 33 and flag ~= DamageFlag.DAMAGE_FIRE and flag ~= DamageFlag.DAMAGE_EXPLOSION and flag ~= DamageFlag.DAMAGE_TNT and flag ~= DamageFlag.DAMAGE_SPIKES and flag ~= DamageFlag.DAMAGE_POOP and flag ~= DamageFlag.DAMAGE_ACID and flag ~= DamageFlag.DAMAGE_LASER then
  149.                     return false
  150.                 end
  151.             else
  152.                 local player = Isaac.GetPlayer(0);
  153.                 if source.Type == playerEntity.Type then
  154.                     target:TakeDamage(player.Damage, 0, EntityRef(player), 1)
  155.                     return false
  156.                 end
  157.             end
  158.         end
  159.     end
  160. end
  161.  
  162.  
  163. function checkisplayeratdoor()
  164.     local player = Isaac.GetPlayer(0);
  165.     local currentLevel = Game():GetLevel()
  166.     local currentroom = currentLevel:GetCurrentRoom()
  167.     local distance = 20;
  168.    
  169.     isplayeratdoor = false
  170.     for i = 0, 7 do
  171.         local poscheck = true
  172.         local door = currentroom:GetDoor(i)
  173.         if not door then
  174.             poscheck = false
  175.         end
  176.         if poscheck then
  177.             if door:IsOpen() then
  178.                 local doorpos = door.Position
  179.                 if player.Position.X > doorpos.X - distance and player.Position.X < doorpos.X + distance then
  180.                     if player.Position.Y > doorpos.Y - distance and player.Position.Y < doorpos.Y + distance then
  181.                         isplayeratdoor = true
  182.                         break
  183.                     end
  184.                 end
  185.             end
  186.         end
  187.     end
  188. end
  189.  
  190.  
  191.  
  192.  
  193. function revengemod:debug()
  194.     Isaac.RenderText(debug_text, 50, 50, 0, 255, 0, 255)
  195. end
  196.  
  197.  
  198. revengemod:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, revengemod.PostPlayerInit);
  199. revengemod:AddCallback(ModCallbacks.MC_POST_UPDATE, revengemod.tick);
  200. revengemod:AddCallback(ModCallbacks.MC_NPC_UPDATE, revengemod.NPCtick);
  201. revengemod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, revengemod.takeDamage);
  202. revengemod:AddCallback(ModCallbacks.MC_POST_RENDER, revengemod.debug)
Advertisement
Add Comment
Please, Sign In to add comment