Hey, I'm trying to make it so the human im spawning only spawns to the one player only so no one else can see it. I've tried spawnTo and its only worked like a couple of times when testing. And ive also tried to remove the spawned entity for everyone else whos online and it still doesnt work. This code is executed over player join event and it shows no errors. It just spawns the entity for everyone still. PHP: $skin = $player->getSkin(); $data = $skin->getSkinData(); $id = $skin->getSkinId(); $nbt = new CompoundTag("", [ "Pos" => new ListTag("Pos", [ new DoubleTag("", 126.549), new DoubleTag("", 20), new DoubleTag("", 184.527) ]), "Motion" => new ListTag("Motion", [ new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", 90), new FloatTag("", 0) ]), "Skin" => new CompoundTag("Skin", [ "Data" => new StringTag("Data", $data), "Name" => new StringTag("Name", $id) ] ) ]); $entity = Entity::createEntity("Human", $this->getServer()->getDefaultLevel(), $nbt); $entity->setNameTag("§l§6".$player->getName()); $entity->spawnTo($player);//this worked like 2 times before } PHP: $entity->spawnToAll($player); foreach($this->getServer()->getOnlinePlayers() as $online){ If($player->getName() != $online->getName()){ $entity->despawnFrom($player);}} Any ideas? Edit - My ultimate goal here is to have it so everyone sees a human entity at the same coords but it displays their own skin.
Possibly make the entity invisible, spawnToAll, then set the same entity visible, and spawnTo the main Player? If spawnTo doesn't work at all, though, that may be a useless suggestion. I'm not sure why spawnTo only works some of the time.
I don't think setting an entity invisible and visible again would really do anything? I did try using AddPlayerPacket instead today but I've only seemed to be crashing with no errors when i spawn it. I did see the player packet spawn tho before i crashed. Maybe I'm missing something? PHP: $player = $event->getPlayer(); $uuid = $player->getUniqueId(); $pk = new AddPlayerPacket(); $pk->entityRuntimeId = Entity::$entityCount++; $pk->uuid = $uuid; $pk->username = $player->getName(); $pk->item = ItemFactory::get(ItemIds::AIR); $pk->metadata = array(); $pk->yaw = 0; $pk->pitch = 0; $pk->position = new Position(255,5, 255,$this->getServer()->getDefaultLevel()); $player->dataPacket($pk);
Just another update on this thread, I've recently tried using PlayerSkinPacket() when people join to make the entity display their skin. It does display players skin on the entity but it seems to crash people have the time when testing PHP: $pk = new PlayerSkinPacket();$pk->uuid = $entity->getUniqueId();$pk->skin = clone $player->getSkin();$player->dataPacket($pk); I'm really determined to get this done so any input is appreciated
Yeah the conclusion here is this does not work on join event unless you use it in a delayed task lol Works fine now