Guest User

smasnoturnback.lua

a guest
Sep 3rd, 2022
138
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. --smasnoturnback.lua (v1.0.1)
  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 also compatible with customCamera, and supports zooming and area stretching with it. You don't have to use customCamera to use this library, but just a reminder that it works with it.
  6.  
  7. local smasnoturnback = {}
  8.  
  9. local customCamera
  10. pcall(function() customCamera = require("customCamera") end)
  11. local autoscroll = require("autoscroll")
  12.  
  13. smasnoturnback.enabled = false --Enable this to activate everything here
  14. smasnoturnback.overrideSection = false --Set to true to prevent the turn back on a certain area, useful for onLoadSection(number)
  15. 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'.
  16.  
  17. function smasnoturnback.setSectionBounds(section, left, top, bottom, right)
  18. local sectionObj = Section(section)
  19. local bounds = sectionObj.boundary
  20. bounds.left = left
  21. bounds.top = top
  22. bounds.bottom = bottom
  23. bounds.right = right
  24. sectionObj.boundary = bounds
  25. end
  26.  
  27. function smasnoturnback.onInitAPI()
  28. registerEvent(smasnoturnback,"onCameraDraw")
  29. registerEvent(smasnoturnback,"onCameraUpdate")
  30. registerEvent(smasnoturnback,"onDraw")
  31. registerEvent(smasnoturnback,"onTick")
  32. end
  33.  
  34. smasnoturnback.failsafeTable = {
  35. "left",
  36. "right",
  37. "up",
  38. "down",
  39. }
  40.  
  41. function smasnoturnback.onCameraUpdate()
  42. for k,v in ipairs(Section.getActiveIndices()) do
  43. if not autoscroll.isSectionScrolling(v) then
  44. if smasnoturnback.enabled and not smasnoturnback.overrideSection then
  45. for itwo = 1,4 do
  46. if smasnoturnback.turnBack ~= smasnoturnback.failsafeTable[itwo] then --Failsafe if the turnBack argument is anything else but the things in this script
  47. smasnoturnback.turnBack = "left"
  48. end
  49. end
  50. if smasnoturnback.turnBack == "left" then
  51. if customCamera 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. else
  58. local fullX = camera.x
  59. if camera.x >= player.sectionObj.boundary.left then
  60. local x1 = fullX
  61. smasnoturnback.setSectionBounds(player.section, x1, player.sectionObj.boundary.top, player.sectionObj.boundary.bottom, player.sectionObj.boundary.right)
  62. end
  63. end
  64. elseif smasnoturnback.turnBack == "right" then
  65. if customCamera then
  66. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  67. if camera.x <= player.sectionObj.boundary.right then
  68. local x1 = fullX + 800
  69. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, player.sectionObj.boundary.bottom, x1)
  70. end
  71. else
  72. local fullX = camera.x
  73. if camera.x <= player.sectionObj.boundary.right then
  74. local x1 = fullX + 800
  75. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, player.sectionObj.boundary.bottom, x1)
  76. end
  77. end
  78. elseif smasnoturnback.turnBack == "up" then
  79. if customCamera then
  80. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  81. if camera.y >= player.sectionObj.boundary.top then
  82. local x1 = fullY
  83. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, x1, player.sectionObj.boundary.bottom, player.sectionObj.boundary.right)
  84. end
  85. else
  86. local fullY = camera.y
  87. if camera.y >= player.sectionObj.boundary.top then
  88. local x1 = fullY
  89. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, x1, player.sectionObj.boundary.bottom, player.sectionObj.boundary.right)
  90. end
  91. end
  92. elseif smasnoturnback.turnBack == "down" then
  93. if customCamera then
  94. local fullX,fullY,fullWidth,fullHeight = customCamera.getFullCameraPos()
  95. if camera.y <= player.sectionObj.boundary.bottom then
  96. local x1 = fullY + 600
  97. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, x1, player.sectionObj.boundary.right)
  98. end
  99. else
  100. local fullY = camera.y
  101. if camera.y <= player.sectionObj.boundary.bottom then
  102. local x1 = fullY + 600
  103. smasnoturnback.setSectionBounds(player.section, player.sectionObj.boundary.left, player.sectionObj.boundary.top, x1, player.sectionObj.boundary.right)
  104. end
  105. end
  106. end
  107. end
  108. else
  109. smasnoturnback.enabled = false
  110. smasnoturnback.overrideSection = true
  111. end
  112. end
  113. end
  114.  
  115. local levelTablesWithNoTurnbacks = {
  116. "levelsGoHere.lvlx",
  117. "youCanPutAnything.lvlx",
  118. "inThisTable.lvlx",
  119. "thatCanHaveANoTurnBack.lvlx",
  120. }
  121.  
  122. 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.
  123. --This is a sample table used for applying no-turn-backs on levels.
  124. if table.icontains(levelTablesWithNoTurnbacks,Level.filename()) and not smasnoturnback.overrideSection then
  125. smasnoturnback.enabled = true
  126. end
  127.  
  128.  
  129.  
  130. if smasnoturnback.overrideSection then
  131. smasnoturnback.enabled = false
  132. end
  133. end
  134.  
  135. return smasnoturnback
Advertisement
Comments
Add Comment
Please, Sign In to add comment