• Help
  • maxHp & maxSp is not synced to the GUI after levelUp

  1. As in the title and image below.
    HP

  2. After die player.allRecovery() does not work

I have onDead hook for player:

    onDead(player: RpgPlayer) {
        BattleIntervals.clearByVictim(player.id);
        FollowManager.stopFollowByPlayer(player.id);
        HPRecovery.disable(player)

        player.changeMap('map1', {
            x: 300,
            y: 400,
        });
        
        player.allRecovery();
        HPRecovery.enable(player);
    },

and when I die I have -30/700 HP instead of 700/700
but when I add something like this:

...
        setTimeout(() => {
            player.allRecovery();
            HPRecovery.enable(player);
        }, 0);
...

Then it works

  • Here's an example (Press Enter to increase the level)

Note that the synchronization system works by room (on RPGJS, a room is a map).

So when you change maps, player synchronization is performed on the old map, not the new one.

This may seem a strange implementation, but it's deliberate because one map may have a different synchronization scheme from another. So synchronization is done per map.

A solution for recovering the correct synchronization after a map change would be as follows:

import { RpgWorld, RpgPlayer } from '@rpgjs/server'

// [...]

async onDead(player: RpgPlayer) {
    await player.changeMap('map2', {
        x: 300,
        y: 400,
    });
    const currentPlayer = RpgWorld.getPlayer(player.id)
    currentPlayer.allRecovery();
}

    Samarium

    Ok so, if I understood correctly something like this should recover my HP after dying:

        onDead(player: RpgPlayer) {
            player.allRecovery();
        },

    but it does not work, as you can see in this video: https://imgur.com/9D4yxEs

    On the other hand onLevelUp works perfect:

        onLevelUp(player: RpgPlayer, leveledUpBy: number) {
            player.showAnimation('level-up', 'default');
    
            player.allRecovery();
        },

    Your example does not work too:

        onDead(player: RpgPlayer) {
            const currentPlayer = RpgWorld.getPlayer(player.id)
    
            currentPlayer.allRecovery();
        },

    The second issue is that after level-up I have 794/700 HP (visible at the end of the above video).
    I know this GUI is custom, but the same is for the built one.

    13 days later

    Samarium

    That's right issue with recovering HP after die works now!

    But the issue with max hp is not synced to GUI persists img

    3 months later

    @Samarium

    Could you take a look at it?

    This issue still persists:

    properties in the param object are not updated after level up while synchronization to the client through rpgCurrentPlayer subscription.

    Here's an example (Press Enter to increase the level)