Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Routine: Nearby

1cec0ld edited this page Oct 9, 2012 · 5 revisions

Nearby is a powerful routine that enables many new kinds of interaction. Basically it allows you to go through every entity near one of the named event entities and do something with/to them.

Syntax

- 'nearby.{entity}.{filter}.{radius}':
    - 'more routines here'

{entity} - One of the standard event entities, i.e. attacker, target, projectile
{filter} - An entity type to filter for. All entities chosen by nearby will match this type.
{radius} - Some expression for the cube radius to search in.

How it works

Inside the nearby routine, the it entity reference refers to the selected nearby entity.

There is also a nearest variant to select and run the routine on only the closest entity that the filter catches.

- 'nearest.{entity}.{filter}.{radius}':
    - 'more routines here'

Examples

Zombie Knockback Helmet

In this example, the Chainmail Helmet becomes a powerful zombie repellant. Anytime a zombie attacks you while you're wearing one, all zombies within 10 blocks get thrown back.

Damage:
    - 'if target.wearing.CHAINMAIL_HELMET and attacker.type.Zombie':
        - 'message.target.FOOM!'
        - 'nearby.target.Zombie.10':
            - 'iteffect.knockback': '10'

Blood absorber/healer

You are a strange cross between a vampire and a healer. Anytime you kill a mob that's not undead (undead doesn't have blood), all your buddies close by get healed for 10% of the mob's maximum health.

Death:
    - 'if attacker.type.player and !(target.type.zombie or target.type.skeleton)':
        - 'nearby.attacker.Player.8':
            - 'iteffect.heal': '(target_maxhealth / 10)'

Spawn mobs only near players

Note: This is could be a bit slow. A nearby conditional will be a better solution (if it gets added)

Spawn:
    - '0' # default to canceling the spawn
    - 'nearby.target.Player.50':
        - 'target_maxhealth' # set their health back to the default
    # at this point, the health will be 0 if no players were found, 
    # or the default maximum health for the entity if one or more was found
Clone this wiki locally