Paste #16710: Edit of P#16709 - SatyrQuest 0.0.2

Date: 2015/06/21 10:43:04 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


satyrquest_master:
    type: world
    debug: true
    events:
        on sq command:
          - if <player.selected_npc> == null {
            - narrate "<&7>Please select an npc before using SatyrQuest."
            - flag player QuestEditor:!
          }
          else if !<player.has_flag[QuestEditor]> {
            - if !<player.selected_npc.has_flag[StepCount]> {
              - flag <player.selected_npc> StepCount:->:0
            }
            - narrate "<&0>((<&8>((<&7>( S <&f>a <&e>t y <&6>r Q <&e>u e <&f>s t <&7>! )<&8>))<&0>))"
            - narrate "<&7>You are now in the quest editor for <player.selected_npc.name> (<player.selected_npc.id>)"
            - narrate "<&5>Quests involving this NPC:"
            - foreach <player.selected_npc.flag[Quests].as_list> {
              - narrate "<&7><&l>    <def[loop_index]> -  <&f><&o><def[value]>"
            }
            - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7>, <&d>rename <&7>or <&c>remove <&7>quests."
            - flag player QuestEditor:SelQuest
          }
          else {
            - narrate "<&7>Exited the quest editor. Have a nice day!"
            - flag player QuestEditor:!
            }
          - determine fulfilled

        on player chats:
          - if <player.flag[QuestEditor]> == SelQuest {
            - if <context.message.substring[0,3].to_lowercase> == "add " {
              - define string <context.message.substring[5]>
              - flag <player.selected_npc> Quests:->:%string%
              - flag <player.selected_npc> StepCount[<player.selected_npc.flag[Quests].as_list.find[%string%]>]:0
              - narrate "<&7>Added <&f><&o><context.message.substring[5]> <&7>to quests."
              - narrate "<&5>Quests involving this NPC:"
              - foreach <player.selected_npc.flag[Quests].as_list> {
                - narrate "<&7><&l>    -  <&f><&o><def[value]>"
              }
              - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7>, <&d>rename <&7>or <&c>remove <&7>quests."
              - determine cancelled
            }
            else if <context.message.substring[0,6].to_lowercase> == "remove " {
              - define string <context.message.substring[8]>
              - define quest <player.selected_npc.flag[Quests].as_list.find[%string%]>
              - flag <player.selected_npc> Quests:<-:%string%
              - repeat <player.selected_npc.flag[Stepcount].as_list.get[]> {
                - flag <player.selected_npc> StepDataQ%quest%S<def[value]>:!
                - flag <player.selected_npc> TriggerQ%quest%S<def[value]>:!
              }
              - flag <player.selected_npc> StepCount[<player.selected_npc.flag[Quests].as_list.find[<context.message.substring[8]>]>]:0
              - narrate "<&f><&o><context.message.substring[8]> <&7> was removed for this NPC, if it existed in the first place."
              - narrate "<&5>Quests involving this NPC:"
              - foreach <player.selected_npc.flag[Quests].as_list> {
                - narrate "<&7><&l>    -  <&f><&o><def[value]>"
              }
              - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7>, <&d>rename <&7>or <&c>remove <&7>quests."
              - determine cancelled
            }
            else if <context.message.substring[0,6].to_lowercase> == "rename " {
              - if <player.selected_npc.flag[Quests]> contains <context.message.substring[8]> {
                - define string <context.message.substring[8]>
                - flag player renameid:<player.selected_npc.flag[Quests].as_list.find[%string%]>
                - flag player QuestEditor:RenQuest
                - narrate "<&7>Enter a new name for <&f><&o>%string%<&7>."
              }
              - determine cancelled
            }
            else if <context.message.substring[0,4].to_lowercase> == "edit " {
              - if <player.selected_npc.flag[Quests].as_list> contains <context.message.substring[6]> {
                - define string <context.message.substring[6]>
                - flag player QuestEditID:<player.selected_npc.flag[Quests].as_list.find[%string%]>
                - narrate "<&7>Editing quest <&f><&o><context.message.substring[6]><&7>. (ID: <player.flag[QuestEditID]>)"
                - narrate "<&7>Steps: <&6><player.selected_npc.flag[StepCount].as_list.get[<player.flag[QuestEditID]>]].as_int>"
                - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7> and <&c>remove<&7> steps, or go <&3>back<&7>."
                - flag player QuestEditor:SelStep
              }
              - determine cancelled
            }
          }
          else if <player.flag[QuestEditor]> == RenQuest {
            - flag <player.selected_npc> Quests[<def[renameid]>]:<context.message>
            - narrate "<&7>Quest was renamed to <&f><&o><context.message><&7>."
            - flag player QuestEditor:SelQuest
            - foreach <player.selected_npc.flag[Quests].as_list> {
                - narrate "<&7><&l>    -  <&f><&o><def[value]>"
              }
              - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7>, <&d>rename <&7>or <&c>remove <&7>quests."
              - determine cancelled
          }
          else if <player.flag[QuestEditor]> == SelStep {
            - if <context.message.substring[0,3].to_lowercase> == "add " {
              - flag <player.selected_npc> StepCount[<player.flag[QuestEditID]>]:+:1
              - define questid <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - flag player CurrentStep:<player.selected_npc.flag[StepCount].as_list.get[%questid%].as_int>
              - narrate "<&7>Added a new step at index <&f>%step%<&7>."
              - narrate "<&7>Anything you type into chat will now be added to this step. Type <&3>back<&7> to return to the step selection menu, <&e>view<&7> to see any existing script, or <&b>edit<&7>, or <&c>remove<&7>. Don't forget to add a <&5>trigger<&7>."
              - flag player QuestEditor:StepEdit
              - determine cancelled
            }
            else if <context.message.substring[0,4].to_lowercase> == "edit " {
              - narrate "<&7>Editing step <&f><context.message.substring[6].as_int>"
              - flag player QuestEditor:StepEdit
              - flag player CurrentStep:<context.message.substring[6].as_int>
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - narrate "<&7>Anything you type into chat will now be added to this step. Type <&3>back<&7> to return to the step selection menu, <&e>view<&7> to see any existing script (<&c><player.selected_npc.flag[StepDataQ%quest%S%step%].as_list.size><&7> lines), or <&b>edit<&7>, or <&c>remove<&7>. Don't forget to add a <&5>trigger<&7>."
              - determine cancelled
            }
            else if <context.message.substring[0,6].to_lowercase> == "remove " {
              - flag <player.selected_npc> StepDataQ<player.flag[QuestEditID]>S<context.message.substring[8].as_int>:!
              - narrate "<&7>Step <&f><context.message.substring[8].as_int><&7> has been removed, however due to the way SatyrQuest currently works, it will leave behind a blank ID. You can type <&b>edit <&f><context.message.substring[8].as_int><&7> to put a new step in its place."
              - determine cancelled
            }
            else if <context.message.substring[0,4].to_lowercase> == "back " {
              - flag player QuestEditor:SelQuest
              - foreach <player.selected_npc.flag[Quests].as_list> {
                - narrate "<&7><&l>    -  <&f><&o><def[value]>"
              }
              - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7>, <&d>rename <&7>or <&c>remove <&7>quests."
              - determine cancelled
            }
          }
          else if <player.flag[QuestEditor]> == StepEdit {
            - if <context.message.substring[0,4].to_lowercase> == "back " {
              - define quest <player.flag[QuestEditID]>
              - narrate "<&7>Steps: <&6><player.selected_npc.flag[StepCount].as_list.get[%quest%]].as_int>"
              - narrate "<&7>You can <&a>add<&7>, <&b>edit<&7> and <&c>remove<&7> steps, or go <&3>back<&7>."
              - flag player QuestEditor:SelStep
              - determine cancelled
            }
            else if <context.message.substring[0,4].to_lowercase> == "edit "{
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - define string <context.message.substring[6].as_int>
              - narrate "<&c>%string% <&7><player.selected_npc.flag[StepDataQ%quest%S%step%].as_list.get[%string%]>"
              - narrate "<&7>Enter a new line to replace this."
              - flag player EditLine:%string%
              - flag player QuestEditor:EditScript
              - determine cancelled
            }
            else if <context.message.substring[0,4].to_lowercase> == "view "{
              - define viewstart <context.message.substring[6].as_int.max[0]>
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - foreach <player.selected_npc.flag[StepDataQ%quest%S%step%].as_list> {
                - narrate "<&c><def[loop_index]> <&7><def[value]>"
              }
              - determine cancelled
            }
            else if <context.message.substring[0,6].to_lowercase> == "remove "{
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - define string <context.message.substring[8].as_int>
              - flag <player.selected_npc> StepDataQ%quest%S%step%:<-:<player.selected_npc.flag[StepDataQ%quest%S%step%].as_list.get[%string%]>
              - narrate "<&7>The script at line <&c>%string%<&7> was deleted."
              - determine cancelled
            }
            else if <context.message.substring[0,7].to_lowercase> == "trigger "{
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - if <context.message.substring[9].to_lowercase> == "talk" {
                - narrate "<&7>Please click on an NPC to use as the trigger for this step."
                - flag player QuestEditor:SetNPC
              }
              else if <context.message.substring[9].to_lowercase> == "use" {
                - narrate "<&7>Please click on a usable block to use as the trigger for this step. (This includes, doors, trapdoors, chests, buttons, levers, pressure plates and tripwire hooks.)"
                - flag player QuestEditor:SetBlock
              }
              else if <context.message.substring[9].to_lowercase> == "near" {
                - narrate "<&7>Please click on an NPC to use as the trigger for this step."
                - flag player QuestEditor:SetNPC
              }
              else {
                - narrate "<&7>Please enter a valid trigger type after the word trigger. (talk|use|near)"
              }
              - determine cancelled
            }
            else {
              - define quest <player.flag[QuestEditID]>
              - define step <player.flag[CurrentStep]>
              - flag <player.selected_npc> StepDataQ%quest%S%step%:->:<context.message>
              - narrate "<&c><player.selected_npc.flag[StepDataQ%quest%S%step%].as_list.size> <&7><context.message>"
              - determine cancelled
            }
          }
          else if <player.flag[QuestEditor]> == EditScript {
            - define quest <player.flag[QuestEditID]>
            - define step <player.flag[CurrentStep]>
            - flag <player.selected_npc> StepDataQ%quest%S%step%[<player.flag[EditLine]>]:<context.message>
            - narrate "<&7>Line <&c><player.flag[EditLine]> <&7>changed to: <context.message>"
            - flag player QuestEditor:StepEdit
            - determine cancelled
          }
        on player right clicks block:
          - if <player.flag[QuestEditor]> == SetBlock {
            - if li@door|chest|button|lever|trapdoor|pressureplate|tripwirehook contains <context.location.material> {
            - flag <player.selected_npc> TriggerLoc[<player.flag[CurrentStep]>]:<context.location>
            - narrate "<&7>Trigger was successfully set to <&e><context.location.material><&7> at <&a><context.location><&7>."
            }
            else {
              - narrate "<&7>That (<&e><context.location.material><&7>) is not a valid trigger block. Try again."
            }
          }
        on player right clicks entity:
          - if <player.flag[QuestEditor]> == SetNPC {
            - if <context.entity.is_npc> == true {
            - define quest <player.flag[QuestEditID]>
            - define step <player.flag[CurrentStep]>
            - execute as_server "npc select <context.entity.id>"
            - execute as_server "npc assignment --set satyrquest_npc"
            - flag <player.selected_npc.flag[TriggerQ%quest%S%step%]> Triggers:<-:"<player.selected_npc.id>,<player.flag[QuestEditID]>,<player.flag[CurrentStep]>"
            - flag <player.selected_npc> TriggerQ%quest%S%step%:<context.entity.id>
            - flag <context.entity> "QTrigs:<-:<player.selected_npc.id>,<player.flag[QuestEditID]>,<player.flag[CurrentStep]>"
            - flag <context.entity> "QTrigs:->:<player.selected_npc.id>,<player.flag[QuestEditID]>,<player.flag[CurrentStep]>"
            - narrate "<&7>Trigger was successfully set to <&e><context.entity.name><&7> (<context.entity.id>)."
            - flag player QuestEditor:StepEdit
            }
          }
satyrquest_npc:
    type: assignment
    interact scripts:
    - 1 sqnpc

sqnpc:
    type: interact
    steps:
        1:
          click trigger:
            script:
            - if !<player.has_flag[QuestEditor]> {
              - foreach <npc.flag[QTrigs].as_list> {
                - define parentnpc n@<def[value].split[,].get[1]>
                - define quest <def[value].split[,].get[2]>
                - define step <def[value].split[,].get[3]>
                - foreach <def[parentnpc].flag[StepDataQ%quest%S%step%]> {
                  - narrate "Debug: <def[value]>"
                }
              }
            }