Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local GameState = {}
- local json = require("json")
- local reevaluateCustomAchievements = false
- function Mod:onStart()
- GameState = json.decode(Mod:LoadData()) -- decodes the data from the savefile (returns a lua table)
- if GameState.HeartKill == nil then GameState.HeartKill = 0 end
- if GameState.SatanKill == nil then GameState.SatanKill = 0 end
- if GameState.Trophy == nil then GameState.Trophy = 0 end
- end
- Mod:AddCallback(ModCallacks.MC_POST_PLAYER_INIT, Mod.onStart)
- function Mod:onExit(save)
- Mod:SaveData(json.encode(GameState))
- end
- Mod:AddCallback(ModCallacks.MC_PRE_GAME_EXIT, Mod.onExit)
- Mod:AddCallback(ModCallacks.MC_POST_GAME_END, Mod.onExit)
- if Challenge == -- the challenge
- or Challenge == -- the other challenge then
- if reevaluateCustomAchievements == true then
- -- check for current gamestates
- -- first the achievements gained through Mom's Heart
- if GameState.HeartKill == 1 then
- -- spawn the achievement paper
- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.FIRST_TRINKET_CHALLENGE_WON, 0, Vector(0,0), Vector(250, 200), player)
- -- increase the trophy counter
- GameState.Thropy = GameState.Thropy + 1
- -- check if the trophy should be spawned
- if GameState.Thropy == 2 then -- the 2 challenges have been beaten
- -- spawn the achievement paper
- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TROPHY_ACHIEVEMENT, 0, Vector(0,0), Vector(250, 200), player)
- end
- elseif GameState.HeartKill == 5 then
- -- spawn the achievement paper
- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TRUE_TESTING_DEDICATION, 0, Vector(0,0), Vector(250, 200), player)
- end
- -- achievement gained through Satan
- if GameState.SatanKill == 1 then
- -- spawn the achievement paper
- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.SECOND_TRINKET_CHALLENGE_WON, 0, Vector(0,0), Vector(250, 200), player)
- -- increase the trophy counter
- GameState.Thropy = GameState.Thropy + 1
- -- check if the trophy should be spawned
- if GameState.Thropy == 2 then -- the 2 challenges have been beaten
- -- spawn the achievement paper
- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.TROPHY_ACHIEVEMENT, 0, Vector(0,0), Vector(250, 200), player)
- end
- end
- reevaluateCustomAchievements = false
- end
- end
- Mod:AddCallback(ModCallacks.MC_POST_PEFFECT_UPDATE, Mod.onUpdate)
- function Mod:onHeartKill(entity)
- local data = entity:GetData()
- if entity:IsDead() -- is it dead?
- and not data.Died then -- did it already die?
- data.Died = true -- well now it is dead
- if Challenge == -- the Challenge then
- -- increase the kill counter
- GameState.HeartKill = GameState.HeartKill + 1
- -- reevaluate the custom achievements
- reevaluateCustomAchievements = true
- end
- end
- end
- Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_MOMS_HEART)
- Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_IT_LIVES)
- function Mod:onSatanKill(entity)
- local data = entity:GetData()
- if entity:IsDead() -- is it dead?
- and not data.Died then -- did it already die?
- data.Died = true -- well now it is dead
- if Challenge == -- the Challenge then
- -- increase the kill counter
- GameState.SatanKill = GameState.SatanKill + 1
- -- reevaluate the custom achievements
- reevaluateCustomAchievements = true
- end
- end
- end
- Mod:AddCallback(ModCallacks.MC_NPC_UPDATE, Mod.onSatanKill, EntityType.ENTITY_SATAN)
Add Comment
Please, Sign In to add comment