Denizen/0.7/Example Scripts/Beginner Scripts: Difference between revisions

From Citizens Wiki

< Denizen‎ | 0.7

No edit summary
No edit summary
Line 130: Line 130:


====A Simple Multiple Requirement Script====
====A Simple Multiple Requirement Script====
{{codebox|height=250px|Interact Script conversation with the ZAP command.|<syntaxhighlight line='false' lang="yaml">
{{codebox|height=250px|Two scripts are better than one.|<syntaxhighlight line='false' lang="yaml">
# A script that shows the behavior of multiple assignments.
# A script that shows the behavior of multiple assignments.
#  
#  
Line 154: Line 154:
         - NARRATE "You have clicked on script 1."
         - NARRATE "You have clicked on script 1."


'Script 1':
'Script 2':
   Type: Interact
   Type: Interact
   Requirements:
   Requirements:
Line 171: Line 171:




====Script sequencing with the SCRIPT requirement====
{{codebox|height=250px|You must do them in order!|<syntaxhighlight line='false' lang="yaml">
# A script that shows the behavior of multiple assignments.
#
# ---- Assignments.yml
Denizens:
  Jimmy:
    Interact Scripts:
    - 10 Quest, part 1
    - 20 Quest, part 2
# ---- Multiple Scripts.yml
'Quest, part 1':
  Type: Interact
  Requirements:
    Mode: None
  Steps:
    1:
      Click Trigger:
        Script:
        - ^FINISH
        - NARRATE 'And with no warning...
        - NARRATE '...you embark on a quest, filled with danger.'
'Quest, part 2':
  Type: Interact
  Requirements:
    Mode: All
    List:
    - SCRIPT FINISHED 'SCRIPT:Quest, part 1'
  Steps:
    1:
      Click Trigger:
        Script:
        - CHAT AS_PLAYER "Uhh.. can I at least have a sword?"
        - LOOK AT
        - CHAT "Yes, I suppose that would be wise... check the attic.'
</syntaxhighlight>
}}
====Script sequencing with FLAGS====
This script is more of an intermediate script, but shows how flags can completely change how you use Denizen. In this example, multiple NPCs are part of this karma example. Note: Scottie's Script/Jason's Script/etc. are not shown, and aren't necessarily important to this example, but it is assumed that the player collects karma somehow, '''one at a time'''.
{{codebox|height=250px|Complete with generic texts!|<syntaxhighlight line='false' lang="yaml">
# A script that shows the behavior of multiple assignments.
#
# ---- Assignments.yml
Denizens:
  Scottie:
    Interact Scripts:
    - 10 Scottie's Script
    - 100 ^Karma Check
  Jason:
    Interact Scripts:
    - 10 Jason's Script
    - 100 ^Karma Check
  Jeb:
    Interact Scripts:
    - 10 Jeb's Script
    - 100 ^Karma Check
# ---- Multiple Scripts.yml
'Karma Check':
  Type: Interact
  Requirements:
    Mode: Any
    List:
    - FLAGGED EXACTLY KARMA:10
    - FLAGGED EXACTLY KARMA:50
    - FLAGGED EXACTLY KARMA:100
  Steps:
    1:
      Click Trigger:
        Script:
        - CHAT "Wow, <PLAYER>, sorry to interrupt, but you've certainly racked up some karma!"
        - RUNTASK 'SCRIPT:Karma reward <FLAG.PLAYER:KARMA>'
# These 'TASK' scripts are only used when called upon.
'Karma reward 10':
  Type: Task
  Script:
  - NARRATE "Alright! You have 10 karma! Here's a reward.."
  - GIVE BREAD QTY:10
'Karma reward 50':
  Type: Task
  Script:
  - NARRATE "Whoa! You have 50 karma! Here's a reward.."
  - GIVE GOLD_INGOT QTY:25
'Karma reward 100':
  Type: Task
  Script:
  - NARRATE "Holy bejezzus! 100 KARMA?! Here's a reward.."
  - GIVE GOLDEN_APPLE QTY:5
</syntaxhighlight>
}}






This is the script from the start-up kit. It's 2 interact scripts assigned to 1 Denizen named Steve. He will respond different to a right-click by a player depending on whether or not the player has the modifyworld.* permission.
{| class="wikitable collapsible collapsed"  
{| class="wikitable collapsible collapsed"  
! Joe the Builder Script and Assignment
! Joe the Builder Script and Assignment

Revision as of 20:08, 19 September 2012

Sometimes the best way to learn is by looking at some examples. The following beginner scripts use basic denizen commands and requirements to provide some nice basic functionality for your Denizens.

Example scripts are provided with both the assignments and the scripts in the same box. Be sure and put the text in the correct file in your plugins folder.
  • Assignments should always be appended to plugins\Denizen\assignments.yml
  • Scripts can be placed in any .yml file in the plugins\Denizen\scripts\ directory. Remember: You can have multiple scripts per file!



and now... the scripts!


Simple, random conversations

A great way to provide some nice immersion into your world is as simple as a basic interaction with a Denizen NPC outputting a random response. There are a couple different ways this can be done, as provided in the examples below. Since this concept is simple, it can be done with a Quick Script as well as an Interact Script.

A conversation with RANDOM

Code: Quick Script conversation with the RANDOM command.
{{{2}}}


A conversation with ZAP RANDOM

Code: Interact Script conversation with the ZAP command.
{{{2}}}


Notch's Cookies

Code: Notch loves cookies, and RANDOM chat.
{{{2}}}


Multiple Scripts & Requirements

One of the best features of Denizen's Interact Scripts is the requirements system, which can be used to control multiple scripts. Imagine NPCs greeting players based on weather, or having conversations only when on a quest. For further understanding, you should check out [Denizen/Script Assignments#Multiple Scripts], but take these examples below to get a basic understanding.


A Simple Multiple Requirement Script

Code: Two scripts are better than one.
{{{2}}}


Script sequencing with the SCRIPT requirement

Code: You must do them in order!
{{{2}}}


Script sequencing with FLAGS

This script is more of an intermediate script, but shows how flags can completely change how you use Denizen. In this example, multiple NPCs are part of this karma example. Note: Scottie's Script/Jason's Script/etc. are not shown, and aren't necessarily important to this example, but it is assumed that the player collects karma somehow, one at a time.


Code: Complete with generic texts!
{{{2}}}


Basic Repeatable Fetch Quest

Here is the fastest way to do a repeatable 'fetch' quest. Useful for custom crafting-type NPCs. Once the player agrees to help, he can turn in the items as often as he wants to receive the reward.

Basic Unrepeatable Fetch Quest

By adding 3 lines to the script above, it becomes un-repeatable.

The Race

Coach wants you to RUN, BOY! This script uses a TASK script and a Location trigger to make a timed race for the player. Good example of ZAP and RUNTASK/CANCELTASK command usage. Be sure and define a Location Bookmark called 'theTree' using the /denizen bookmark location command.