# RpgEvent

# @EventData decorator

Summary


# mode

  • Property: mode
  • Type: string
  • Optional: true
  • Usage:

The mode of the event, shared evening or scenario

The scenario mode allows you to have events specific to the player. Thus, the graphics, the positions of the event will be different for each player. Beware of performance! The event is duplicated by each player.

shared mode by default

import { RpgEvent, EventData, RpgPlayer, EventMode } from '@rpgjs/server'
@EventData({
     name: 'EV-1',
     mode: EventMode.Scenario // or EventMode.Shared
})
export class CharaEvent extends RpgEvent { }

# hitbox

  • Property: hitbox
  • Type: { width: number, height: number }
  • Optional: true
  • Usage:

The hitbox of the event. By default, this is the size of the tile of the map


# name

  • Property: name
  • Type: string
  • Optional: false
  • Usage:

Name of the event. This is its identifier. it allows you to retrieve an event and place it on the map

# RpgEvent Hooks

An event has hooks that will be called according to the life cycle of the event.

Full example:

import { RpgEvent, EventData, RpgPlayer } from '@rpgjs/server'

@EventData({
    name: 'EV-1'
})
export class CharaEvent extends RpgEvent {
    onInit() { }

    onChanges(player: RpgPlayer)

    onAction(player: RpgPlayer) { }

    onPlayerTouch(player: RpgPlayer) { }
}

Info

Note that RpgEvent inherits from RpgPlayer, you can use all of the player's commands

# onInit()

As soon as the event is created, this method is called

# onChanges()

this method is called as soon as any event on the map (including itself) is executed

import { RpgEvent, EventData, RpgPlayer } from '@rpgjs/server'

@EventData({
    name: 'EV-1'
})
export class CharaEvent extends RpgEvent {
    onChanges(player: RpgPlayer) {
        if (player.getVariable('BATTLE_END')) {
            this.graphic('chest-open')
        }
        else {
            this.graphic('chest-close')
        }
    }
}

Above, as soon as the variable BATTLE_END is set to true (and this change is made by another event), then the graph of the event will change automatically

# onAction()

If the event collides with the player and the player presses the action key, the method is called

# onPlayerTouch()

If the event collides with the player, the method is called