Repeatable Kill Quest - Timer

Author: mythanical
Created: 2013-02-22T09:00:17-0500
Edited: 2014-01-12T03:48:30-0500
Denizen Version: 0.9.3
Views: 226
Downloads: 1590
Likes: 7

Description: Kill the Bats - Repeatable Quest on Timer
Denizen 0.9.3 (build #1417)
Citizens 2 (build #1045)

To assign to an NPC, type:
/npc assign --set "Bat Killer"

This will ask the player to kill a few bats and will reward them for doing so.

It uses the "listen" command to determine whether the player has killed
any bats, but unfortunately doesn't allow control over WHERE the bats have been killed.

The quest repeat timeout constant value controls how often the player can repeat the quest.

# Kill the Bats
# Citizens 2 (build #1045)
# Denizen 0.9.3 (build #1417)
# This will ask the player to kill a few bats and will reward them for doing so.
# It uses the "listen" command to determine whether the player has killed
# any bats, but unfortunately doesn't allow control over WHERE the bats have been killed.
# The quest repeat timeout constant value below will control how often the 
# player can repeat the quest. It's on 24 hours currently.
# NOTE: This requires an economy to deal with 'money' as a method of reward.
# @author mythanical
# @script version 1.0.3
# @last-updated 12 January 2014
# @irc EsperNet IRC Network #denizen-dev
# @Minecraft Server -
# @Donate Bitcoin: 1Fzacc2gZ5NGRMXg5jWP6NcUkWei34xjzt
# @Donate Litecoin: LhsaGa1QzmVLjMYwg4ZPTVnmSgnBDGc75U

"Bat Killer":
  type: assignment

  default constants:

    # Number of bats that must be killed for quest to be completed
    BatsQty: 3
    # The reward (money) for killing the bats
    RewardAmount: 300
    # The time in between each repeat of the quest (currently set at 24 hours)
    Quest Repeat Timeout: 86400
    # Reset all quest progress (this is in case quest gets stuck or if the 'kill listener' stops 'listening'
    Quest Reset Timeout: 86400
    # Name of your town, used in some dialog options.
    Townname: 'Arrowin'

  interact scripts:
  - 10 Killing the Bats

    on assignment:
    - trigger name:chat toggle:true
    - trigger name:click toggle:true
    - trigger name:proximity toggle:true
    - trigger name:damage toggle:true
    # Make the NPC so they can be killed by the player. They will respawn a few seconds later.
    - execute as_npc "npc sel <>"
    - execute as_npc "npc vulnerable"
    # When a player kills the NPC, narrate something. On my server, I run another script instead that 
    # changes the alignment of the player for commiting such a heinous act.
    on death by player:
    - narrate "<red>You have killed <yellow><><red>. Are you pleased with yourself?"

"Killing the Bats":
  type: interact
      proximity trigger:
          # On player entering proximity range, run a script (located further down).
          - run "Batkiller Check Requirements"

      click trigger:
        # On clicking, run a slightly different script to check requirements before starting quest.
        - run "Batkiller Quest Requirement"

      damage trigger:
        # When you hit the NPC, it will run the script called Batkiller Warning (further below).
        - run "Batkiller Warning"

      chat trigger:
        'Start Questline':
          Trigger: /Yes/, I am interested. I'll start now.
          # If the player answer 'yes', this will set the quest flag to started and also start 'listening' for the player
          # killing bats and once the player killed the number of bats specified at the top of the script, it will run
          # the 'Batkiller Quest Completed' script.
          - engage
          - flag <player> BatKiller:Started "duration:<npc.constant[Quest Reset Timeout]>"
          - listen kill "id:Batkiller Listener" type:entity qty:<npc.constant[BatsQty]> target:bat "script:Batkiller Quest Completed"
          - chat "<yellow>Great! come back to me once you've killed <red><npc.constant[BatsQty]><yellow> bats."
          - narrate "<red> Exterminate Bats - Quest Started"
          - disengage

        'Deny Questline':
          Trigger: /No/, I am not interested.
          # If the player says 'no', then display one of the following 3 messages and put them back at Step 1 for 'Killing
          # the Bats' script.
          - random {
            - chat "<yellow>Oh ok, don't come crying to me if the noise these bast..I mean bats make wake you up at night."
            - chat "<yellow>That is really unfortunate, but OK. Come back to me when you change your mind."
            - chat "<yellow>It would've been a great help if you could get rid of these plagued bats. Please come back later." }
          - zap step:1
      proximity trigger:
          # If they exit the proximity trigger for the NPC, put them back at Step 1 so they get presented with the
          # relevant options when they come back later.
          - zap step:1

      click trigger:
        # This is simply to present the options again if the player accidentally clicks the NPC, rather than type a response.
        - run "Batkiller Quest Requirement"

      damage trigger:
        - run "Batkiller Warning"

"Batkiller Check Requirements":
  type: task

  # The following options exist here
  # 1) If the player is holding a sword in their hand, the NPC will run the 'Deny Interaction' script until the player put
  #  their weapon away.
  # 2) The next if statement checks to see if the quest has been flagged as 'Started', if so tell them to come back when all the bats
  #  have been killed.
  # 3) Otherwise if the flag is set to 'ClaimReward', tell the player to come get the reward.
  # 4) Lastly, if none of the 'if' statements are met, simply present them with the general chat dialog.
  - if 267|268|272|276 contains <> run "Deny Interaction"
    else if <player.flag[BatKiller]> == Started chat "<yellow>Hi <white><><yellow>, please come back to me when you've killed all <red><npc.constant[BatsQty]><yellow> bats!"
    else if <player.flag[BatKiller]> == ClaimReward chat "<white><><yellow>, come over here! Come get your <gold>reward<yellow> for killing those pesky bats!"
    else if <player.flag[BatKiller]> == Claimed chat "<yellow>Thanks for your help <white><><yellow>, please come back later to help me again."
    else run "Batkiller General Chat"

"Batkiller General Chat":
  type: task

  # These are the general chats that come up when the player walks into proximity range.
  - ^random {
    - chat "<yellow>And then he said 'She ate the rat!'. Hahahaha.. oh, sorry. Didn't see you there <white><><yellow>."
    - chat "<yellow>These sewers.. they get to you. Voices, chills..there are more than bats down here."
    - chat "<yellow>Some days I hate my job, but then I say 'No <white><><yellow>, you love your job' and then I love it again."
    - chat "<yellow>Rats, bats, cats and giant gnats. I kill them all.. it's great because I get paid to hunt for my own food!"
    - chat "<yellow>The smell in these sewers will get into your clothes. Remember to put your clothes in a bucket of water for 3 days, then wash it with soap."
    - chat "<yellow>Stay down here long enough, the sewers grow on you. Much like the moss on these bricks.."
    - chat "<yellow>Another day in the sewers..or night, I don't know anymore. Are you here to help?" }

"Batkiller Warning":
  type: task

  # When you hit (damage) the NPC, they will respond with one of the following lines.
  - ^random {
    - chat "<red>Oucch! <yellow>Why would you do that? If I die, you WILL regret it!"
    - chat "<red>Aaarrggg! <yellow>What did I ever do to you? Don't hit me again!"
    - chat "<red>Wha..why are you hurting me? <yellow>Oh, these cuts..they hurt so much."
    - chat "<red>Please don't hurt me! <yellow>I have never done anything bad to you!"
    - chat "<red>Owwee! <yellow>Don't do something now that you will regret later.." }

"Deny Interaction":
  type: task

  # If the player has a weapon, the NPC will say one of the following things.
  - ^random {
    - chat "<yellow>Oh, why do you come to me armed? Please put away your weapon first."
    - chat "<yellow>Is that a..weapon in your hand? Please don't hurt me! You might regret it."
    - chat "<white><npc.constant[Townname]><yellow> is a friendly town, please put your weapon away!"
    - chat "<yellow>It's courtesy to put your weapon away while talking to people in <white><npc.constant[Townname]><yellow>."
    - chat "<yellow>Why is a weapon necessary here? Are we engaging in some kind of fight?" }

"Batkiller Quest Requirement":
  type: task

  # This part is for when the player clicks the NPC. The options that exist are the same as the
  # check requirements above except this time if the BatKiller flag is on 'ClaimReward', it will run the 'Batkiller Quest
  # Completed Reward' script further below.
  - if 267|268|272|276 contains <> run "Deny Interaction"
    else if <player.flag[BatKiller]> == Started chat "<yellow>Hi <white><><yellow>, please come back to me when you've killed all <red><npc.constant[BatsQty]><yellow> bats!"
    else if <player.flag[BatKiller]> == Claimed chat "<yellow>Thanks for your help <white><><yellow>, please come back in <red><player.flag[BatKiller].expiration.formatted><yellow> to help me again."
    else if <player.flag[BatKiller]> == ClaimReward run "Batkiller Quest Completed Reward"
    else run "Batkiller Present Quest"

"Batkiller Present Quest":
  type: task

  # This part presents the player with the quest, giving them some details via random dialog options
  # and then asks them to answer 'yes' or 'no' before 'zapping' them to Step 2 in the script 'Killing the Bats'
  # where it's waiting for the player to type something.
  - random {
    - chat "<yellow>Hello there <white><><yellow>! Can you please help me get rid of these darn bats?"
    - chat "<yellow>Oh hey <white><><yellow>, there are some nasty bats in these sewers. Will you go kill some for me?"
    - chat "<yellow>Bats... bats everywhere! Their squeaky high-pitched noises driving me nuts. Kill some for me?"
    - chat "<yellow>These bats carry the plague! We need to exterminate them. Will you help me?"
    - chat "<yellow>Feel like slicing and dicing some bats? Grab yourself a sword and pretend you are a fruit ninja!" }
  - random {
    - chat "<yellow>I will pay you <gold><npc.constant[RewardAmount]><yellow> <> if you kill <red><npc.constant[BatsQty]><yellow> bats for me."
    - chat "<yellow>How does <gold><npc.constant[RewardAmount]><yellow> <> for <red><npc.constant[BatsQty]><yellow> bats sound to you?"
    - chat "<yellow>The reward for killing <red><npc.constant[BatsQty]><yellow> bats is <gold><npc.constant[RewardAmount]><yellow> <>. Interested?" }
  - narrate "<red>Say<&co>"
  - ^narrate "  <blue>Yes<blue> <gray>or<red> No"
  - ^zap "[email protected] the Bats" step:2

"Batkiller Quest Completed":
  type: task

  # When the 'listen' command detects the necessary quantity of bats killed, it will run this scripts and also
  # update the flag to 'ClaimReward' which the NPC will check to decide if the user should be rewarded.
  - narrate "<red>Exterminate Bats - Quest Completed. Return to <aqua><><red> to claim your reward."
  - ^flag <player> BatKiller:ClaimReward

"Batkiller Quest Completed Reward":
  type: task

  # This is the part where the flag expiry duration is determined from the constant value you set at the top of the script. After that
  # time, the flag expires and the quest can be done again. In this section the player is also rewarded (money) by the quantity specified
  # above.
  - ^flag <player> BatKiller:Claimed "duration:<npc.constant[Quest Repeat Timeout]>"
  - random {
    - chat "<yellow>Haha, good job <white><><yellow>, you got those bats good! You can come back and help me again tomorrow."
    - chat "<yellow>Well done <white><><yellow>, that will teach those pesky bats! You can come back and help me again tomorrow."
    - chat "<yellow>Fantastic <white><><yellow>, but they will be back again tomorrow. Please come help me again and I'll pay you for the service." }
  - ^give money qty:<npc.constant[RewardAmount]>
  - ^narrate "<red><> pays you <gold><npc.constant[RewardAmount]><red> <>."

2013-02-23 01:29:24 - Inyolius:

Your scripts are awesome, I love all of the included stuff! However, Quest Repeat Timeout needs to be changed to QuestRepeatTimeout, or else it will just keep giving you the reward script. Here's a copy with changes:
2013-02-23 01:50:53 - mythanical:

Sorry, apologies for that! Instead of changing the the name I simply had to add quotes. Thank you
2013-07-30 19:07:57 - hunter_rich:

this looks great but I cant get it to work, the quest begins ok but does not count the bats killed, or zombies as I have changed it to zombies.
2013-07-30 19:14:35 - hunter_rich:

I tried again without changing anything and its still not counting bats killed. Any idea what could be causing this?
2013-08-01 18:50:21 - Kussie:

Having the same issue as the person above sadly. It's not registering when i kill the bats :/
2013-08-18 09:11:26 - mythanical:

Hi guys! Yes, there are currently issues with Listeners in Denizen. The devs know about it, just need some time to fix it up. I have logged a job for item (craft) listeners not working, but there are about 3 other listener types that aren't working either.
2013-09-10 11:20:21 - mythanical:

Kill listeners should now be working again! Please let me know if there are still any problems.
2013-12-17 10:00:06 - cubebix9000:

because im using 2 listeners im tring to create a quest stage check that check for 2 flags in one line but i cant seem to get it to work am i doing somwthing wrong? "slayer quest stage check": type: task script: - if "" == "none" runtask "script:slayer class 1" else if "" == "stage1" chat "oh, , you have not completed your tasks yet." else if "" == "stage2" chat "oh, , you have killed the requierd amount of zombies but you still need to collect flesh." else if "" == "stage3" chat "oh, , you have collected the amount of flesh needed but you still need to kill the zombies." else if "" == "stage2" && "" == "stage3" run "script:slayer stage three complete" else if "" == "stagefinal" runtask "script:slayer stage final complete" else runtask "script:slayer class 1"
2013-12-17 10:03:07 - cubebix9000:

whoops seems the tags did not paste in my bad here is a paste bin
2014-02-10 00:29:10 - djbeauchamp:

I'm not sure but I think the listeners are not working again? Here's my tweaked version of the script (modded for zombies) if anyone wants to look over my changes...
2014-02-18 16:16:04 - djbeauchamp:

Found the listener actually is working after reviewing the server logs My question now is, how do I modify the script so that the player receives feedback as they kill their target?
2014-06-10 23:01:20 - thor54:

this is the script of yours im canablizing for my privet 5 player server the bat killer kill quest in trying to change reward type to give the player 400xp any idea what that command line would be? changed qty of bats to 10 changed all chat lines from npc to a more interesting story about vampire bat killing her family... anyway im trying to give the player 400 XP but cant figure out the command line to do that any help would be greatly appreciated.