1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Setting skin / creating a human entity

Discussion in 'Development' started by Bad and Boujee, Dec 19, 2017.

  1. Bad and Boujee

    Bad and Boujee Creeper

    Messages:
    4
    GitHub:
    None
    So I have this,

    Code:
    $nbt = new CompoundTag('', [
                'Pos' => new ListTag('Pos', [
                    new DoubleTag('', $pos->x),
                    new DoubleTag('', $pos->y),
                    new DoubleTag('', $pos->z)
                ]),
                'Motion' => new ListTag('Motion', [
                    new DoubleTag('', 0),
                    new DoubleTag('', 0),
                    new DoubleTag('', 0)
                ]),
                'Rotation' => new ListTag('Rotation', [
                    new FloatTag(0, $yaw),
                    new FloatTag(1, $pitch)
                ]),
            ]);
            $entity = Entity::createEntity("Human", $this->getServer()->getDefaultLevel(), $nbt);
    How would I set its skin? I know there's a ->setSkin function but It accept a Skin class which I have no idea on how to get it?

    Please assist.
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    $player->getSkin() return skin object that you can use in setSkin()
     
  3. TGames

    TGames Silverfish

    Messages:
    18
    this will work:
    $nbt = new CompoundTag("", [
    new ListTag("Pos", [
    new DoubleTag("", $player->getX()),
    new DoubleTag("", $player->getY()),
    new DoubleTag("", $player->getZ())
    ]),
    new ListTag("Motion", [
    new DoubleTag("", 0),
    new DoubleTag("", 0),
    new DoubleTag("", 0)
    ]),
    new ListTag("Rotation", [
    new FloatTag("", lcg_value() * 360),
    new FloatTag("", 0)
    ]),
    //use pocketmine =>1.2/*new CompoundTag("Skin", [
    new StringTag("Data", $player->getSkin()->getSkinData()),
    new StringTag("Name", $player->getSkin()->getSkinId()),
    ]),*/
    new CompoundTag("Skin", [
    "Data" => new StringTag("Data", $player->getSkinData()),
    "Name" => new StringTag("Name", $player->getSkinId())
    ]),
    ]);
    $npc = new Human($player->getLevel(), $nbt);
    foreach($this->getServer()->getOnlinePlayers() as $plr) {
    $npc->spawnTo($plr);
    }
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Why don't use $npc->setSkin($player->getSkin()) instead? Isn't that easier?
     
    Kenn Fatt likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.