Advertisement
Guest User

Untitled

a guest
Nov 19th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.64 KB | None | 0 0
  1. --**********
  2. --|INCLUDES|
  3. --**********
  4. world_raocoin_lib = loadSharedAPI("raocoin2");
  5. world_raocoin_currency = world_raocoin_lib.registerCurrency(274, true, 480, 66);
  6. local eventu = loadAPI("eventu");
  7. local encrypt = loadSharedAPI("encrypt");
  8. local multipoints = loadSharedAPI("multipoints");
  9. local pnpc = loadSharedAPI("pnpc");
  10.  
  11. --******
  12. --|VARS|
  13. --******
  14. local levelFinished = false;
  15. ShowInputs = false
  16. musichudfile = Misc.resolveFile("musichud.png");
  17. local demosgraphic= Graphics.loadImage(Misc.resolveFile("demos.png"));
  18. local musichud = Graphics.loadImage(Misc.resolveFile("musichud.png"));
  19. local localraocoin = Graphics.loadImage(Misc.resolveFile("raocoin.png"));
  20. local raocoin_taken = Graphics.loadImage(Misc.resolveFile("raocoin_taken.png"));
  21. showmusic = false
  22. musicwait = false
  23. local hasDied = false;
  24. local local_raocoin_counter = 0;
  25.  
  26.  
  27. --***************
  28. --|SAVE SETTINGS|
  29. --***************
  30. Settings = encrypt.Data(Data.DATA_WORLD, "ConfigData", true)
  31. TextSettings = Data(Data.DATA_WORLD, "TextConfigData", true)
  32.  
  33.  
  34. if Settings:get("DemoCounter") == nil then
  35.     Settings:set("ShowInputsConfig", 0)
  36.     Settings:set("MusicComboConfig", 0)
  37.     Settings:set("DemoCounter", 1)
  38.     Settings:set("Raocoin1", 0)
  39.     Settings:set("Raocoin2", 0)
  40.     Settings:set("Raocoin3", 0)
  41.     Settings:set("Raocoin4", 0)
  42.     Settings:set("Raocoin5", 0)
  43.     Settings:save()
  44. end
  45.  
  46. if TextSettings:get("CurrentLevel") == "" then
  47.     TextSettings:set("CurrentLevel","none");
  48.     TextSettings:save();
  49. end
  50.  
  51. local raocoinnpcs = {};
  52. local raocoin_empty = {};
  53.  
  54. local ranInitialCheck = false;
  55. local midpointLoaded = false;
  56. InputConfig = Settings:get("ShowInputsConfig");
  57. MusicCombo = Settings:get("MusicComboConfig");
  58. UseDemos = Settings:get("DemoCounter");
  59.  
  60. function world_raocoin_currency:onCollect(increment, npc)
  61.     local_raocoin_counter = local_raocoin_counter + increment;
  62.     table.insert(raocoin_empty, {x=npc.x, y=npc.y});
  63.     local n = pnpc.wrap(npc);
  64.     n.data.collected = true;
  65. end
  66.  
  67. --*************************
  68. --|SAVE COLLECTED RAOCOINS|
  69. --*************************
  70. function multipoints:onCollected(id)
  71.       world_raocoin_currency:save();
  72.      
  73.       TextSettings:set("CurrentLevel", tostring(mem(0x00B250B0, FIELD_STRING)));
  74.       for k,v in ipairs(raocoinnpcs) do
  75.         if(not v.isValid and v.data.collected == true) then
  76.             Settings:set("Raocoin"..k, 1);
  77.         end
  78.       end
  79.     Settings:save()
  80.     TextSettings:save();
  81. end
  82.  
  83. function onNPCKill(event, npc, reason)
  84.     if(midpointLoaded and npc.id == 192) then
  85.         multipoints.onCollected(npc,0);
  86.     end
  87. end
  88.  
  89. function multipoints.onLevelStart()
  90.     midpointLoaded = true;
  91. end
  92.  
  93. function onEvent(eventname)
  94.     if eventname == "ShowInputsConfig" then
  95.         if InputConfig == 0 then
  96.            Settings:set("ShowInputsConfig", 1)
  97.         else
  98.            Settings:set("ShowInputsConfig", 0)
  99.         end
  100.         Settings:save()
  101.         InputConfig = Settings:get("ShowInputsConfig");
  102.     end
  103.  
  104.     if eventname == "MusicComboConfig" then
  105.         if MusicCombo == 0 then
  106.            Settings:set("MusicComboConfig", 1)
  107.         else
  108.            Settings:set("MusicComboConfig", 0)
  109.            Misc.cheatBuffer("")
  110.         end
  111.         Settings:save()
  112.         MusicCombo = Settings:get("MusicComboConfig");
  113.     end
  114.  
  115.     if eventname == "DemoCounter" then
  116.         if UseDemos == 0 then
  117.            Settings:set("DemoCounter", 1)
  118.         else
  119.            Settings:set("DemoCounter", 0)
  120.         end
  121.         Settings:save()
  122.         UseDemos = Settings:get("DemoCounter");
  123.     end
  124.  
  125. end
  126.  
  127. function onLoop()
  128.  
  129.  
  130.  
  131. --**************
  132. --|RAOCOIN CODE|
  133. --**************
  134.     if(mem(0x00B2C59E,FIELD_WORD) ~= 0 and not levelFinished) then --level is ending
  135.       levelFinished = true;
  136.       world_raocoin_currency:save();
  137.    end
  138. musicCode() --Music Code
  139.  
  140. --*******************
  141. --|FILE-SAVING STUFF|
  142. --*******************
  143.     if ranInitialCheck == false then
  144.         if ShowInputsConfig == tostring(1) then
  145.            -- ShowInputs = true
  146.         end
  147.         if MusicComboConfig == tostring(1) then
  148.             --MusicCombo = true
  149.         end
  150.        
  151.         --**************************************
  152.         --|DELETE PREVIOUSLY COLLECTED RAOCOINS|
  153.         --**************************************
  154.         if(tostring(mem(0x00B250B0, FIELD_STRING)) ~= TextSettings:get("CurrentLevel")) then
  155.             Settings:set("Raocoin1", 0)
  156.             Settings:set("Raocoin2", 0)
  157.             Settings:set("Raocoin3", 0)
  158.             Settings:set("Raocoin4", 0)
  159.             Settings:set("Raocoin5", 0)
  160.             Settings:save();
  161.             TextSettings:set("CurrentLevel", "none")
  162.             TextSettings:save();
  163.         end
  164.        
  165.         for k,v in ipairs(NPC.get(274,-1)) do
  166.             raocoinnpcs[k] = pnpc.wrap(v);
  167.             if(Settings:get("Raocoin"..k) == 1) then
  168.                 v:mem(0x3C,FIELD_STRING,""); --Remove from layer (allows hidden raocoins to not be displayed) - work around for kill() not working on hidden NPCs
  169.                 local_raocoin_counter = local_raocoin_counter + 1;
  170.                 table.insert(raocoin_empty, {x=v.x, y=v.y});
  171.                 v:kill();
  172.             end
  173.         end
  174.        
  175.         if #raocoinnpcs < 5 then --Search container NPCs such as grass, bubbles and yoshis.
  176.             for k,v in ipairs(NPC.get({283,91,263,96},-1)) do
  177.                 if v:mem(0xF0,FIELD_DFLOAT) == 274 then
  178.                     table.insert(raocoinnpcs, pnpc.wrap(v));
  179.                     if(Settings:get("Raocoin"..#raocoinnpcs) == 1) then
  180.                         local_raocoin_counter = local_raocoin_counter + 1;
  181.                        
  182.                         local yoffset = 0;
  183.                         if(v.id == 91) then
  184.                             yoffset = -64;
  185.                         elseif(v.id == 96) then
  186.                             yoffset = -32;
  187.                         end
  188.                        
  189.                        
  190.                         table.insert(raocoin_empty, {x=v.x, y=v.y+yoffset});
  191.                         v:mem(0xF0,FIELD_DFLOAT,0)
  192.                     end
  193.                 end
  194.             end
  195.         end
  196.        
  197.     ranInitialCheck = true;
  198.     end
  199.    
  200.     for k,v in ipairs(raocoin_empty) do
  201.         Graphics.drawImageToScene(raocoin_taken,v.x,v.y)
  202.     end
  203.    
  204. end
  205.  
  206. function onInputUpdate()
  207.         --*****************************
  208.         --|START + SELECT BUTTON COMBO|
  209.         --*****************************
  210.         if (player.dropItemKeyPressing and player.pauseKeyPressing) then
  211.                 Level.exit()
  212.                 --mem(0x00B250E2,FIELD_FLOAT,0)
  213.                 player.dropItemKeyPressing = false
  214.                 player.pauseKeyPressing = false
  215.         end
  216.  
  217.         --****************************
  218.         --|SNES9X-STYLE INPUT DISPLAY|
  219.         --|      CUSTOM SETTING      |
  220.         --****************************
  221.         if (InputConfig == 1) then
  222.                 if (player.upKeyPressing) then
  223.                         Text.print("U",460,584)
  224.                 end
  225.                 if (player.downKeyPressing) then
  226.                         Text.print("D",480,584)
  227.                 end
  228.                 if (player.leftKeyPressing) then
  229.                         Text.print("L",500,584)
  230.                 end
  231.                 if (player.rightKeyPressing) then
  232.                         Text.print("R",520,584)
  233.                 end
  234.        
  235.                 if (player.pauseKeyPressing) then
  236.                         Text.print("RUN",600,584)
  237.                 end
  238.                 if (player.dropItemKeyPressing) then
  239.                         Text.print("SEL",540,584)
  240.                 end
  241.        
  242.                 if (player.runKeyPressing == true and player.altRunKeyPressing == false) then
  243.                         Text.print("IV",760,584)
  244.                 end
  245.        
  246.                 if (player.jumpKeyPressing) then
  247.                         Text.print("II",680,584)
  248.                 end
  249.        
  250.                 if (player.altRunKeyPressing) then
  251.                         Text.print("III",700,584)
  252.                 end
  253.                 if (player.altJumpKeyPressing) then
  254.                         Text.print("I",640,584)
  255.                 end
  256.        
  257.         end
  258.  
  259.         if (MusicCombo == 1) then
  260.                 if (player.upKeyPressing and player.pauseKeyPressing) then
  261.                         showmusic = true
  262.                         player.pauseKeyPressing = false
  263.                 end
  264.         end
  265. end
  266.  
  267.  
  268. function onLoad()
  269.         --*************************************
  270.         --|REMOVE ANY BLUE SACKS ON LEVEL LOAD|
  271.         --*************************************
  272.         if (player.isValid) then
  273.                 if (player:mem(0x108,FIELD_WORD) == 1 and player:mem(0x10A,FIELD_WORD) == 3) then
  274.                         player:mem(0x108,FIELD_WORD, 0)
  275.                 end
  276.         end
  277.  
  278.         --*************************
  279.         --|DEMO COUNTER INIT STUFF|
  280.         --*************************
  281.         if (Settings:get(Level.filename() .. "-deaths") == nil) then
  282.                 Settings:set(Level.filename() .. "-deaths", 0)
  283.         end
  284.         if (Settings:get("totalDeaths") == nil) then
  285.                 Settings:set("totalDeaths", 0)
  286.         end
  287.        
  288.         Settings:save()
  289.  
  290. end
  291.  
  292. --******************
  293. --|MUSIC CHEAT CODE|
  294. --******************
  295. function musicCode()
  296.         if (MusicCombo == 0) then
  297.                 musiccheatcode = Misc.cheatBuffer()
  298.                 musiccheat = string.find(musiccheatcode, "music", 1)
  299.                 if (musiccheat ~= 0 and musiccheat ~= nil) then
  300.                         showmusic = true
  301.                         Misc.cheatBuffer("")
  302.                 end
  303.         end
  304.         if (showmusic == true) then
  305.                 Graphics.drawImage(musichud,0,515,50);
  306.                 if (Audio.MusicTitleTag() ~= "") then
  307.                        
  308.                         Text.print(Audio.MusicTitleTag(),50,550)
  309.                         Text.print(Audio.MusicArtistTag(),50,525)
  310.                         Text.print(Audio.MusicAlbumTag(),50,575)
  311.  
  312.                 else
  313.                         Text.print(ManualTitle,50,550)
  314.                         Text.print(ManualArtist,50,525)
  315.                         Text.print(ManualAlbum,50,575)
  316.                 end
  317.                 if (musicwait == false) then
  318.                 musicwait = true
  319.                 eventu.setTimer(5, hidecredits, false);
  320.                 end
  321.         end
  322. end
  323.  
  324. function hidecredits()
  325.         musicwait = false
  326.         showmusic = false
  327. end
  328.  
  329. --**************
  330. --|DEMO COUNTER|
  331. --**************
  332. function onHUDDraw()
  333.         if player:mem(0x13C, FIELD_DWORD) ~= 0 and not hasDied then
  334.                 Settings:set(Level.filename() .. "-deaths", Settings:get(Level.filename() .. "-deaths") + 1)
  335.                 Settings:set("totalDeaths", Settings:get("totalDeaths") + 1)
  336.                 Settings:save()
  337.                 hasDied = true
  338.         end
  339.         if (UseDemos == 1 and Graphics.isHudActivated()) then
  340.                 Graphics.drawImage(demosgraphic,56,26);
  341.                 Text.print(tostring(Settings:get("totalDeaths")), 1, 128, 27)
  342.                
  343.                 for i=1,math.min(5,local_raocoin_counter),1 do
  344.                     Graphics.drawImage(localraocoin,234+12*i,66);
  345.                 end
  346.         end
  347. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement