Advertisement
Enjl

playerphysicspatch shmoove

Feb 8th, 2025
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.67 KB | None | 0 0
  1. -- Playerphysicspatch SHMOOVE Mode
  2.  
  3. -- Use with caution around slopes
  4.  
  5. local lastXSpeed = {}
  6. local ppp = {}
  7.  
  8. ppp.speedXDecelerationModifier = 0.08
  9. ppp.groundTouchingDecelerationMultiplier = 1
  10. ppp.groundNotTouchingDecelerationMultiplier = 2
  11.  
  12. ppp.accelerationMaxSpeedThereshold = 2
  13. ppp.accelerationMinSpeedThereshold = 0.1
  14. ppp.accelerationSpeedDifferenceThereshold = 0.2
  15. ppp.accelerationMultiplier = 1.5
  16.  
  17. ppp.aerialIdleDeceleration = 1
  18.  
  19. ppp.lenientPSpeed = false
  20.  
  21. ppp.enabled = true
  22.  
  23. local RUNSPEED = 6
  24. local WALKSPEED = 3
  25.  
  26. local pSpeedTimer = 0
  27. local pSpeedDecay = false
  28.  
  29. function ppp.onInitAPI()
  30.     registerEvent(ppp, "onTick")
  31.     registerEvent(ppp, "onTickEnd")
  32. end
  33.  
  34. function ppp.setWalkSpeed(spd)
  35.     WALKSPEED = spd or 3
  36. end
  37.  
  38. function ppp.setRunSpeed(spd)
  39.     RUNSPEED = spd or 6
  40. end
  41.  
  42. function ppp.onTickEnd()
  43.     Defines.player_walkspeed = 16
  44.     Defines.player_runspeed = 16
  45.     for k,p in ipairs(Player.get()) do
  46.         local maxspeed = WALKSPEED
  47.         if p.keys.run then maxspeed = RUNSPEED end
  48.         if p.hasStarman then
  49.             maxspeed = maxspeed + 2.5
  50.         end
  51.         local sliding = false
  52.         if p:mem(0x3C, FIELD_BOOL) then
  53.             sliding = true
  54.         end
  55.         if sliding then
  56.             sliding = false
  57.             local slopeIdx = p:mem(0x48, FIELD_WORD)
  58.             if p.speedY > 0 and slopeIdx > 0 then
  59.                 local b = Block(slopeIdx)
  60.                 if Block.config[b.id].floorslope ~= 0 then
  61.                     p.speedX = p.speedX + 0.1 * Block.config[b.id].floorslope
  62.                     sliding = true
  63.                 end
  64.             end
  65.         end
  66.         if not sliding then -- Prevents speed decrease when not pressing any buttons
  67.             local decrease = 0.15
  68.             if not p:isOnGround() and not p.keys.left and not p.keys.right then
  69.                 decrease = 0
  70.             end
  71.             if p.speedX > maxspeed then
  72.                 p.speedX = math.max(p.speedX - decrease, maxspeed)
  73.             elseif p.speedX < -maxspeed then
  74.                 p.speedX = math.min(p.speedX + decrease, -maxspeed)
  75.             end
  76.         end
  77.    
  78.         if not player:mem(0x16E, FIELD_BOOL) then
  79.             if math.abs(p.speedX) >= RUNSPEED then
  80.                 if p:isOnGround() then
  81.                     pSpeedTimer = pSpeedTimer + 1
  82.                 else
  83.                     pSpeedTimer = pSpeedTimer - 3
  84.                 end
  85.             else
  86.                 if pSpeedDecay then
  87.                     pSpeedTimer = 0
  88.                 end
  89.                 pSpeedTimer = pSpeedTimer - 3
  90.             end
  91.             pSpeedDecay = false
  92.             pSpeedTimer = math.max(pSpeedTimer, 0)
  93.         elseif not ppp.lenientPSpeed then
  94.             pSpeedDecay = true
  95.         end
  96.         p:mem(0x168, FIELD_FLOAT, pSpeedTimer)
  97.  
  98.         local t = p:mem(0x118, FIELD_FLOAT)
  99.         p:mem(0x118, FIELD_FLOAT, t + math.max(0, (math.abs(p.speedX) - WALKSPEED) * 0.17))
  100.     end
  101. end
  102.  
  103. function ppp.onTick()-- (deceleration tightness)
  104.     if ppp.enabled and player.forcedState == 0 then
  105.         for k,p in ipairs(Player.get()) do
  106.             lastXSpeed[k] = lastXSpeed[k] or 0
  107.             if not p:mem(0x3C, FIELD_BOOL) then
  108.                 if (not (p:isGroundTouching() and p:mem(0x12E, FIELD_BOOL))) then
  109.                     local mod = ppp.groundTouchingDecelerationMultiplier
  110.                     if (not p:isGroundTouching()) then
  111.                         mod = ppp.groundNotTouchingDecelerationMultiplier
  112.                     end
  113.                     if p.rightKeyPressing then
  114.                         if p.speedX < 0 then
  115.                             p.speedX = p.speedX + ppp.speedXDecelerationModifier * mod;
  116.                         end
  117.                     elseif p.leftKeyPressing then
  118.                         if  p.speedX > 0 then
  119.                             p.speedX = p.speedX - ppp.speedXDecelerationModifier * mod;
  120.                         end
  121.                     else
  122.                         p.speedX = p.speedX * ppp.aerialIdleDeceleration;  
  123.                     end
  124.                 end
  125.            
  126.             -- (acceleration tightness)
  127.                 local xspeeddiff = p.speedX - lastXSpeed[k]
  128.  
  129.                 if math.abs(p.speedX) < ppp.accelerationMaxSpeedThereshold and math.abs(p.speedX) > ppp.accelerationMinSpeedThereshold and math.sign(p.speedX * xspeeddiff) == 1 and math.abs(xspeeddiff) <= ppp.accelerationSpeedDifferenceThereshold then
  130.                     p.speedX = p.speedX - xspeeddiff
  131.                     p.speedX = p.speedX + xspeeddiff * ppp.accelerationMultiplier
  132.                 end
  133.  
  134.             end
  135.             lastXSpeed[k] = p.speedX
  136.         end
  137.     end
  138. end
  139.  
  140. return ppp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement