Advertisement
KBM-Quine

X2 achievement reset

Nov 28th, 2023 (edited)
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local lunajson = require("ext\\lunajson")
  2.  
  3. local EPISODEPATH = Misc.episodePath():gsub([[[\/]+]], [[/]]);
  4. local SMBXPATH = (Native.getSMBXPath() .. "/"):gsub([[[\/]+]], [[/]]);
  5. local noGoodEpiosodeFolder = (EPISODEPATH == SMBXPATH)
  6.  
  7. local savedata;
  8. local savepath = EPISODEPATH.."progress.json";
  9.  
  10. local function resetAch(index)
  11.     if noGoodEpiosodeFolder then return end
  12.  
  13.     -- reset the achievement in the Achievements class
  14.     local resettie = Achievements.get(index)
  15.     resettie.__CLTD = false -- has to be this. .collected throws an error on editor exit and fails to change.
  16.     resettie.__PSHWN = false -- same for .popupShown
  17.  
  18.     for l,m in pairs(resettie.conditions) do
  19.         if(m.conditiontype == "number") then
  20.             resettie.conditions[l].value = 0;
  21.         else
  22.             resettie.conditions[l].value = false;
  23.         end
  24.     end
  25.  
  26.     -- commit those changes to the file
  27.     savedata = {};
  28.     for k,v in pairs(Achievements.get()) do
  29.         k = tostring(k)
  30.         if(savedata[k] == nil) then
  31.             savedata[k] = {};
  32.         end
  33.  
  34.         savedata[k].c = v.collected;
  35.         savedata[k].s = v.collected and v.popupShown;
  36.         for l,m in pairs(v.conditions) do
  37.             l = tostring(l);
  38.             if(savedata[k][l] == nil) then
  39.                 savedata[k][l] = {};
  40.             end
  41.             if(v.collected) then
  42.                 if(m.conditiontype == "number") then
  43.                     savedata[k][l].v = m.max;
  44.                     savedata[k][l].m = m.max;
  45.                 else
  46.                     savedata[k][l].v = true;
  47.                 end
  48.             else
  49.                 savedata[k][l].v = m.value;
  50.                 if(m.conditiontype == "number") then
  51.                     savedata[k][l].m = m.max;
  52.                 end
  53.             end
  54.         end
  55.     end
  56.     local savefile = io.open(savepath, "w+");
  57.     savefile:write(lunajson.encode(savedata));
  58.     savefile:close();
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement