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 referenced from "Intro to desktop Editor and Typescript". I added some logic to check if it's an NPC. If it is an NPC it will print "Should be NPC". If it is a player it will print "Should be Player"
Since I only have one NPC and myself. I was expecting to see "Should be Player" and "Should be NPC" printed once
However, not only was Should be Player printed three tiems, but it thought NPC was a player, than deleted the NPC and than said NPC is a player again. See attached below
This would be a problem because I have other logic where enemies will check when player entered world and follow that player, but it will start following the NPC instead because it thinks the NPC is a player
How come the NPC is treated as a player at the beginning? How can I make sure the NPC is never treated as a player - I don't want to have to check the NPC's name to see if it is an NPC
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 thatexport 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"; } }