Advertisement
Guest User

walljumps.lua v1.1.2

a guest
Apr 22nd, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. --[[
  2.  
  3. ||||  O    ||||
  4. |||| /     ||||   walljumps.lua v1.1.2
  5. ||||/      ||||
  6. ||||\      ||||   Original Author: PixelPest
  7. ||||/      ||||   Further Work: Antiginger
  8.  
  9. ]]--
  10.  
  11. local eventu = API.load("eventu");
  12.  
  13. local walljumps = {};
  14.  
  15. walljumps.slideSpeed = 2; --speed when sliding down walls
  16. walljumps.jumpIntensityX = 8; --absolute speed of how fast the player travels along the horizontal axis after walljumping
  17. walljumps.jumpIntensityY = -10.5; --speed of how fast the player travels along the vertical axis after walljumping
  18. walljumps.delayTime = 0.5; --time (in seconds) that the player has to wait to walljump after making contact with the wall
  19. walljumps.maxNumFramesStuck = 24;
  20.  
  21. local isWallSlidingRight = false;
  22. local isWallSlidingLeft = false;
  23. local ReadyToJump = false;
  24. local timerIsSet = false;
  25. local StuckToWall = false;
  26. local FrameCounterStuck = 0;
  27.  
  28. function walljumps.onInitAPI()
  29.     registerEvent(walljumps, "onInputUpdate", "onInputUpdate", false);
  30. end
  31.  
  32. local function jump()
  33.     playSFX(2);
  34.     player.speedY = walljumps.jumpIntensityY;
  35.     ReadyToJump = false;
  36.     StuckToWall = false;
  37.     if isWallSlidingRight then
  38.         player.speedX = (-1)*walljumps.jumpIntensityX;
  39.         Animation.spawn(75, player.x + 0.5*(player.width), player.y + player.height - 16);
  40.     elseif isWallSlidingLeft then
  41.         player.speedX = walljumps.jumpIntensityX;
  42.         Animation.spawn(75, player.x - 0.5*(player.width), player.y + player.height - 16);
  43.     end
  44.    
  45. end
  46.  
  47. local function reset()
  48.     timerIsSet = false;
  49.     canJump = true;
  50. end
  51.  
  52. function walljumps.onInputUpdate()
  53.     if ((isWallSlidingRight) or
  54.     (isWallSlidingLeft)) and
  55.     (player.jumpKeyPressing == true) and
  56.     (ReadyToJump == true) and
  57.     (not player.downKeyPressing) and
  58.     (player:mem(0x34, FIELD_WORD) ~= 2) and
  59.     (player:mem(0x108, FIELD_WORD) == 0) and
  60.     (player.holdingNPC == nil) then
  61.         jump();
  62.     end
  63.    
  64.     if (player:mem(0x146, FIELD_WORD) == 0) and
  65.     (player:mem(0x14A, FIELD_WORD) == 0) and
  66.     (((player:mem(0x148, FIELD_WORD) == 2) or
  67.     (player:mem(0x14C, FIELD_WORD) == 2)) or
  68.     ((player:mem(0x148, FIELD_WORD) == 2) and
  69.     (player:mem(0x14C, FIELD_WORD) == 2))) and
  70.     (((player.rightKeyPressing) and
  71.     (player:mem(0x14C, FIELD_WORD) == 2)) or
  72.     ((player.leftKeyPressing)) and
  73.     (player:mem(0x148, FIELD_WORD) == 2)) or
  74.     (StuckToWall == true) and
  75.     (not player.downKeyPressing) and
  76.     (player:mem(0x34, FIELD_WORD) ~= 2) and --is not underwater/quicksand
  77.     (player:mem(0x50, FIELD_BOOL) ~= true) then --is not spingjumping
  78.         if (not isWallSlidingLeft) and (not isWallSlidingRight) and (not timerIsSet) then
  79.             eventu.setTimer(walljumps.delayTime, reset, false);
  80.             timerIsSet = true;
  81.             ReadyToJump = false;
  82.         end
  83.            
  84.         if player:mem(0x148, FIELD_WORD) == 2 then
  85.             isWallSlidingLeft = true;
  86.             isWallSlidingRight = false;
  87.             if player.jumpKeyPressing == false then
  88.                 ReadyToJump = true;
  89.             end
  90.             if player.speedY > 0 then
  91.                 Animation.spawn(74, player.x - 8, player.y + 0.5*(player.height + 8));
  92.             end
  93.         elseif player:mem(0x14C, FIELD_WORD) == 2 then
  94.             isWallSlidingRight = true;
  95.             isWallSlidingLeft = false;
  96.             if player.jumpKeyPressing == false then
  97.                 ReadyToJump = true;
  98.             end
  99.             if player.speedY > 0 then
  100.                 Animation.spawn(74, player.x + player.width, player.y + 0.5*(player.height + 8));
  101.             end
  102.         end
  103.         if (player.speedY > 0) and (not player.downKeyPressing) then
  104.             player.speedY = walljumps.slideSpeed;
  105.             if (StuckToWall == false) then
  106.                 StuckToWall = true;
  107.                 FrameCounterStuck = walljumps.maxNumFramesStuck;
  108.             end
  109.         end
  110.         if (StuckToWall) then
  111.             FrameCounterStuck = FrameCounterStuck - 1;
  112.             if (FrameCounterStuck == 0) then
  113.                 StuckToWall = false;
  114.                 player.speedY = 0;
  115.                 player.speedX = 0;
  116.             end
  117.             if (isWallSlidingRight) then
  118.                 player.speedX = 3;
  119.                 if player:mem(0x14C, FIELD_WORD) ~= 2 then
  120.                     StuckToWall = false;
  121.                     player.speedY = 0;
  122.                     FrameCounterStuck = 0;
  123.                 end
  124.             end    
  125.             if (isWallSlidingLeft) then
  126.                 player.speedX = -3;
  127.                 if player:mem(0x148, FIELD_WORD) ~= 2 then
  128.                     StuckToWall = false;
  129.                     player.speedY = 0;
  130.                     FrameCounterStuck = 0;
  131.                 end
  132.             end                
  133.         end
  134.     else
  135.         isWallSlidingRight = false;
  136.         isWallSlidingLeft = false;
  137.         ReadyToJump = false;
  138.     end
  139.  
  140.     if player:mem(0x146, FIELD_WORD) == 2 then
  141.         ReadyToJump = false;
  142.     end
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement