Advertisement
eliasdaler

Door script

Feb 10th, 2016
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. local makeCutscene = function(args)
  2.     local door = args.door
  3.    
  4.     local cutscene = args.cutscene
  5.        
  6.     -- position to which player goes before fade in to black
  7.     local enterDestinationPos = door:getCenter()
  8.     enterDestinationPos.y = enterDestinationPos.y - 40.0
  9.  
  10.     local teleportDestination = getEntityByTag(door:getDestinationTag())
  11.  
  12.     -- position from which player starts after fade in
  13.     local insideCenterPos = teleportDestination:getCenter()
  14.     insideCenterPos.y = insideCenterPos.y + 28.0
  15.  
  16.     local actions = {
  17.         {
  18.             f = function()
  19.                 if(door:getScriptStateName() == "DoorLockedState") then -- check if the door is locked
  20.                     if(playerEntity:hasItem(args.key)) then -- check if player has the key
  21.                         cutscene:goTo("OPEN")
  22.                     else
  23.                         cutscene:goTo("CANT_OPEN")
  24.                     end
  25.                 else
  26.                     cutscene:goTo("ENTER") -- just open the door
  27.                 end
  28.             end
  29.         },
  30.        
  31.         -- has the key, open the door and enter
  32.         {
  33.             tag = "OPEN",
  34.             type = ActionType.UsedItem,
  35.             itemName = args.key,
  36.             nextTag = "ENTER"
  37.         },
  38.        
  39.         -- can't open, say that the door is locked
  40.         {
  41.             tag = "CANT_OPEN",
  42.             type = ActionType.Dialogue,
  43.             dialogue = {
  44.                 {
  45.                     text = { "DOOR_LOCKED" }
  46.                 }
  47.             },
  48.             nextTag = "EXIT_REQUEST_TAG"
  49.         },
  50.        
  51.         -- enter the house
  52.         {  
  53.             tag = "ENTER",
  54.             f = function()
  55.                 door:setScriptState("DoorOpeningState")
  56.                 playerEntity:setComponentDisabled("CollisionComponent", true)
  57.                 cameraUnfollow()
  58.             end
  59.         },
  60.         {
  61.             type = ActionType.GoTo,
  62.             entity = playerEntity,
  63.             destination = enterDestinationPos
  64.         },
  65.         -- don't forget to close the door, it's cold outside
  66.         {
  67.             f = function()
  68.                 door:setScriptState("DoorClosingState")
  69.             end
  70.         },
  71.         {
  72.             type = ActionType.Effect,
  73.             name = "FadeOutToBlack",
  74.             popAfterFinish = false
  75.         },
  76.         {
  77.             f = function()
  78.                 centerCameraAround(teleportDestination) -- this sets camera to be in the room which player teleports into
  79.             end
  80.         },
  81.         {
  82.             type = ActionType.Effect,
  83.             name = "FadeInFromBlack",
  84.             popPrevious = true,
  85.             waitForFinish = false
  86.         },
  87.         {
  88.             f = function()
  89.                 playerEntity:setCenter(insideCenterPos)
  90.                 playerEntity:setDisabled(false)
  91.                 playerEntity:setComponentDisabled("CollisionComponent", false)
  92.                 cameraFollow(playerEntity)
  93.             end
  94.         },
  95.         {
  96.             type = ActionType.GoTo,
  97.             entity = playerEntity,
  98.             destinationEntity = teleportDestination
  99.         }
  100.     }
  101.  
  102.     return actions
  103. end
  104.  
  105. return makeCutscene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement