Fidgeting Shopkeeper


Author: Mastaba
Created: 2013-03-02T23:10:07-0500
Edited: 2013-03-06T22:10:06-0500
Denizen Version: .8.8
Views: 126
Downloads: 962
Likes: 1


WGET
Description: This contains a script intended to be used as a framework to add a store or other interactive npc. On spawn, the npc will wander around aimlessly around a central location. If the player clicks, they will return to the center and further interaction will be possible. When the player then leaves, the npc will continue 'fidgeting'. If you use this framework run the fidgeting script on multiple kinds of npcs, make sure that their interact scripts have different names.

.asint bug has been fixed, this now works properly in all quadrants.

Update: 3/6/12
-made a slightly cleaner despawn (still needs work)
-added ability for npc to sit if it ends movement or within one block of a wooden slab. For the sake of reliability, I have required the wood slab "chairs" to be on the same y level as the npc when it is assigned. you can replace flag.npc:fs_spawny with npc.location.y in that gigantic IF statement if you want to have chairs that are on different y levels, but it seems to occasionally take data from the level below. Since this is random and interactive, I opted for normal slabs rather than stairs. I prefer the abstraction of slabs as stools in my particular builds but Im sure you could adapt stairs to be used.
-added some more random dialogue options
-increased the length of some of the delays (need to make these adjustable constants)
-gave npc a fixed spawn location on assignment, which always use as the default center point
-made the npc lookclose while waiting to move again

# Updated: 3/6/2013
# for Denizen 0.8.8+
# requires citizens2 and craftbukkit
# Place these scripts in the /plugins/Denizen/scripts folder.
 
# From here to the task 'buystuffexample' is the framework for an npc that is using the fidgeting script.
# You could get by with less, but I've included some basic flair to give that immersive feeling.
"Shopkeeper":
    type: assignment

    default constants:
# X-axis wander radius
        Width: 5
# Z-axis wander radius
        Depth: 5
        Delay: 10s
        Speed: 5

    interact scripts:
    - 10 Interact Script

    actions:
        on assignment:
            - flag npc "fs_spawnx:<npc.location.x>"
            - flag npc "fs_spawnz:<npc.location.z>"
            - flag npc "fs_spawny:<npc.location.y>"
            - flag npc "fs_spawny:<flag.n:fs_spawny.asint>"

        on spawn:
            - execute as_npc speed 0.5
            - trigger name:click toggle:true radius:3
            - trigger name:chat toggle:true radius:5
            - trigger name:proximity toggle:true cooldown:1 radius:10
            - flag npc "fs_spawned:true"
            - flag npc "fs_attention:false"
            - flag npc "fs_defaultx:<flag.n:fs_spawnx>"
            - flag npc "fs_defaultz:<flag.n:fs_spawnz>"
            - runtask "script:Fidgeting" queue

        on despawn:
            - flag npc "fs_spawned:false"

        on complete navigation:
            - ^runtask "script:fs_scanforchair"
 

"Interact Script":
    type: interact

    steps:
        1:
            click trigger:
                script:
                - random 2
                - chat "I'll be with you in one moment."
                - chat "Just a minute, honey."
                - ^flag npc "fs_attention:true"
                - zap 2 "script:Interact Script"
            proximity trigger:
                entry:
                    script:
                    - random 2
                    - chat "You look like a man with taste."
                    - chat "See anything you like?"
        2:
            proximity trigger:
                exit:
                    script:
                    - chat "Goodbye."
                    - ^flag npc "fs_attention:false"
                    - lookclose toggle:false
                    - runtask "script:Fidgeting" queue
                    - zap 1 "script:Interact Script"

            click trigger:
                script:
                - chat "Looking for something... special?"
                - runtask "script:buystuffexample"

"buystuffexample":
    type: task
    script:
    - chat "Please browse my fine wares."
 
 
# Here is the meat of the fidgeting script, put this in a separate file for convienience. 
"Fidgeting":
    type: task

    script:
    - runtask "script:fs_genrandoms" instantly
    - if "<flag.n:fs_spawned>" == "true" && "<flag.n:fs_attention>" == "false"
      runtask "script:fs_walk" queue
      else if "<flag.n:fs_spawned>" == "false" runtask "script:fs_despawn"
      else runtask "script:fs_waittoleave"

"fs_genrandoms":
    type: task

    script:
    - ^flag npc "fs_randomx:<util.random.int[0].to[<cons:Width>]>"
    - ^flag npc "fs_randomz:<util.random.int[0].to[<cons:Depth>]>"
    - ^flag npc "fs_randomposx:<flag.n:fs_defaultx>"
    - random 2
    - ^flag npc "fs_randomposx:-:<flag.n:fs_randomx>"
    - ^flag npc "fs_randomposx:+:<flag.n:fs_randomx>"
    - ^flag npc "fs_randomposx:<flag.n:fs_randomposx.asint>"
    - ^flag npc "fs_randomposz:<flag.n:fs_defaultz>"
    - random 2
    - ^flag npc "fs_randomposz:-:<flag.n:fs_randomz>"
    - ^flag npc "fs_randomposz:+:<flag.n:fs_randomz>"
    - ^flag npc "fs_randomposz:<flag.n:fs_randomposz.asint>"
 

"fs_walk":
    type: task

    script:
    - stand
    - walkto "location:<flag.n:fs_randomposx>,<npc.location.y>,<flag.n:fs_randomposz>,<npc.location.world>"
    - lookclose toggle:true
    - wait 10
    - lookclose toggle:false
    - runtask "script:Fidgeting" queue
 

"fs_return":
    type: task

    script:
    - stand
    - walkto "location:<flag.n:fs_defaultx>,<npc.location.y>,<flag.n:fs_defaultz>,<npc.location.world>"
    - lookclose toggle:true
    - wait 20
    - lookclose toggle:false
    - runtask "script:Fidgeting" queue

"fs_waittoleave":
    type: task

    script:
    - walkto "location:<flag.n:fs_defaultx>,<npc.location.y>,<flag.n:fs_defaultz>,<npc.location.world>"
    - lookclose toggle:true

"fs_despawn":
    type: task

    script:
    - chat "Take this job and shove it!"

"fs_scanforchair":
    type: task

    script:
    - ^flag npc "fs_scanx1:<npc.location.x>"
    - ^flag npc "fs_scanx2:<npc.location.x>"
    - ^flag npc "fs_scanz1:<npc.location.z>"
    - ^flag npc "fs_scanz2:<npc.location.z>"
    - ^flag npc "fs_scanx1:+:1"
    - ^flag npc "fs_scanx2:-:1"
    - ^flag npc "fs_scanz1:+:1"
    - ^flag npc "fs_scanz2:-:1"
    - ^flag npc "fs_scanx1:<flag.n:fs_scanx1.asint>"
    - ^flag npc "fs_scanx2:<flag.n:fs_scanx2.asint>"
    - ^flag npc "fs_scanz1:<flag.n:fs_scanz1.asint>"
    - ^flag npc "fs_scanz2:<flag.n:fs_scanz2.asint>"
    - if "<location[<npc.location>].block.material>" == "WOOD_STEP" sit "location:<npc.location>"
      else if "<location[<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>"
      else if "<location[<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<npc.location.z>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<npc.location.z>,<npc.location.world>"
      else if "<location[<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx1>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>"
      else if "<location[<npc.location.x>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<npc.location.x>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>"
      else if "<location[<npc.location.x>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<npc.location.x>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>"
      else if "<location[<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<flag.n:fs_scanz1>,<npc.location.world>"
      else if "<location[<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<npc.location.z>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<npc.location.z>,<npc.location.world>"
      else if "<location[<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>].block.material>" == "WOOD_STEP" sit "location:<flag.n:fs_scanx2>,<flag.npc:fs_spawny>,<flag.n:fs_scanz2>,<npc.location.world>"




Comments
No one has posted a comment! Post one below: