Denizen/Additional Traits: Difference between revisions

From Citizens Wiki
(Created page with "You can add even further Denizen features by enabling various traits. You can add traits by simply selecting the NPC and doing doing <pre>/trait <traitname></pre> EG <pre>...")
 
No edit summary
Line 12: Line 12:


= Mobprox Trait =
= Mobprox Trait =
Mobprox is short for "Mob Proximity". It enables a [http://wiki.citizensnpcs.com/Denizen/Triggers#Proximity_Trigger proximity trigger]-like functionality, but for mobs instead of players.
When the trait is assigned, it is assumed the NPC has a Denizen script assigned.
== Actions ==
The mobprox trait will fire the following actions on the Denizen script:
<pre>
on mob enter proximity:
on mob exit proximity:
on mob move proximity:
on <mobname> enter proximity:
on <mobname> exit proximity:
on <mobname> move proximity:
</pre>
"mob" actions fire whenever <b>any</b> mob does the action.
&lt;mobname&gt; actions fire whenever <b>a specific mob</b> does the action.
&lt;mobname&gt; is the name of the mob, EG "zombie" or "creeper".
"enter" actions fire when a mob walks into range. It will fire again if the mob walks out and back in.
"exit" actions fire when a mob leaves range. It will fire again if the mob walks in and back out.
"move" actions fire whenever a mob has been in range and continues to be in range. It doesn't necessarily mean the mob actually moved.
Note that the actions don't run instantly, it can take up to 2 seconds before they are called. (Usually a bit faster)
Also note that sometimes several actions will be called all at almost the same time, if there are multiple entities in range.
== Tags ==
In each action, you can use the [http://wiki.citizensnpcs.com/Denizen/Replaceable_Tags Replaceable Tag] "&lt;<context.entity&gt;" (With the &lt;&gt; included, quotes aren't needed) to refer to the mob in question.
You can check for matching details with an if command using the tag, like
<pre>
- if <context.entity.entity_type> == "creeper" CommandHere
</pre>
or similar.
One tag that's very useful with the mobprox trait is &lt;entity.can_see[<entity>]&gt; - you can use this to check if the entity is visible to the NPC by doing:
<pre>
- if <npc.can_see[<context.entity>]> CommandHere
</pre>
== Flags ==
Additionally, you can modify the mobprox behavior using NPC flags:
MobProx Range:
* Flag name is "mobprox_range"
* Set to 10 by default
* Can be any integer number, but it's recommended you don't exceed 100
* Keep in mind, this is cubic range, not spherical range. Meaning, if the range is 10, and the mob is 9 blocks left and 9 blocks forward, it's still considered to be in range.
Whether to accept NPC mobs as mobprox triggers:
* flag name is "mobprox_acceptnpcs"
* Set to false by default
* Can be true or false. True means NPC mobs or real mobs will fire the mobprox actions, false means only real non-NPC mobs will fire the mobprox actions.
* Keep in mind, if you want NPCs to interact when they get near each other, there's better ways to do it than mobprox actions. Only set this true if you want NPC mobs treated exactly the same as real mobs.
== Example ==
For an example, create an NPC and assign the script below using "/npc assign --set mobproxexample" then enable the trait with "/trait mobprox"
<pre>'mobproxexample':
    type: assignment
    actions:
        on assignment:
        - flag npc mobprox_range:20
        - flag npc mobprox_acceptnpcs:false
        on mob enter proximity:
        - if <context.entity.entity_type> != "creeper"
          announce "<&7>[<npc.name>]<&2> I see a mob! It's a <context.entity.entity_type>!"
        on mob exit proximity:
        - if <context.entity.entity_type> != "creeper"
          announce "<&7>[<npc.name>]<&2> Goodbye, <context.entity.entity_type>!"
        on creeper enter proximity:
        - announce "<&7>[<npc.name>]<&2> Aahh! Creeper! Die creeper!"
        on creeper exit proximity:
        - announce "<&7>[<npc.name>]<&2> Oh good, the creeper's gone!"
        on creeper move proximity:
        - announce "<&7>[<npc.name>]<&2> I cast lightning on you, creeper!"
        - strike <context.entity.location>
</pre>

Revision as of 06:38, 10 August 2013

You can add even further Denizen features by enabling various traits.

You can add traits by simply selecting the NPC and doing doing

/trait <traitname>

EG

/trait mobprox

And use the same command again to remove them

Mobprox Trait

Mobprox is short for "Mob Proximity". It enables a proximity trigger-like functionality, but for mobs instead of players.

When the trait is assigned, it is assumed the NPC has a Denizen script assigned.

Actions

The mobprox trait will fire the following actions on the Denizen script:

on mob enter proximity:
on mob exit proximity:
on mob move proximity:
on <mobname> enter proximity:
on <mobname> exit proximity:
on <mobname> move proximity:

"mob" actions fire whenever any mob does the action.

<mobname> actions fire whenever a specific mob does the action.

<mobname> is the name of the mob, EG "zombie" or "creeper".

"enter" actions fire when a mob walks into range. It will fire again if the mob walks out and back in.

"exit" actions fire when a mob leaves range. It will fire again if the mob walks in and back out.

"move" actions fire whenever a mob has been in range and continues to be in range. It doesn't necessarily mean the mob actually moved.


Note that the actions don't run instantly, it can take up to 2 seconds before they are called. (Usually a bit faster)

Also note that sometimes several actions will be called all at almost the same time, if there are multiple entities in range.

Tags

In each action, you can use the Replaceable Tag "<<context.entity>" (With the <> included, quotes aren't needed) to refer to the mob in question.

You can check for matching details with an if command using the tag, like

- if <context.entity.entity_type> == "creeper" CommandHere

or similar.

One tag that's very useful with the mobprox trait is <entity.can_see[<entity>]> - you can use this to check if the entity is visible to the NPC by doing:

- if <npc.can_see[<context.entity>]> CommandHere

Flags

Additionally, you can modify the mobprox behavior using NPC flags:

MobProx Range:

  • Flag name is "mobprox_range"
  • Set to 10 by default
  • Can be any integer number, but it's recommended you don't exceed 100
  • Keep in mind, this is cubic range, not spherical range. Meaning, if the range is 10, and the mob is 9 blocks left and 9 blocks forward, it's still considered to be in range.

Whether to accept NPC mobs as mobprox triggers:

  • flag name is "mobprox_acceptnpcs"
  • Set to false by default
  • Can be true or false. True means NPC mobs or real mobs will fire the mobprox actions, false means only real non-NPC mobs will fire the mobprox actions.
  • Keep in mind, if you want NPCs to interact when they get near each other, there's better ways to do it than mobprox actions. Only set this true if you want NPC mobs treated exactly the same as real mobs.

Example

For an example, create an NPC and assign the script below using "/npc assign --set mobproxexample" then enable the trait with "/trait mobprox"

'mobproxexample':
    type: assignment
    actions:
        on assignment:
        - flag npc mobprox_range:20
        - flag npc mobprox_acceptnpcs:false
        on mob enter proximity:
        - if <context.entity.entity_type> != "creeper"
          announce "<&7>[<npc.name>]<&2> I see a mob! It's a <context.entity.entity_type>!"
        on mob exit proximity:
        - if <context.entity.entity_type> != "creeper"
          announce "<&7>[<npc.name>]<&2> Goodbye, <context.entity.entity_type>!"
        on creeper enter proximity:
        - announce "<&7>[<npc.name>]<&2> Aahh! Creeper! Die creeper!"
        on creeper exit proximity:
        - announce "<&7>[<npc.name>]<&2> Oh good, the creeper's gone!"
        on creeper move proximity:
        - announce "<&7>[<npc.name>]<&2> I cast lightning on you, creeper!"
        - strike <context.entity.location>