Advertisement
eliasdaler

Witch script

Mar 29th, 2015
1,585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. ScriptStateMachineComponent = {
  2.     states = {
  3.         IdleState = {
  4.             enter = function(self, entity)
  5.                 setAnimation(entity, "idle")
  6.                 startTimer(entity, "idleTimer")
  7.             end,
  8.             execute = function(self, entity)
  9.                 if(timerTicked(entity, "idleTimer")) then -- open the book after some time
  10.                     setScriptState(entity, "OpeningBookState")
  11.                 end
  12.             end,
  13.             exit = function(self, entity)
  14.                 stopTimer(entity, "idleTimer")
  15.             end
  16.         },
  17.         OpeningBookState = {
  18.             enter = function(self, entity)
  19.                 setAnimation(entity, "openingBook")
  20.                 end,
  21.             execute = function(self, entity)
  22.                 if(currentAnimationFinished(entity)) then -- finished opening the book
  23.                     setScriptState(entity, "ReadingBookState")
  24.                 end
  25.             end
  26.         },
  27.         ReadingBookState = {
  28.             init = function(self)
  29.                 self.flippingPage = false
  30.                 self.flippedPages = 0
  31.             end,
  32.             enter = function(self, entity)
  33.                 setAnimation(entity, "reading")
  34.                 startTimer(entity, "pageFlipTimer")
  35.             end,
  36.             execute = function(self, entity)
  37.                 if(timerTicked(entity, "pageFlipTimer") and not self.flippingPage) then -- time to flip the page
  38.                     if(self.flippedPages == 5) then -- flipped enough times already, go to idle state
  39.                         setScriptState(entity, "IdleState")
  40.                     else -- flip the page!
  41.                         self.flippingPage = true
  42.                         setAnimation(entity, "flippingPage")
  43.                         stopTimer(entity, "pageFlipTimer")
  44.                     end
  45.                 end
  46.                 if(self.flippingPage and currentAnimationFinished(entity)) then -- finished flipping the page, go to reading state
  47.                     setAnimation(entity, "reading")
  48.                     startTimer(entity, "pageFlipTimer")
  49.                     self.flippingPage = false
  50.                     self.flippedPages = self.flippedPages + 1
  51.                 end
  52.             end
  53.         }
  54.     }
  55. },
  56. TimerComponent = {
  57.     timers = {
  58.         idleTimer = {
  59.             tickTime = 1500,
  60.         },
  61.         pageFlipTimer = {
  62.             tickTime = 2500,
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement