Denizen/Additional Traits: Difference between revisions

From Citizens Wiki
No edit summary
No edit summary
Line 93: Line 93:
         - flag npc mobprox_acceptnpcs:false
         - flag npc mobprox_acceptnpcs:false
         on mob enter proximity:
         on mob enter proximity:
         - if <context.entity.entity_type> != "creeper"
         - if <context.entity.entity_type> != "creeper" {
           announce "<&7>[<npc.name>]<&2> I see a mob! It's a <context.entity.entity_type>!"
           announce "<&7>[<npc.name>]<&2> Here's a mob! It's a <context.entity.entity_type>!"
          - if <context.entity.can_see[<npc>]> == false
            announce "<&7>[<npc.name>]<&2> I can't see it though <&co>("
          }
         on mob exit proximity:
         on mob exit proximity:
         - if <context.entity.entity_type> != "creeper"
         - if <context.entity.entity_type> != "creeper"
Line 103: Line 106:
         - announce "<&7>[<npc.name>]<&2> Oh good, the creeper's gone!"
         - announce "<&7>[<npc.name>]<&2> Oh good, the creeper's gone!"
         on creeper move proximity:
         on creeper move proximity:
         - announce "<&7>[<npc.name>]<&2> I cast lightning on you, creeper!"
         # Note: don't use player-type npc. or player. can_see, always use context.entity.can_see
        - strike <context.entity.location>
        # Due to a bug in Bukkit
        - if <context.entity.can_see[<npc>]> == true {
          - announce "<&7>[<npc.name>]<&2> I cast lightning on you, creeper!"
          - strike <context.entity.location>
          }
</pre>
</pre>

Revision as of 07:17, 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> Here's a mob! It's a <context.entity.entity_type>!"
          - if <context.entity.can_see[<npc>]> == false
            announce "<&7>[<npc.name>]<&2> I can't see it though <&co>("
          }
        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:
        # Note: don't use player-type npc. or player. can_see, always use context.entity.can_see
        # Due to a bug in Bukkit
        - if <context.entity.can_see[<npc>]> == true {
          - announce "<&7>[<npc.name>]<&2> I cast lightning on you, creeper!"
          - strike <context.entity.location>
          }