Denizen/Additional Traits

From Citizens Wiki
Jump to: navigation, search

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.

Mobprox 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.

Mobprox 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

Mobprox 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.

MobProx action fire timing:

  • Flag name is "mobprox_timer"
  • Set to 4 by default
  • Can be any integer number, but between 1 and 10 is recommended.
  • Keep in mind, 1 means fire actions every half second, 2 means every second, 4 means every two seconds, and so on.

Mobprox 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
        - trigger name:click state:true
        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>
          }
    interact scripts:
    - 10 mobproxexample_interact

mobproxexample_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                - chat target:<player> "Hello, I'm a mob researcher! I'm looking for interesting mobs to classify!"
                - chat target:<player> "But I'm deathly afraid of creepers! Luckily a wizard taught me a spell to cast lightning!"