Advertisement
Bulby

Sm3dwPal

Nov 27th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.36 KB | None | 0 0
  1. --[[
  2.     Super Mario 3D World Move
  3.     Allows player to Crawl + Long Jump
  4.     sm3dwMovePal is library name.
  5.     ]]
  6. -- Yes, I know that if you hold Alt Jump you will be fast for a little bit.
  7. -- Toad is slightly slower because his top speed is a headache.
  8. local inputs = API.load("inputs2");
  9. local textblox = API.load("textblox");
  10.  
  11. local sm3dwMovePal = {}
  12. local trueCharacterID = {};
  13. local footContact = {};
  14. local players = {player, player2};
  15. local isBannedCharacter = {};
  16. local isInSomething = {};
  17. local isDoingBannedStuff = {};
  18. local allowCrawl = {};
  19. local isHoldingSomething = {};
  20. local isRunning = {};
  21. local   currentPowerUp = {};
  22. local   inGroundNow = {};
  23. local   inSlopeNow = {};
  24. local   inStandNPC = {};
  25. local   isInVine = {};
  26. local   pressedAltJump = {};
  27. local   isInMount = {};
  28. local isInWater = {};
  29. local spriteHeld =  {};
  30. local characterId =  {};
  31. local isStatue = {};
  32. local isInRainbowShell =  {};
  33. local isLeft =  {};
  34. local playerZoomFactor = {};
  35. local truePowerup = {};
  36. local currentPowerUp = {};
  37. local crouchWalkEntered = {};
  38. local addSpeed = {};
  39. local times = {};
  40. local isLongJumping = {};
  41. local BannedCrouchList = {0, 0, 1, 0, 1, 2, 2, 1, 1, 1, 0, 1, 0, 0, 1, 2}; -- 0 is allowed with own character, 1 is allowed if changing to other characters is allowed, 2 is never allowed
  42. local BannedLongJumpList = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}; -- I don't know why this is still here, but used for long jump
  43. local maxSpeed = {6, 6, 6, 6.42, 6, 6.4, 8, 4, 6, 6, 6, 6, 6, 5.5, 5, 6}; -- Maximum speed of a character. Certian characters have a different max speed depending what they are doing, which is what specialMaxSpeed and preventspecialMaxEnforce are for.
  44. local allowedInSmallState = {false, false, true, false, true, false, false, true, true, true, false, true, false, false, true, false}; -- Used, as some characters small state can't fit into a 1 block gap.
  45. local specialMaxSpeed = {6, 6, 6, 6.42, 6, 3.4, 4, 4, 3, 6, 6, 6, 6, 5.5, 5, 6}; -- Some characters run speed define changes, and this is used to deal with that.
  46. local preferedMorph = {1, 2, 1, 4, 2, 6, 7, 1, 4, 4, 11, 2, 13, 14, 4, 16}; -- Character morphed into during crawl. If they are a 2 on the BannedCrouchList they are just listed as their own character instead of nil.
  47. local walkMax = {3, 3, 3, 3, 3, 2.8, 3, 2, 3, 3, 3, 3, 3, 5.5, 3, 3}; -- Not used, the Default Defines.player_walkspeed
  48. local preventspecialMaxEnforce = {nil, nil, nil, nil, nil, nil, altjump, nil, run, nil, nil, nil, nil, nil, nil, nil}; -- Button, that if pressed, ignores specialMaxSpeed and changes to maxSpeed
  49. local isCrawling = {}; -- Detects if character is currently crawling
  50. local timer = 0; -- Used to prevent character from going over their max define speed.
  51. local ymodifier = {}; -- Used to force characters to crouch
  52. local player_isCrouching = {}; -- Used to force characters to crouch
  53. local player_lowCeiling = {}; -- Used to force characters to crouch
  54. sm3dwMovePal.speed = 1.5 -- speed added during long jump
  55. sm3dwMovePal.allowCharacterTransform = true; -- Used to see if characters who are a 1 in BannedCrouchList can crawl anyway
  56. zoomFactor = math.abs(tonumber(sm3dwMovePal.speed))
  57. Defines.player_runspeed = 10 + sm3dwMovePal.speed;
  58. currentPowerUp[1] = players[1].powerup
  59. trueCharacterID[1] = players[1].character
  60. if Player.count() == 2 then
  61.     currentPowerUp[2] = players[2].powerup
  62.     trueCharacterID[2] = players[2].character
  63. end
  64.  
  65. function sm3dwMovePal.onInitAPI()
  66.     registerEvent(sm3dwMovePal, "onTick", "onTick");
  67.     registerEvent(sm3dwMovePal, "onStart", "onStart");
  68.     registerEvent(sm3dwMovePal, "onInputUpdate");
  69.     registerEvent(sm3dwMovePal, "onTickEnd", "onTickEnd");
  70. end
  71.  
  72. local function memRecognitionFunction()
  73.     for d, y in ipairs(Player.get()) do
  74.     currentPowerUp[d] = y:mem(0x112, FIELD_WORD)
  75.     inGroundNow[d] = y:mem(0x146, FIELD_BOOL)
  76.     inSlopeNow[d] = y:mem(0x48, FIELD_BOOL)
  77.     inStandNPC[d] = y:mem(0x176, FIELD_BOOL)
  78.     isInVine[d] = y:mem(0x40, FIELD_BOOL)
  79.     pressedAltJump[d] = y.altJumpKeyPressing
  80.     isInMount[d] =  y:mem(0x108, FIELD_BOOL)
  81.     isInWater[d] = y:mem(0x44, FIELD_BOOL)
  82.     spriteHeld[d] =  y:mem(0x154, FIELD_WORD)
  83.     characterId[d] =  y:mem(0xF0, FIELD_WORD)
  84.     isStatue[d] = y:mem(0x4A, FIELD_BOOL)
  85.     isInRainbowShell[d] =  y:mem(0x44, FIELD_BOOL)
  86.     isLeft[d] =  y:mem(0x106, FIELD_WORD) < 0
  87.     playerZoomFactor[d] = y:mem(0xE0, FIELD_DFLOAT)
  88.     end
  89. end
  90.  
  91. local function memFusions()
  92.     for e,z in ipairs(Player.get()) do
  93.         if math.abs(z.speedX) > walkMax[trueCharacterID[e]] then
  94.             isRunning[e] = true;
  95.         else
  96.             isRunning[e] = false;
  97.         end
  98.         if not inSlopeNow[e] and
  99.     not inGroundNow[e] and
  100.     not inStandNPC[e] then
  101.         footContact[e] = false;
  102.     else
  103.         footContact[e] = true;
  104.     end
  105.     if spriteHeld[e] >= 1 then
  106.         isHoldingSomething[e] = true;
  107.     else
  108.         isHoldingSomething[e] = false;
  109.     end
  110.     if isInVine[e] or
  111.     isInMount[e] or
  112.     isInWater[e] or
  113.     isInRainbowShell[e] or
  114.     isStatue[e] then
  115.         isInSomething[e] = true;
  116.     else
  117.         isInSomething[e] = false
  118.     end
  119.     end
  120. end
  121. function checkSpeed()
  122.     for i,v in ipairs(Player.get()) do
  123.     if footContact[i]  and
  124.     (inputs.state[i].altjump ~= 1 and (inputs.state[i].altjump ~= 2 or times[i] > 5)) and not isBannedCharacter[i] then
  125.         isLongJumping[i] = false
  126.     end
  127.     if inputs.state[i].altjump == 2 and not isBannedCharacter[i] then
  128.             times[i] = times [i] +  1
  129.     else
  130.         times[i] = 0
  131.     end
  132.     end
  133. end
  134. local function doingBannedStuff()
  135.     for i,v in ipairs(Player.get()) do
  136.     if  not footContact[i] or
  137.     isInSomething[i] or
  138.     isHoldingSomething[i] then
  139.         isDoingBannedStuff[i] = true;
  140.     else
  141.         isDoingBannedStuff[i] = false;
  142.     end
  143.     end
  144. end
  145. local function preventZoom() -- Stop player from going over their normal Run Speed define
  146.     for i, v in ipairs(Player.get()) do
  147.         if not isLongJumping[i] and (math.abs(v.speedX) > specialMaxSpeed[v.character]) then --Make sure the character is not long jumping. It uses specialMaxSpeed because most characters specialMaxSpeed is the same as their maxSpeed
  148.             if v.character == 6 then -- Megaman
  149.                 if v.height < 20  and -- Checking if megaman is sliding by checking hitbox, not if button pressed to avoid exploits.
  150.                 (math.abs(v.speedX) > maxSpeed[v.character]) then
  151.                     if v.speedX < 0 then
  152.                         v.speedX = 0 - maxSpeed[v.character];
  153.                     else
  154.                         v.speedX = maxSpeed[v.character];
  155.                     end
  156.                 else
  157.                     if v.speedX < 0 then
  158.                         v.speedX = 0 - specialMaxSpeed[v.character];
  159.                     else
  160.                         v.speedX = specialMaxSpeed[v.character];
  161.                     end
  162.                 end
  163.             elseif v.character == 9 then -- Klonoa
  164.                 if (inputs.state[i].altrun == inputs.HOLD) and
  165.                 math.abs(v.speedX) > maxSpeed[v.character] then
  166.                     if v.speedX < 0 then
  167.                         v.speedX = 0 - maxSpeed[v.character];
  168.                     else
  169.                         v.speedX = maxSpeed[v.character];
  170.                     end
  171.                 else
  172.                     if v.speedX < 0 then
  173.                         v.speedX = 0 - specialMaxSpeed[v.character];
  174.                     else
  175.                         v.speedX = specialMaxSpeed[v.character];
  176.                     end
  177.                 end
  178.             elseif v.character == 7 then
  179.                 if (inputs.state[i].altrun == inputs.HOLD) and
  180.                 math.abs(v.speedX) > maxSpeed[v.character] then
  181.                     if v.speedX < 0 then
  182.                         v.speedX = 0 - maxSpeed[v.character];
  183.                     else
  184.                         v.speedX = maxSpeed[v.character];
  185.                     end
  186.                 else
  187.                     if v.speedX < 0 then
  188.                         v.speedX = 0 - specialMaxSpeed[v.character];
  189.                     else
  190.                         v.speedX = specialMaxSpeed[v.character];
  191.                     end
  192.                 end
  193.             else
  194.                 if math.abs(v.speedX) > maxSpeed[v.character] then
  195.                     if v.speedX < 0 then
  196.                         v.speedX = 0 - maxSpeed[v.character];
  197.                     else
  198.                         v.speedX = maxSpeed[v.character];
  199.                     end
  200.                 end
  201.             end
  202.         end
  203.     end
  204. end
  205. for c, x in ipairs(Player.get()) do
  206.     if not isBannedCharacter[c] then
  207.         inputs.locked[c].down = true;
  208.     else
  209.         inputs.locked[c].down = false;
  210.     end
  211. end
  212. local function longJump(i)  -- Adds more speed than define allows
  213.     if not isDoingBannedStuff[i] and isRunning[i] and
  214.     inputs.state[i].altjump == 1 then
  215.         isLongJumping[i] = true
  216.         players[i].runKeyPressing = false;
  217.         addSpeed[i] = v.speedX
  218.         if isLeft[i] then
  219.             players[i].leftKeyPressing = false;
  220.         else
  221.             players[i].rightKeyPressing = false;
  222.         end
  223.         players[i].speedX = 0
  224.         Audio.playSFX(1);
  225.         if isLeft[i] then
  226.             players[i].speedX = addSpeed[i] - zoomFactor   
  227.         else
  228.             players[i].speedX = addSpeed[i] + zoomFactor
  229.         end
  230.         players[i].jumpKeyPressing = true                          
  231.     end
  232. end
  233. local function crouchwalk(i)
  234.     if not isDoingBannedStuff[i] and
  235.     ((currentPowerUp[i] ~= PLAYER_SMALL and not allowedInSmallState[trueCharacterID[i]]) or
  236.     (allowedInSmallState[trueCharacterID[i]] and trueCharacterID[i] == players[i].character))
  237.         Audio.playSFX(26);
  238.         truePowerup[i] = players[i].powerup;
  239.         trueCharacterID[i] = players[i].character;
  240.         players[i]:mem(0x112, FIELD_WORD, 1);
  241.         players[i]:mem(0xF0, FIELD_WORD, preferedMorph[trueCharacterID[i]]);
  242.         isCrawling[i] = true;
  243.     end
  244.     if ((truePowerup[i] ~= currentPowerUp[i] and not allowedInSmallState[trueCharacterID[i]]) or
  245.     (trueCharacterID[i] ~= players[i].character and allowedInSmallState[trueCharacterID[i]])) and
  246.     inputs.state[i].down == inputs.RELEASE and
  247.     ((truePowerup[i] ~= 1 and not allowedInSmallState[trueCharacterID[i]]) or allowedInSmallState[i]) and
  248.     isCrawling[i] then
  249.         Audio.playSFX(71);     
  250.         players[i]:mem(0x112, FIELD_WORD, truePowerup[i]);
  251.         players[i]:mem(0xF0, FIELD_WORD, trueCharacterID[i]);
  252.         isCrawling[i] = false;
  253.     end
  254. end
  255. for i,v in ipairs(Player.get()) do
  256.     trueCharacterID[i] = v:mem(0xF0, FIELD_WORD);
  257.     truePowerup[i] = v.powerup;
  258.     currentPowerUp[i] = v.powerup;
  259.     if trueCharacterID[i] == 1 or trueCharacterID[i] == 2 or trueCharacterID[i] == 4 then
  260.         isBannedCharacter[i] = false
  261.     else
  262.         isBannedCharacter[i] = true
  263.     end
  264. end
  265. local function runOnInput(c)
  266.     if not isBannedCharacter[c] then
  267.     if inputs.state[c].down == inputs.PRESS and
  268.     ((inSlopeNow[c] and (characterId[c] == 1 or characterId[c] == 2)) or isInVine[c] or isInMount[c] or not footContact[c]) then
  269.         inputs.locked[c].down = false;
  270.     end
  271.     if inputs.locked[c].down == false and
  272.     not((inSlopeNow[c] and (characterId[c] == 1 or characterId[c] == 2)) or isInVine[c] or isInMount[c] or not footContact[c]) then
  273.         inputs.locked[c].down = true;
  274.     end
  275.     if(players[c].altJumpKeyPressing) and (players[c]:mem(0x108,FIELD_WORD) < 1) and not players[c].jumpKeyPressing and isRunning[c] then
  276.         players[c].altJumpKeyPressing = false;
  277.         longJump(c);
  278.     end
  279. end
  280. function sm3dwMovePal.onInputUpdate()
  281.     runOnInput(1);
  282.     bugInput(1);
  283.     if Player.count() == 2 then
  284.         inputs.locked[c].down = false
  285.     end
  286.    
  287. end
  288.  
  289.  
  290. function sm3dwMovePal.onTick()
  291.     preventZoom();
  292.    
  293.     timer = timer + 1;
  294.     if timer % 2 == 0 then
  295.         checkSpeed();
  296.     end
  297.     textblox.printExt ("True Character ID:" + tostring(trueCharacterID[1]), {x=400,y=150, halign=textblox.HALIGN_MID, valign=textblox.VALIGN_MID})
  298.     for c, x in ipairs(Player.get()) do
  299.         if (BannedCrouchList[trueCharacterID[c]] == 0) or
  300.         (BannedCrouchList[trueCharacterID[c]] == 1 and sm3dwMovePal.allowCharacterTransform) then
  301.             memRecognitionFunction();
  302.             memFusions();
  303.             doingBannedStuff();
  304.             if inputs.state[c].down == inputs.PRESS or
  305.             inputs.state[c].down == inputs.RELEASE then
  306.                 crouchwalk(c);
  307.             end
  308.         end
  309.     end
  310. end
  311.    
  312. end
  313. -- SMBX Crouching Bugfix --
  314. -- by Nat The Porcupine --
  315. --Further work by BulbyVR --
  316. function has_value (tab, val)
  317.     for index, value in ipairs(tab) do
  318.         if value == val then
  319.             return true
  320.         end
  321.     end
  322.  
  323.     return false
  324. end
  325. function bugInput(i)
  326.     if true then
  327.     -- Stores the player's crouching state in a variable --
  328.     if players[i]:mem(0x12E,FIELD_WORD) == -1 then
  329.         player_isCrouching[i] = true;
  330.         ymodifier[i] = 32;
  331.     else
  332.         player_isCrouching[i] = false;
  333.         ymodifier[i] = 0;
  334.     end
  335.    
  336.     -- Checks if the player is small or touching ground--
  337.     if players[i]:mem(0x112, FIELD_WORD) ~= 1 and footContact[i] then
  338.        
  339.         -- Checks for blocks above the player while they're crouching --
  340.         for k,v in pairs(Block.getIntersecting(players[i].x, players[i].y - ymodifier[i], players[i].x + players[i].width, players[i].y)) do
  341.            
  342.              
  343.             -- Checks for visible blocks only --
  344.             if v:mem(0x1C,FIELD_WORD) == 0 then
  345.                
  346.                 -- Block exception list: list of blocks that will not force the player to duck --
  347.                 local exception = {8, 25, 26, 27, 28, 30, 38, 69, 79, 108, 121, 122, 123,130, 161, 168, 172, 175, 178,
  348.                 181, 240, 241, 242, 243, 244, 245, 259, 260, 261, 287, 288, 289, 290, 370, 371, 372, 373, 374, 375, 379, 380, 381, 382, 389, 391, 392, 404, 405, 406, 420, 437, 438, 439, 440 ,441, 442, 443, 444, 445, 446, 447, 448, 459, 460
  349.                 ,461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 506, 507, 508, 568, 572, 575, 579};
  350.                 if has_value(exception, v.id) then player_lowCeiling[i] = false else player_lowCeiling[i] = true end
  351.                
  352.             end
  353.            
  354.         end
  355.        
  356.     end
  357.    
  358.    
  359.     -- Forces the player to crouch --
  360.    
  361.     if f.downKeyPressing == false then
  362.        
  363.         if player_lowCeiling[i] == true then
  364.             players[i].downKeyPressing = true;
  365.         elseif players[i]:mem(0x146,FIELD_WORD) == 0 and player_isCrouching[i] == true then
  366.             players[i].downKeyPressing = true;
  367.         else
  368.             players[i].downKeyPressing = false;
  369.         end
  370.     end
  371.  
  372.     end
  373. end
  374. function sm3dwMovePal.onTickEnd()
  375.     -- Resets the player's low ceiling variable for technical reasons --
  376.     for i, v in ipairs(Player.get()) do
  377.         if not isBannedCharacter[i] then
  378.         player_lowCeiling[i] = false;
  379.         end
  380.     end
  381.    
  382. end
  383.  
  384.  
  385. return sm3dwMovePal;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement