Guest User

smasnoturnback.lua - v1.0

a guest
Sep 3rd, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. --smasnoturnback.lua
  2. --By Spencer Everly
  3. --This script provides a remake of the noTurnBack option, but with additional things like going left but not turning back right, and other things!
  4.  
  5. --This is only compatible with customCamera, to support zooming and area stretching. If you want the script without it, remove the customCamera mentions and do this:
  6. --local fullX = camera.x
  7. --local fullY = camera.y
  8.  
  9. local smasnoturnback = {}
  10.  
  11. local customCamera = require("customCamera")
  12. local autoscroll = require("autoscroll")
  13.  
  14. smasnoturnback.enabled = false --Enable this to activate everything here
  15. smasnoturnback.overrideSection = false --Set to true to prevent the turn back on a certain area, useful for onLoadSection(number)
  16. smasnoturnback.turnBack = "left" --Set to 'right' for a no right turn back, or 'up' for a no top turn back, or even 'down' for a no bottom turn back. Anything else accidentally set will be automatically set to 'left'.
  17.  
  18. function smasnoturnback.setSectionBounds(section, left, top, bottom, right)
  19. local sectionObj = Section(section)
  20. local bounds = sectionObj.boundary
  21. bounds.left = left
  22. bounds.top = top
  23. bounds.bottom = bottom
  24. bounds.right = right
  25. sectionObj.boundary = bounds
  26. end
  27.  
  28. function smasnoturnback.onInitAPI()
  29. registerEvent(smasnoturnback,"onCameraDraw")
  30. registerEvent(smasnoturnback,"onCameraUpdate")
  31. registerEvent(smasnoturnback,"onDraw")
  32. registerEvent(smasnoturnback,"onTick")
  33. end
  34.  
  35. smasnoturnback.failsafeTable = {
  36. "left",
  37. "right",
  38. "up",
  39. "down",
  40. }
  41.  
  42. function smasnoturnback.onCameraUpdate()
  43. for i = 0,20 do
  44. if not autoscroll.isSectionScrolling(i) then
  45. if smasnoturnback.enabled and not smasnoturnback.overrideSection then
  46. for itwo = 1,4 do
  47. if smasnoturnback.turnBack ~= smasnoturnback.failsafeTable[itwo] then --Failsafe if the turnBack argument is anything else but the things in this script
  48. smasnoturnback.turnBack = "left"
  49. end
  50. end
  51. if smasnoturnback.turnBack == "left" then
  52. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  53. if camera.x >= player.sectionObj.boundary.left then
  54. local x1 = fullX
  55. smasnoturnback.setSectionBounds(player.section, x1, player.sectionObj.boundary.top, player.sectionObj.boundary.bottom, player.sectionObj.boundary.right)
  56. end
  57. elseif smasnoturnback.turnBack == "right" then
  58. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  59. if camera.x <= player.sectionObj.boundary.right then
  60. local x1 = fullX + 800
  61. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, player.sectionObj.boundary.bottom, x1)
  62. end
  63. elseif smasnoturnback.turnBack == "up" then
  64. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  65. if camera.y >= player.sectionObj.boundary.top then
  66. local x1 = fullY
  67. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, x1, player.sectionObj.boundary.bottom, player.sectionObj.boundary.right)
  68. end
  69. elseif smasnoturnback.turnBack == "down" then
  70. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  71. if camera.y <= player.sectionObj.boundary.bottom then
  72. local x1 = fullY + 600
  73. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, x1, player.sectionObj.boundary.right)
  74. end
  75. end
  76. end
  77. end
  78. if autoscroll.isSectionScrolling(i) then
  79. smasnoturnback.enabled = false
  80. smasnoturnback.overrideSection = true
  81. end
  82. end
  83. end
  84.  
  85. local levelTablesWithNoTurnbacks = {
  86. "levelsGoHere.lvlx",
  87. "youCanPutAnything.lvlx",
  88. "inThisTable.lvlx",
  89. "thatCanHaveANoTurnBack.lvlx",
  90. }
  91.  
  92. function smasnoturnback.onTick() --If you want a certain level or more, make a table with level filenames on it. A sample table is included above.
  93. --This is a sample table used for applying no-turn-backs on levels.
  94. if table.icontains(levelTablesWithNoTurnbacks,Level.filename()) and not smasnoturnback.overrideSection then
  95. smasnoturnback.enabled = true
  96. end
  97.  
  98.  
  99.  
  100. if smasnoturnback.overrideSection then
  101. smasnoturnback.enabled = false
  102. end
  103.  
  104.  
  105. end
  106.  
  107. return smasnoturnback
Advertisement
Add Comment
Please, Sign In to add comment