Paste #77240: Untitled Paste

Date: 2020/11/07 05:58:33 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


world:

  type: world

  events:

    on player right clicks end_portal_frame:

    # If player has ships
    - if <player.has_flag[ships]>:

      # Test if ship is player's
      - define counter 1
      - define blShip false

      - foreach <player.flag[ships]>:

        # Tests if ship in dock is player's ship.
        - if <script[<[value]>].data_key[location]> == <context.location>:
          - flag player nShipId:<[counter]>
          - define blShip true

        - define counter:++

      - if <[blShip]>:

        - repeat 28:
          - define controllist:->:i@air

        - define controllist[11]:i@stone_button[display_name=Hyperdrive]
        - define "controllist[12]:i@stone_button[display_name=Sublight Drive]"
        - define "controllist[13]:i@stone_button[display_name=Landing Jets]"
        - define "controllist[17]:i@map[display_name=Navigation Computer]"

        - note "<inventory[generic[title=Flight Control;size=45;contents=<[controllist]>]]>" as:flight_control
        - inventory open d:flight_control

      #- else:
        #- narrate "Access Denied"



    on player clicks in flight_control:

    - define ship <player.flag[ships].get[<player.flag[nShipId]>]>
    - define model <script[<[ship]>].data_key[model]>
    - define location <script[<[ship]>].data_key[location]>
    - define dock <script[<[ship]>].data_key[dock]>
    - define worldName <location[<[location]>].world.name>

    # Hyperdrive

    - if <context.item> == "i@stone_button[display_name=Hyperdrive]":
      - if <[worldName]> == "Space":
        - if <player.has_flag[destination]>:

          - inventory close d:flight_control
          - narrate "Engaging Hyperdrive engine..."
          - wait 1

          - define xneg <util.random.int[1].to[2]>
          - define yneg <util.random.int[1].to[2]>
          - define xloc <util.random.int[60].to[100]>
          - define yloc <util.random.int[60].to[100]>

          - if <[xneg]> == 1:
            - define xloc:*:-1
          - if <[yneg]> == 1:
            - define yloc:*:-1

          - define planetaryOffset <location[<script[<player.flag[destination]>].data_key[center]>].add[<[xloc]>,0,<[yloc]>]>

          - cast blindness duration:2
          - cast slow duration:2 amplifier:10
          - wait 1
          - playeffect effect:FIREWORKS_SPARK at:<player.location> visibility:100 quantity:500 data:0.5 offset:0.8

          - ^schematic load name:<[model]>
          - ~schematic paste name:<[model]> <[planetaryOffset]> noair
          - ^schematic unload name:<[model]>

          - teleport <player> <[planetaryOffset].add[0,0,-2]>

          - ^schematic load name:<[model]>_blank
          - ^schematic paste name:<[model]>_blank <[location]>
          - ^schematic unload name:<[model]>_blank

          - narrate "We have arrived at <player.flag[destination]>."

          - ~yaml load:scripts/_ships_player.yml id:fileShips
          - yaml id:fileShips set <[ship]>.location:<[location]>
          - ~yaml savefile:scripts/_ships_player.yml id:fileShips
          - yaml unload id:fileShips

          - flag player destination:!
          - flag player nShipId:!

        - else:
          - narrate "Destination not set."
      - else:
        - narrate "You must exit the planet's gravitational field to activate the Hyperdrive engine."


    # Sublight Drive

    - else if <context.item> == "i@stone_button[display_name=Sublight Drive]":

      # Test if trying to enter a world
      - if <[worldName]>  == "Space":

        # Count vacant hangars
        - define counterreg 1
        - define nHangarId 0
        - define blFirst true

        - foreach <server.flag[<script[<[dock]>_hangars]>]>:
          - if <[value]> == "vacant":
            - if <[blFirst]> == "true":
              - define nHangarId <[counterreg]>
              - define blFirst false
          - define counterreg:++

        # If no vacant hangars             
        - if <[blFirst]> == "true":
          - random:
            - chat "There aren't any hangars available at the moment I'm afraid."
            - chat "I'm sorry, they're all occupied currently."
            - chat "You'll have to wait for one to become available."

        # Else if hangars are vacant
        - else: 

          # Define location as the center of the hangar plus the ship navigation offset
          - define hangarOffest <location[<script[<[dock]>_hangar_<[nHangarId]>].data_key[center]>].add[<script[<[model]>_data].data_key[offsetX]>,<script[<[model]>_data].data_key[offsetY]>,<script[<[model]>_data].data_key[offsetZ]>]>

          - ^schematic load name:<[model]>
          - ~schematic paste name:<[model]> <[hangarOffest].add[0,50,0]> noair
          - ^schematic unload name:<[model]>

          - teleport <player> <[hangarOffest].add[0,50,-2]>

          - ^schematic load name:<[model]>_blank
          - ^schematic paste name:<[model]>_blank <[location]>
          - ^schematic unload name:<[model]>_blank

          - ~yaml load:scripts/_ships_player.yml id:fileShips
          - yaml id:fileShips set <[ship]>.location:<[hangarOffest]>
          - ~yaml savefile:scripts/_ships_player.yml id:fileShips
          - yaml unload id:fileShips

          - flag server <location[<[hangarOffest]>].world.name>_hangars[<[nHangarId]>]:<[ship]>
          - execute as_server "dmarker update id:<script[<location[<[hangarOffest]>].world.name>_hangar_<[nHangarId]>].data_key[marker]> icon:yellowflag"

      # Else if trying to enter space      
      - else:

        # If ship is not docked
        - if <location[<[dock]>].add[<script[<[model]>_data].data_key[offsetX]>,<script[<[model]>_data].data_key[offsetY]>,<script[<[model]>_data].data_key[offsetZ]>]> != <[location]>:

          - define xneg <util.random.int[1].to[2]>
          - define yneg <util.random.int[1].to[2]>
          - define xloc <util.random.int[60].to[100]>
          - define yloc <util.random.int[60].to[100]>

          - if <[xneg]> == 1:
            - define xloc:*:-1
          - if <[yneg]> == 1:
            - define yloc:*:-1

          - define planetaryOffset <location[<script[<[worldName]>].data_key[center]>].add[<[xloc]>,0,<[yloc]>]>

          - ^schematic load name:<[model]>
          - ~schematic paste name:<[model]> <[planetaryOffset].add[0,50,0]> noair
          - ^schematic unload name:<[model]>

          - teleport <player> <[planetaryOffset].add[0,50,-2]>

          - ^schematic load name:<[model]>_blank
          - ^schematic paste name:<[model]>_blank <[location]>
          - ^schematic unload name:<[model]>_blank

          - define counterreg 1

          # Update server flags to say hangar now vacant
          - foreach <server.flag[<[worldName]>_hangars]>:
            - if <[value]> == <[ship]>:
              - flag server <[worldName]>_hangars[<[counterreg]>]:vacant
              - execute as_server "dmarker update id:<script[<[worldName]>_hangar_<[counterreg]>].data_key[marker]> icon:greenflag"
            - define counterreg:++


          - ~yaml load:scripts/_ships_player.yml id:fileShips
          - yaml id:fileShips set <[ship]>.location:<[planetaryOffset]>
          - yaml id:fileShips set <[ship]>.dock:<[planetaryOffset].world.name>
          - ~yaml savefile:scripts/_ships_player.yml id:fileShips
          - yaml unload id:fileShips


        # Else if ship is docked
        - else:
          - narrate "Sublight Drive can't be activated while docked."

    # Landing Jets

    - else if <context.item> == "i@stone_button[display_name=Landing Jets]":
      - if <[worldName]> != "Space":
        - if <location[<[dock]>].add[<script[<[model]>_data].data_key[offsetX]>,<script[<[model]>_data].data_key[offsetY]>,<script[<[model]>_data].data_key[offsetZ]>]> == <[location]>:

          - ^schematic load name:<[model]>
          - ~schematic paste name:<[model]> <location[<[location]>].add[0,50,0]> noair
          - ^schematic unload name:<[model]>

          - teleport <player> <location[<[location]>].add[0,50,-2]>

          - ^schematic load name:<[model]>_blank
          - ^schematic paste name:<[model]>_blank <[location]>
          - ^schematic unload name:<[model]>_blank


          - ~yaml load:scripts/_ships_player.yml id:fileShips
          - yaml id:fileShips set <[ship]>.location:<location[<[location]>].add[0,50,0]>
          - ~yaml savefile:scripts/_ships_player.yml id:fileShips
          - yaml unload id:fileShips

          - narrate "Dock cleared."

        - else:

          - ^schematic load name:<[model]>
          - ~schematic paste name:<[model]>  <location[<[location]>].add[0,-50,0]> noair
          - ^schematic unload name:<[model]>

          - teleport <player> <location[<[location]>].add[0,-50,-2]>

          - ^schematic load name:<[model]>_blank
          - ^schematic paste name:<[model]>_blank <[location]>
          - ^schematic unload name:<[model]>_blank


          - ~yaml load:scripts/_ships_player.yml id:fileShips
          - yaml id:fileShips set <[ship]>.location:<location[<[location]>].add[0,-50,0]>
          - ~yaml savefile:scripts/_ships_player.yml id:fileShips
          - yaml unload id:fileShips

          - narrate "Docked."

      - else: 
        - narrate "Landing jets are of little use in Space!."

    # Navigation Computer

    - else if <context.item> == "i@map[display_name=Navigation Computer]":
      - inventory close d:flight_control
      - narrate "Loading navigational maps..."

      # Max 15
      - if <location[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[location]>].world.name> != "Space":
        - define gridX <script[<location[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[location]>].world.name>].data_key[gridX]>
      - else:
        - define gridX <script[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[dock]>].data_key[gridX]>
      - define gridX:-:4
      - if <[gridX]> < 1:
        - define gridX 1
      - if <[gridX]> > 15:
        - define gridX 15

      # Max 16
      - if <location[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[location]>].world.name> != "Space":
        - define gridY <script[<location[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[location]>].world.name>].data_key[gridY]>
      - else:
        - define gridY <script[<script[<player.flag[ships].get[<player.flag[nShipId]>]>].data_key[dock]>].data_key[gridY]>
      - define gridY:-:3
      - if <[gridY]> < 1:
        - define gridY 1
      - if <[gridY]> > 16:
        - define gridY 16

      - flag player counterY:<[gridY]>

      - repeat 6:

        - flag player counterX:<[gridX]>

        - repeat 9:
          - flag player maplist:->:<script[space].data_key[grid].get[<player.flag[counterY]>].get[<player.flag[counterX]>]>
          - flag player counterX:++
        - flag player counterY:++

      - note <inventory[generic[title=Navigation;size=54;contents=<player.flag[maplist]>]]> as:mapinv
      - inventory open d:mapinv

      - flag player counterX:!
      - flag player counterY:!
      - flag player maplist:!

    - determine cancelled

    on player clicks void|point in inventory:

    - narrate "Destination set: <context.item.lore.get[1]>"
    - flag player destination:<context.item.lore.get[1]>

    - inventory close d:<context.clicked_inventory>
    - inventory open d:flight_control

    - determine cancelled


    #on player death:

    #- if <player.has_flag[hangars]>:
    #  - foreach <player.flag[hangars]>:
    #    # remove associated astromech
    #    - define sublist <server.flag[hangars].get[<[value]>]>
    #    - remove <def[sublist].get[1]>

    #    # set global hangar flag to vacant
    #    - flag server hangars[<[value]>]:vacant

    #  # remove hangar flag from player
    #  - flag player hangars:!


    on entity targets player:

    - if <player.has_flag[sith]>:
      - if <context.entity.name> == skeleton || <context.entity.name> == wither_skeleton || <context.entity.name> == stray || <context.entity.name> == zombie || <context.entity.name> == husk || <context.entity.name> == drowned:
        - determine cancelled
      - else:
        - attack <context.entity.location.find.entities[skeleton].within[20]> target:<context.entity>
        - attack <context.entity.location.find.entities[wither_skeleton].within[20]> target:<context.entity>
        - attack <context.entity.location.find.entities[stray].within[20]> target:<context.entity>
        - attack <context.entity.location.find.entities[zombie].within[20]> target:<context.entity>
        - attack <context.entity.location.find.entities[husk].within[20]> target:<context.entity>
        - attack <context.entity.location.find.entities[drowned].within[20]> target:<context.entity>

    on entity damages player:
    - if <player.has_flag[sith]>:
      - attack <context.entity.location.find.entities[skeleton].within[20]> target:<context.entity>
      - attack <context.entity.location.find.entities[wither_skeleton].within[20]> target:<context.entity>
      - attack <context.entity.location.find.entities[stray].within[20]> target:<context.entity>
      - attack <context.entity.location.find.entities[zombie].within[20]> target:<context.entity>
      - attack <context.entity.location.find.entities[husk].within[20]> target:<context.entity>
      - attack <context.entity.location.find.entities[drowned].within[20]> target:<context.entity>