Josh64

won

Dec 9th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. local GameState = {}
  2. local json = require("json")
  3.  
  4. local reevaluateCustomAchievements = false
  5.  
  6. function Mod:onStart()
  7. GameState = json.decode(Mod:LoadData()) -- decodes the data from the savefile (returns a lua table)
  8. if GameState.HeartKill == nil then GameState.HeartKill = 0 end
  9. if GameState.SatanKill == nil then GameState.SatanKill = 0 end
  10. if GameState.Trophy == nil then GameState.Trophy = 0 end
  11. end
  12. Mod:AddCallback(ModCallacks.MC_POST_PLAYER_INIT, Mod.onStart)
  13.  
  14. function Mod:onExit(save)
  15. Mod:SaveData(json.encode(GameState))
  16. end
  17. Mod:AddCallback(ModCallacks.MC_PRE_GAME_EXIT, Mod.onExit)
  18. Mod:AddCallback(ModCallacks.MC_POST_GAME_END, Mod.onExit)
  19.  
  20. if Challenge == -- the challenge
  21. or Challenge == -- the other challenge then
  22. if reevaluateCustomAchievements == true then
  23. -- check for current gamestates
  24. -- first the achievements gained through Mom's Heart
  25. if GameState.HeartKill == 1 then
  26. -- spawn the achievement paper
  27. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.FIRST_TRINKET_CHALLENGE_WON, 0, Vector(0,0), Vector(250, 200), player)
  28. -- increase the trophy counter
  29. GameState.Thropy = GameState.Thropy + 1
  30. -- check if the trophy should be spawned
  31. if GameState.Thropy == 2 then -- the 2 challenges have been beaten
  32. -- spawn the achievement paper
  33. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TROPHY_ACHIEVEMENT, 0, Vector(0,0), Vector(250, 200), player)
  34. end
  35. elseif GameState.HeartKill == 5 then
  36. -- spawn the achievement paper
  37. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TRUE_TESTING_DEDICATION, 0, Vector(0,0), Vector(250, 200), player)
  38. end
  39. -- achievement gained through Satan
  40. if GameState.SatanKill == 1 then
  41. -- spawn the achievement paper
  42. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.SECOND_TRINKET_CHALLENGE_WON, 0, Vector(0,0), Vector(250, 200), player)
  43. -- increase the trophy counter
  44. GameState.Thropy = GameState.Thropy + 1
  45. -- check if the trophy should be spawned
  46. if GameState.Thropy == 2 then -- the 2 challenges have been beaten
  47. -- spawn the achievement paper
  48. Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TROPHY_ACHIEVEMENT, 0, Vector(0,0), Vector(250, 200), player)
  49. end
  50. end
  51. reevaluateCustomAchievements = false
  52. end
  53. end
  54. Mod:AddCallback(ModCallacks.MC_POST_PEFFECT_UPDATE, Mod.onUpdate)
  55.  
  56. function Mod:onHeartKill(entity)
  57. local data = entity:GetData()
  58. if entity:IsDead() -- is it dead?
  59. and not data.Died then -- did it already die?
  60. data.Died = true -- well now it is dead
  61. if Challenge == -- the Challenge then
  62. -- increase the kill counter
  63. GameState.HeartKill = GameState.HeartKill + 1
  64.  
  65. -- reevaluate the custom achievements
  66. reevaluateCustomAchievements = true
  67. end
  68. end
  69. end
  70. Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_MOMS_HEART)
  71. Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_IT_LIVES)
  72.  
  73. function Mod:onSatanKill(entity)
  74. local data = entity:GetData()
  75. if entity:IsDead() -- is it dead?
  76. and not data.Died then -- did it already die?
  77. data.Died = true -- well now it is dead
  78. if Challenge == -- the Challenge then
  79. -- increase the kill counter
  80. GameState.SatanKill = GameState.SatanKill + 1
  81.  
  82. -- reevaluate the custom achievements
  83. reevaluateCustomAchievements = true
  84. end
  85. end
  86. end
  87. Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onSatanKill, EntityType.ENTITY_SATAN)
Add Comment
Please, Sign In to add comment