• Help
  • How to get values outside of dbData?

Issue

  • Install @rpgjs/title-screen plugin
  • nickname, password, email fields are created in the MongoDB collection after user registration
  • I want to use the nickname field from the DB on the client side to display the users name, but I cannot access nickname

Expected

  • Install @rpgjs/title-screen plugin
  • nickname, password, email fields are created in the MongoDB collection after user registration
  • Some type of object that can pull values outside of the data attribute associated with the logged-in player so nickname can be used

Note: I am also using rpgjs-character-select plugin, which may be overwriting the player.name with one of the selected characters as I see the player.name is being set in @rpgjs/title-screen here [https://github.com/RSamaium/RPG-JS/blob/afba6593c6d060c46a67be465bef2abd401d4c8d/packages/plugins/title-screen/src/server/mmorpg/index.ts#L137] so I'm not sure where the problem is. Either @rpgjs/title-screen or rpgjs-character-select. Maybe the problem is in both as per this conversation: https://community.rpgjs.dev/d/177-title-screen-plugin-issues/22

See the screenshot for this to make more sense:
![

  • dominx99 replied to this.
  • Poopy

    Hello,

    I also struggled with the same problem with player.name being overwritten.

    It's not the issue with plugins but with the setActor method

    player.setActor(ActorClass)

    I suppose your Actor has the name Human and that's why it overrides the player's name.

    For me, it makes no sense. I assume that it's for RPG (not MMORPG) purposes to set the name of the actor.

    Check this thread: https://community.rpgjs.dev/d/186-player-name-is-not-displayed-after-login-when-setactor-is-used-in-meantime/2

    and here is the line in the engine that does this: https://github.com/RSamaium/RPG-JS/blob/7270db77500e1446bf7669417d4312c28eddc83f/packages/server/src/Player/ClassManager.ts#L57

    I got a workaround for that like this:

        onCharacterSelected(player: RpgPlayer, actorId: string) {
            const name = player.name; // here player's name is the one from db `nickname`
            player.setActor(actorId); // it overrides the player name to actor's name
            player.name = name; // it restores original name
        },

    Poopy

    Hello,

    I also struggled with the same problem with player.name being overwritten.

    It's not the issue with plugins but with the setActor method

    player.setActor(ActorClass)

    I suppose your Actor has the name Human and that's why it overrides the player's name.

    For me, it makes no sense. I assume that it's for RPG (not MMORPG) purposes to set the name of the actor.

    Check this thread: https://community.rpgjs.dev/d/186-player-name-is-not-displayed-after-login-when-setactor-is-used-in-meantime/2

    and here is the line in the engine that does this: https://github.com/RSamaium/RPG-JS/blob/7270db77500e1446bf7669417d4312c28eddc83f/packages/server/src/Player/ClassManager.ts#L57

    I got a workaround for that like this:

        onCharacterSelected(player: RpgPlayer, actorId: string) {
            const name = player.name; // here player's name is the one from db `nickname`
            player.setActor(actorId); // it overrides the player name to actor's name
            player.name = name; // it restores original name
        },

      dominx99 Thanks for the response. The code you provided clears out the name to undefined, so that's good that I am able to change the name, but still its not picking up the users nickname.

      I do see now where this is being set in the engine.

      I was able to do something like this in the onCharacterSelected and get the nickname from the mongoose collection.

         mongoose.connect('mongodb://myinstance.com');
      
          const mongoId = '6590c6ff541f21bcc3d81fef'; //using player.mongoId in the real code
      
      
          PlayerModel.findById(mongoId)
              .then(document => {
                  console.log('Fetched document:', document);
              })
              .catch(err => {
                  console.error('Error fetching document:', err);
              });

      Then, once I got the document, I overwrote the player.name to have the document.nickname

      Thanks for pointing me in the right direction @dominx99 !!

        Poopy

        Great you managed to do it!

        However for me snippet I shared works without fetching the nickname using mongoose because the title screen already sets the nickname here as you mentioned, but I don't remember if it's a complete solution. I will test it tomorrow on a clean project with title-screen and character-select plugins 👍

          dominx99 It’s not that big of a deal since I got it working in my own way, but it’s much appreciated. It would’ve been funnier if you said you’ll test it next year ( ͡ ° ͜ʖ ͡ °)

            Poopy

            Poopy It would’ve been funnier if you said you’ll test it next year ( ͡ ° ͜ʖ ͡ °)

            Daaamn, I might have thought of that 😄


            I see now why it's not working for you. You were right about mentioning this🤦‍♂️:

            Poopy Maybe the problem is in both as per this conversation: https://community.rpgjs.dev/d/177-title-screen-plugin-issues/22

            I had problems implementing the character-select plugin because the title-screen does not provide an easy transition to the next GUI.

            so as result character-select plugin is activated before

            player.name = user.nickname

            inside the title-screen plugin is executed

            For me, it worked because I customized the title-screen plugin to my needs and forgot about that I moved:

            player.name = user.nickname

            a little higher in code 😅

              dominx99 yea I have forked the title-screen and made a local package to customize it for my needs.

              Thanks for looking into it, but I got it working so all good.