Josh64

json test

Dec 22nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. local Mod = RegisterMod("Challenge Only Trinkets", 1)
  2. local game = Game()
  3.  
  4. local GameState = {}
  5. local json = require("json")
  6.  
  7. local Challenges = {
  8. CHALLENGE_ONLY_TRINKETS = Isaac.GetChallengeIdByName("Trinkets Only!")
  9.  
  10. function Mod:onStart()
  11. GameState = json.decode(Mod:LoadData()) -- decodes the data from the savefile (returns a lua table)
  12. if GameState.HeartKill == nil then GameState.HeartKill = 0 end
  13. end
  14. Mod:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, Mod.onStart)
  15.  
  16. function Mod:onHeartKill(entity)
  17. -- Isaac.ConsoleOutput("Heart?")
  18. local data = entity:GetData()
  19. if entity:IsDead() -- is it dead?
  20. and not data.Died then -- did it already die?
  21. data.Died = true -- well now it is dead
  22. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
  23. Isaac.ConsoleOutput("Diiiiie!!")
  24. -- increase the kill counter
  25. GameState.HeartKill = GameState.HeartKill + 1
  26.  
  27. -- reevaluate the custom achievements
  28. reevaluateCustomAchievements = true
  29. end
  30. end
  31. end
  32. Mod:AddCallback(ModCallbacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_MOMS_HEART)
  33.  
  34. function Mod:onExit(save)
  35. Mod:SaveData(json.encode(GameState)) -- encodes the data
  36. end
  37. Mod:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, Mod.onExit)
  38. Mod:AddCallback(ModCallbacks.MC_POST_GAME_END, Mod.onExit)
Advertisement
Add Comment
Please, Sign In to add comment