Closed Sago92 closed 4 years ago
Generally you want to spawn the NPC with the correct name from the start, not spawn it and rename it after.
Now I changed my logic so that the name will only be set when I create a whole new NPC and I never update or set the name in the rest of my code (spawn, despawn or setup logic).
// Gets the color based on the attitude
ChatColor nameColor = ColorHelper.attitudeColor.get(definition.getAttitude());
// Splits the entity name by spaces, because client side names need the color code before every part of the name
String[] splittedName = definition.getName().split(" ");
// Combines back the name with the needed color code
String entityName = "";
for (String namePart : splittedName)
entityName += nameColor + namePart + " ";
// Creates the new entity/npc instance
NPC npc = CitizensAPI.getNPCRegistry().createNPC(definition.getType(), definition.getRolePrefix() + entityName);
npc.spawn(spawnLocation);
Nevertheless the NPCs name wont show up after the NPC gets killed, respawns and directly starts a fight or is directly walking after the respawn.
And the last described scenario when you come from far away and the NPCs are already in a fight the names won't update, too.
When the NPC stands still for around 1~2 seconds the name will correctly be updated after respawn.
Do you need any additional information or soruce code snippets?
Regards Sascha
Can you test with a fully up-to-date Spigot 1.13.2 build (make a new one via buildtools), and the latest stable 1.13.2 build - which is this one: https://ci.citizensnpcs.co/job/Citizens2/1636/
Issue is still there with the latest version of Spigot and Citizens
Sample: Directly walking after spawn:
Try latest build.
With the latest build all 3 described behaviors are still there. It look like the update of the name won't trigger/work if the NPC is moving (see directly walking after spawn or fight while player ist comming from far away)
And what's your packet update delay? The point of 1657 was to change that if you look at the commit.
My packet update delay is 30. I tried to change it to 5, but it doesn't change anything.
I did some additional testing.
1.) The scencario when I come from far away to the NPCs that are fighting, the names are updated correctly now. - Had this issue again
2.) Adding a "spawn protection" from 2 seconds where the NPC don't walk or gets into a fight including the reducing of the packet update delay to 5 seconds updates the name correctly, too
Nevertheless without the delay the name doesn't update when an NPC is directly walking or starting a fight
I figured something new out. If the entity type of the spawned entity is a Player the name is directly correct. Only if the entity type is something different like a sheep or a wolf the update appears a bit later
Switchted from Spigot to Sponge, because of better entity control. Close this issue because it seems nobody is facing it and nobody is doing the "research to do"...
The output of command
/version
on my server is: The output of command/version citizens
on my server is: Citizens configuration & latest server log file: clickDear Development-Team,
I am using the engine/plugin/api of Citizens to control and create different NPC's on my in progress MMORPG Server.
I've created some own traits. For example to archive a friendly/aggressive or neutral behavior or for exmaple a wander trait where an NPC walks randomly in a defined area.
Now I have the issue, that my custom NPC names won't show up in the following scenarios. Scenario 1: When the NPC is navigating directly after it was spawned Scenario 2: When a NPC gets into a fight after spawned Scenario 3: When you moving from far away into the area where NPCs are fighting each other
As you can see in the following screenshots the wolf and the sheep are in a fight and the custom name doesn't show up.
I am using different color codes in the name and figured out that setting the name of the NPC is slow because of the internal respawn (~1-3 seconds). I am using this piece of code to change the name of the NPC
When a entitys health reached zero (custom health management) the kill method will get invoked
After a specified defined of time the respawn logic calls the spawn method
Finally my setup method after I created an NPC
Do you have any ideas/suggestions or code improvements to solve the above scenarios?
Regards Sascha