Paste #567: dTravelers 2.1

Date: 2013/12/15 01:36:09 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# | dTravelers 2.1: NPCs to help you travel around the world!
# 
# | WARNING: dTravelers 2 location save data is incompatible with original dTravelers save data!
#          It is also incompatible with copies of the original dTravelers script!
#          However, unlocked names will stay.
# 
# | 2.1:
# ... make it actually work now! (Only ops could use 2.0 ! oops!)
# | 2:
# Updated, reworked, etc. Travel locations saved globally now, new commands, can link areas by permission rather than unlock, and so on.
# | 1:
# Original dTravelers
# 
# | To create a dTraveler:
# /npc create [Name]                        ## [Name] is the name of the NPC
# /npc assign --set dtraveler_assign        ## All literal
# /dtraveler name [NameOfTravelLocation]    ## OPTIONAL. [NameOfTravelLocation] is the name of the location to link to this NPC.
# 
# | To create a travel location:
# /dtraveler add [NameOfTravelLocation]     ## [NameOfTravelLocation] is what you want to call this location
#                                           ## Remember not to make two of the same name!
#                                           ## Note: the location will be placed precisely where you are standing
# 
# | To remove a travel location:
# /dtraveler remove [NameOfTravelLocation]  ## [NameOfTravelLocation] is the name of the location you want to remove
# 
# | To go to a travel location without using an NPC:
# /dtravel goto [NameOfTravelLocation]      ## [NameOfTravelLocation] is the name of the location you want to go to
# 
# | Player interaction:
# Click on a dTraveler to unlock it.
# You can speak the name of any travel location to a traveler to go there.
# You can also say 'list' to a traveler to see what locations you've unlocked.
# 
# | Commands:
# /dtraveler add [NameOfTravelLocation]     ## Adds a travel location
# /dtraveler remove [NameOfTravelLocation]  ## Removes a travel location
# /dtravel goto [NameOfTravelLocation]      ## Teleports you to a travel location
# /dtraveler name [NameOfTravelLocation]    ## Links an NPC to a travel location
# /dtraveler unname                         ## Unlinks an NPC from its travel location
# 
# | Permissions:
# denizen.scripts.dtravelers.add            ## Use the 'add' and 'remove' commands
# denizen.scripts.dtravelers.goto           ## Use the 'goto' command
# denizen.scripts.dtravelers.name           ## Use the 'name' and 'unname' commands
# denizen.scripts.dtravelers.[NameOfLoc]    ## Permits travel to a given travel location even if you haven't unlocked it

dtraveler_world_commands:
    type: world
    events:
        on dtraveler command:
        - determine passively fulfilled
        - IF <player> == "null" {
          - announce to_console format:dtraveler_format_warning "<&4>Only players can use this command!"
          - queue clear
          }
        - if <player.has_permission[denizen.scripts.dtravelers.goto]> != "true" && <player.has_permission[denizen.scripts.dtravelers.add]> != "true" && <player.has_permission[denizen.scripts.dtravelers.name]> != "true" {
          - narrate format:dtraveler_format_warning "You do not have permission to use this command."
          - queue clear
          }
        - if <context.args.size> == 2 && <context.args.get[1]> == "add" {
          - run dtraveler_command_add instantly def:<context.args.get[2]>
          - queue clear
          }
        - if <context.args.size> == 2 && <context.args.get[1]> == "remove" {
          - run dtraveler_command_remove instantly def:<context.args.get[2]>
          - queue clear
          }
        - if <context.args.size> == 2 && <context.args.get[1]> == "goto" {
          - run dtraveler_command_goto instantly def:<context.args.get[2]>
          - queue clear
          }
        - if <context.args.size> == 2 && <context.args.get[1]> == "name" {
          - run dtraveler_command_name instantly def:<context.args.get[2]>
          - queue clear
          }
        - if <context.args.size> == 1 && <context.args.get[1]> == "unname" {
          - run dtraveler_command_unname instantly
          - queue clear
          }
        - narrate format:dtraveler_format_warning "Incorrect command arguments..."
        - narrate "<&c>/dtraveler add [NameOfTravelLocation]"
        - narrate "<&c>/dtraveler remove [NameOfTravelLocation]"
        - narrate "<&c>/dtraveler goto [NameOfTravelLocation]"

dtraveler_command_goto:
    type: task
    script:
    - if <player.has_permission[denizen.scripts.dtravelers.goto]> != "true" {
      - narrate format:dtraveler_format_warning "You do not have permission to use this command."
      - queue clear
      }
    - flag server dtraveler_cutoff:false
    - repeat <server.flag[dtraveler_location_names].size> {
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_cutoff:true
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag player dtraveler_target:<server.flag[dtraveler_locations].get[%value%]>
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% run dtraveler_task_travel delay:1t
      }
    # Note: Repetition above is intentional for complex reasons.
    - if <server.flag[dtraveler_cutoff]> == "true" {
      - queue clear
      }
    - narrate format:dtraveler_format_warning "That travel location doesn't exist!"

dtraveler_command_name:
    type: task
    script:
    - if <player.has_permission[denizen.scripts.dtravelers.name]> != "true" {
      - narrate format:dtraveler_format_warning "You do not have permission to use this command."
      - queue clear
      }
    - if <player.selected_npc> == "null" {
      - narrate format:dtraveler_format_warning "You must have a selected NPC to use this command."
      - queue clear
      }
    - flag server dtraveler_cutoff:false
    - repeat <server.flag[dtraveler_location_names].size> {
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_cutoff:true
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag <player.selected_npc> dtraveler_name:%1%
      }
    # Note: Repetition above is intentional for complex reasons.
    - if <server.flag[dtraveler_cutoff]> == "true" {
      - narrate format:dtraveler_format_valid "NPC successfully linked to travel location '<&b>%1%<&2>'."
      - queue clear
      }
    - narrate format:dtraveler_format_warning "That travel location doesn't exist!"

dtraveler_command_unname:
    type: task
    script:
    - if <player.has_permission[denizen.scripts.dtravelers.name]> != "true" {
      - narrate format:dtraveler_format_warning "You do not have permission to use this command."
      - queue clear
      }
    - if <player.selected_npc> == "null" {
      - narrate format:dtraveler_format_warning "You must have a selected NPC to use this command."
      - queue clear
      }
    - flag <player.selected_npc> dtraveler_name:null
    - narrate format:dtraveler_format_valid "NPC successfully unlinked from any travel locations."

dtraveler_command_add:
    type: task
    script:
    - if <player.has_permission[denizen.scripts.dtravelers.add]> != "true" {
      - narrate format:dtraveler_format_warning "You do not have permission to use this command."
      - queue clear
      }
    - flag server dtraveler_cutoff:false
    - repeat <server.flag[dtraveler_location_names].size> {
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_cutoff:true
      }
    - if <server.flag[dtraveler_cutoff]> == "true" {
      - narrate format:dtraveler_format_warning "That travel location already exists!"
      - queue clear
      }
    - flag server dtraveler_location_names:->:%1%
    - flag server dtraveler_locations:->:<player.location>
    - narrate format:dtraveler_format_valid "Added travel location '<&b>%1%<&2>'!"

dtraveler_command_remove:
    type: task
    script:
    - if <player.has_permission[denizen.scripts.dtravelers.remove]> != "true" {
      - narrate format:dtraveler_format_warning "You do not have permission to use this command."
      - queue clear
      }
    - flag server dtraveler_cutoff:false
    - repeat <server.flag[dtraveler_location_names].size> {
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_cutoff:true
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_locations[%value%]:<-
      - if <server.flag[dtraveler_location_names].get[%value%]> == %1% flag server dtraveler_location_names[%value%]:<-
      }
    # Note: Repetition above is intentional for complex reasons.
    - if <server.flag[dtraveler_cutoff]> == "true" {
      - narrate format:dtraveler_format_valid "Travel location successfully removed."
      - queue clear
      }
    - narrate format:dtraveler_format_warning "That travel location doesn't exist!"

dtraveler_assign:
    type: assignment
    actions:
        on assignment:
        - TRIGGER name:click state:true
        - TRIGGER name:chat state:true
    interact scripts:
    - 10 dtraveler_interact_main

dtraveler_interact_main:
    type: interact
    steps:
        1:
            click trigger:
                script:
                - if <npc.flag[dtraveler_name]> != "null" && <player.flag[dtraveler_named_<npc.flag[dtraveler_name]>]> != "true" {
                  - flag player dtraveler_named_<npc.flag[dtraveler_name]>:true
                  - narrate format:dtraveler_format_valid "You've found a new travel location!"
                  - playsound <player.location> level_up
                  }
                - chat "<&2>Hello there, <player.name>!"
                - wait 1
                - if <npc.flag[dtraveler_name]> != "null" {
                  - chat "<&2>I'm <&b><npc.name.nickname><&2>, the official travel master of <&b><npc.flag[dtraveler_name]><&2>!"
                  }
                  else {
                  - chat "<&2>I'm <&b><npc.name.nickname><&2>, an official serverwide travel master!"
                  }
                - wait 2
                - chat "<&2>My job is to take you places you've been before. Simply name the place and I'll get you there."
                - ^flag player dtraveler_hasresponded:false
                - run dtraveler_task_hello delay:10s
            chat trigger:
                1:
                    trigger: "I need to see a /list/ of what places I've unlocked..."
                    script:
                    - ^flag player dtraveler_hasresponded:true
                    - wait 1
                    - flag player dtraveler_temptext:<&2>
                    - foreach <server.flag[dtraveler_location_names].aslist> {
                      - flag player dtraveler_temp:%value%
                      - if <proc:dtraveler_proc_cantravel> flag player "dtraveler_temptext:<player.flag[dtraveler_temptext]>%value%, "
                      }
                    - if <player.flag[dtraveler_temptext].length> < 4 {
                      - chat "<&2>Well, I'm sorry. It seems you haven't unlocked any travel locations yet."
                      }
                      else {
                      - chat "<&2>If I've heard right, you've been to the following locations<&co>"
                      - narrate "<player.flag[dtraveler_temptext]>"
                      }
                    - wait 2
                    - if <player.flag[dtraveler_temptext].length> >= 4 chat "<&2>So... which one would you like to go to?"
                2:
                    trigger: "/REGEX:.+/"
                    script:
                    - ^flag player dtraveler_hasresponded:true
                    - wait 1
                    - ^flag player dtravel_success:false
                    - ^repeat <server.flag[dtraveler_location_names].size> {
                      - flag player dtraveler_temp:<server.flag[dtraveler_location_names].get[%value%]>
                      - ^if <context.message> contains <server.flag[dtraveler_location_names].get[%value%]> && <proc:dtraveler_proc_cantravel> {
                        - ^chat "<&2>To <server.flag[dtraveler_location_names].get[%value%]>? Alright then..."
                        - ^flag player dtraveler_target:<server.flag[dtraveler_locations].get[%value%]>
                        - ^run dtraveler_task_travel delay:1t
                        - ^flag player dtravel_success:true
                        }
                      }
                    - ^if <player.flag[dtravel_success]> != "true" {
                      - ^chat "<&2>You haven't unlocked such a location."
                      }
                    - wait 1
                    - if <player.flag[dtravel_success]> != "true" {
                      - narrate format:dtraveler_format_valid "If you've forgotten where you've been, just say <&b>list<&2> to the travel master!"
                      }

dtraveler_proc_cantravel:
    type: procedure
    script:
    - if <player.flag[dtraveler_named_<player.flag[dtraveler_temp]>]> == "true" { - determine "true" }
      else if <player.has_permission[denizen.scripts.dtravelers.<player.flag[dtraveler_temp]>]> { - determine "true" } else { - determine "false" }

dtraveler_task_hello:
    type: task
    script:
    - if <player.flag[dtraveler_hasresponded]> == "true" {
      - queue clear
      }
    - if <player.location.distance[<npc.location>]> > 20 {
      - queue clear
      }
    - narrate format:dtraveler_format_valid "If you've forgotten where you've been, just say <&b>list<&2> to the travel master!"

dtraveler_task_travel:
    type: task
    script:
    - narrate format:dtraveler_format_valid "Traveling..."
    - ^playsound <player.location> portal_travel
    - ^playeffect <player.location> large_explode
    - ^cast blindness duration:5s
    - cast confusion duration:8s
    - wait 1
    - teleport <player> <player.flag[dtraveler_target]>
    - ^playsound <player.location> portal_travel
    - playeffect <player.location> large_explode

dtraveler_format_warning:
    type: format
    format: "<&7>[<&2>dTravelers<&7>]: <&c><text>"

dtraveler_format_valid:
    type: format
    format: "<&7>[<&2>dTravelers<&7>]: <&2><text>"