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

From Citizens Wiki

< Denizen‎ | 0.7

No edit summary
No edit summary
Line 20: Line 20:


====The Click Trigger====
====The Click Trigger====
Clicking on a Denizen NPC can activates the Click Trigger, which is probably the main method of interacting with a NPC. Simple scripts can be carried out with a Click Trigger Quick Script, like below.
Clicking on a Denizen NPC can activates the Click Trigger or Damage Trigger, depending on which buttom was pressed. This is probably the easiest and most straight-forward way to interact with a NPC.


{{codebox|height=250px|Right click to speak, left click hurts!|<syntaxhighlight line='false' lang="yaml">
{{codebox|height=250px|Right click to speak, left click hurts!|<syntaxhighlight line='false' lang="yaml">
# A basic QUICK SCRIPT with a click trigger.  
# A basic QUICK SCRIPT with a click trigger and damage trigger.
# Note: Unless your npc is VULNERABLE (use /npc vulnerable -t),
# the Denizen won't take any automatic damage on a Damage Trigger.
# It must be handled and dealt with by using commands.
#  
#  
# ---- Assignments.yml
# ---- Assignments.yml


Denizens:
Denizens:
   'Notch':
   'Jeremy':
     Quick Scripts:
     Quick Scripts:
       Click Trigger:
       Click Trigger:
Line 34: Line 37:
         - CHAT "Here, have a shovel."
         - CHAT "Here, have a shovel."
         - DROP STONE_SPADE
         - DROP STONE_SPADE
      Damage Trigger:
        Script:
        - CHAT "Hey, what was that for?"
</syntaxhighlight>
</syntaxhighlight>
}}  
}}  

Revision as of 13:57, 20 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!

Denizen Basics

Though Denizen can be very advanced, it can perform very simple tasks, as well. Most of the basics can be covered with a QUICK SCRIPT. Check out these examples.

The Click Trigger

Clicking on a Denizen NPC can activates the Click Trigger or Damage Trigger, depending on which buttom was pressed. This is probably the easiest and most straight-forward way to interact with a NPC.


Code: Right click to speak, left click hurts!
{{{2}}}


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

Random chat is nice, but controlling the flow of conversation and events is just as important. 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

Another good way to control the flow of multiple scripts is by using the SCRIPT requirement, which can check if the player has completed or failed scripts. Since 'Quest, part 2' requires the completion of 'Quest, part 1', the player will be forced to complete the scripts in an order set forth by the arguments in the 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 be used to control sequence of a script. 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 from these characters, somehow, one at a time.


Code: A sample 'Karma' reward system.
{{{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.