Using map.removeEvent('event-id') causes server freeze with below error in the console (sometimes it works, sometimes it doesn't):
Link to video
Uncaught TypeError: Cannot read properties of undefined (reading 'x')
at change (RpgClientEngine.js:404:1)
at SafeSubscriber._next (RpgClientEngine.js:418:1)
at SafeSubscriber../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:192:1)
at SafeSubscriber../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:130:1)
at Subscriber../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:76:1)
at Subscriber../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53:1)
at BehaviorSubject../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47:1)
at BehaviorSubject../node_modules/rxjs/_esm5/internal/BehaviorSubject.js.BehaviorSubject.next (BehaviorSubject.js:38:1)
at Socket.<anonymous> (world.js:41:1)
at Socket../node_modules/component-emitter/index.js.Emitter.emit (index.js:145:1)
change @ RpgClientEngine.js:404
(anonymous) @ RpgClientEngine.js:418
./node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:192
./node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:130
./node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:76
./node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:53
./node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
./node_modules/rxjs/_esm5/internal/BehaviorSubject.js.BehaviorSubject.next @ BehaviorSubject.js:38
(anonymous) @ world.js:41
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
emit @ typed-events.js:46
emitEvent @ socket.js:263
onevent @ socket.js:250
onpacket @ socket.js:217
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
emitReserved @ typed-events.js:59
ondecoded @ manager.js:207
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
add @ index.js:130
ondata @ manager.js:199
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
onPacket @ socket.js:400
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
onPacket @ transport.js:105
onData @ transport.js:98
ws.onmessage @ websocket.js:112
setTimeout (async)
hostReportError @ hostReportError.js:3
./node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:200
./node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:130
./node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:76
./node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:53
./node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
./node_modules/rxjs/_esm5/internal/BehaviorSubject.js.BehaviorSubject.next @ BehaviorSubject.js:38
(anonymous) @ world.js:41
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
emit @ typed-events.js:46
emitEvent @ socket.js:263
onevent @ socket.js:250
onpacket @ socket.js:217
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
emitReserved @ typed-events.js:59
ondecoded @ manager.js:207
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
add @ index.js:130
ondata @ manager.js:199
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
onPacket @ socket.js:400
./node_modules/component-emitter/index.js.Emitter.emit @ index.js:145
onPacket @ transport.js:105
onData @ transport.js:98
ws.onmessage @ websocket.js:112
Below is my code:
export const player: RpgPlayerHooks = {
onInput(player: RpgPlayer, { input, moving }) {
const graphic = player.graphic;
if (input == 'attack' && !player.getVariable('attackCooldown')) {
setTimeout(() => player.setVariable('attackCooldown', false), 300);
player.showAnimation(graphic, 'attack', true);
player.setVariable('attackCooldown', true)
const targets = player.otherPlayersCollision as RpgPlayer[];
targets.forEach((target: RpgPlayer | RpgEvent) => {
target.hp -= 20;
if (target.hp <= 0) {
const map = player.getCurrentMap() as RpgMap;
map.removeEvent(target.id);
}
});
}
}
}