Forum Discussion

EchoExclusive's avatar
EchoExclusive
Start Partner
9 months ago
Solved

Differentiating NPC and Player

Hi all, I having a little issue with differentiating player and NPC. Side note: I have the NPC gizmo in the editor and enabled avatar ai_agent. I named my NPC "NameNPC" I have this script that was...
  • uRocketLife's avatar
    9 months ago

    Pigeon found that you have to add a 2 second delay to a PlayerEnterWorld before NPC is registered as NPC. There is a "GetPlayerType" method that recognizes the init NPC enter as being "departed" which you can use as a filter to prevent initial NPC 'fails' from registering

    You would call if (getPlayerType(newPlayer, this.world) === "departed") return; Something like that
    export function getPlayerType(player: Player, world: World): PlayerType {
      if (player === world.getServerPlayer()) {
        return "server";
      } else if (!world.getPlayers().includes(player)) {
        return "departed";
      } else if (player.isInBuildMode.get()) {
        return "builder";
      } else if (AvatarAIAgent.getGizmoFromPlayer(player) !== undefined) {
        return "npc";
      } else {
        return "human";
      }
    }​