Advertisement
Enjl

Simple cutscene

Apr 11th, 2023
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. local routine = require("routine")
  2.  
  3. local lockedInputs = {}
  4. local lastInputs = {}
  5.  
  6. local inputsLocked = false
  7.  
  8. -- Call this function to lock player inputs
  9. function lockInputs()
  10. inputsLocked = true
  11. for k,v in pairs(player.keys) do
  12. lockedInputs[k] = false
  13. lastInputs[k] = player.keys[k]
  14. end
  15. end
  16.  
  17. -- Call this function to unlock player inputs
  18. function unlockInputs()
  19. inputsLocked = false
  20. end
  21.  
  22. -- Set up events that, when called in SMBX, start a lua cutscene
  23. function onEvent(eventName)
  24. if eventName == "StartCutscene" then
  25. Routine.run(sampleCutscene) -- Starts the cutscene
  26. end
  27. end
  28.  
  29. -- Lock inputs if inputs are locked
  30. function onTick()
  31. if inputsLocked then
  32. for k,v in pairs(player.keys) do
  33. lastInputs[k] = player.keys[k]
  34. player.keys[k] = lockedInputs[k]
  35. end
  36. end
  37. end
  38.  
  39. -- Reset the locked inputs, to prevent some edge case scenarios
  40. function onTickEnd()
  41. if inputsLocked then
  42. for k,v in pairs(player.keys) do
  43. player.keys[k] = lastInputs[k]
  44. end
  45. end
  46. end
  47.  
  48. -- Routine cutscenes are functions that can use the Routine class
  49. function sampleCutscene()
  50. lockInputs()
  51.  
  52. Text.showMessageBox("Hey, CHUMP!")
  53.  
  54. -- https://docs.codehaus.moe/#/reference/Routine
  55. Routine.wait(1) -- Wait 1 second
  56. Routine.waitFrames(20) -- Wait 20/64 of a second
  57. Routine.skip() -- Wait 1 frame
  58.  
  59. -- Force the player to run right
  60. -- right, left, up, down, run, altRun, jump, altJump, dropItem, pause
  61. lockedInputs.right = true
  62. Routine.wait(1)
  63. lockedInputs.right = false
  64.  
  65. Text.showMessageBox("Let's fight!")
  66.  
  67. unlockInputs()
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement