Make an event appear
Description
In this example, changing one variable changes the onChanges method for the other events. Here, it's a way of issuing instructions on other events
Structure
Files
female.ts
import { RpgEvent, EventData, RpgPlayer } from '@rpgjs/server'
@EventData({
name: 'EV-1'
})
export default class CharaEvent extends RpgEvent {
onInit() {
this.setGraphic('female')
this.setHitbox(16, 16)
}
async onAction(player: RpgPlayer) {
if (player.getVariable('CAT')) {
await player.showText(`I already have a cat`, {
talkWith: this
})
return
}
await player.showText(`I'm going to make a cat appear`, {
talkWith: this
})
player.setVariable('CAT', true)
}
}
cat.ts
import { RpgEvent, EventData, RpgPlayer } from '@rpgjs/server'
@EventData({
name: 'EV-2'
})
export default class CatEvent extends RpgEvent {
onChanges(player: RpgPlayer) {
if (player.getVariable('CAT')) {
this.setGraphic('cat')
this.setHitbox(16, 16)
}
}
async onAction(player: RpgPlayer) {
player.showText(`I am a cat`, {
talkWith: this
})
}
}