Paste #34895: Edit of P#34893 Camera Utilities

Date: 2016/07/17 02:46:23 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


CameraUtil_Version:
  type: version
  name: "Camera Utilities"
  id: 102
  description: "Player's Camera utilities."
  version: 0.01

CameraUtil:
  type: task
  debug: false
  speed: 0t
  definitions: action|location
  script:
  - if <def[action]> == attach {
    - inject locally detach
    - inject locally create
    - teleport <def[location]>
    - wait 1t
    - inject locally attach
    - queue clear
    }
  - if <def[action]> == detach {
    - inject locally detach
    }
  create:
  - spawn e@CameraUtil_Entity <def[location]> save:x
  - define attach_to <entry[x].spawned_entities.first>
  - flag <player> camerautil_attached_to:<def[attach_to]>
  attach:
  - define to <player.flag[camerautil_attached_to].as_entity||null>
  - if <def[to]> != null {
    - flag <player> camerautil_lastgamemode:<player.gamemode>
    - adjust <player> gamemode:spectator
    - async {
      - while <player.has_flag[camerautil_attached_to]> {
        - adjust <player> spectate:<def[to]>
        - wait 10t
        }
      }
    }
  detach:
  - if <player.has_flag[camerautil_attached_to]> {
    - if <player.has_flag[camerautil_lastgamemode]> {
      - adjust <player> gamemode:<player.flag[camerautil_lastgamemode]>
      - flag <player> camerautil_lastgamemode:!
      }
    - define as <player.flag[camerautil_attached_to]>
    - flag <player> camerautil_attached_to:!
    - adjust <player> spectate:<player>
    - remove <def[as]>
    }

CameraUtil_Listener:
  type: world
  debug: false
  events:
    on player quits:
    - inject CameraUtil detach
    on world unload:
    - foreach <context.world.entities.filter[scriptname.is[==].to[CameraUtil_Entity]]> {
      - remove <def[value]>
      }

CameraUtil_Entity:
  type: entity
  debug: false
  entity_type: e@armor_stand
  gravity: false
  visible: false
  invulnerable: true