Sorry to post so much but I have 10 family members asking for a few issues to be fixed so here goes. I am trying to create a plugin that spawns animals and so far here is what I have PHP: <?phpnamespace robertcc19\spawnanimals; use pocketmine\level\format\FullChunk; use pocketmine\plugin\PluginBase; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\CommandExecutor; use pocketmine\entity\Entity; use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\entity\Villager; use pocketmine\event\Listener; use pocketmine\Player; use pocketmine\Server; use pocketmine\event\player\PlayerJoinEvent; class AnimalSpawn extends PluginBase implements Listener { public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if (strtolower($command->getName()) === "vc") { $nbt = new CompoundTag ("", [ "Pos" => new ListTag( "Pos", [ new DoubleTag("", $player->x), new DoubleTag("", $player->y ), new DoubleTag("", $player->z) ]), "Motion" => new ListTag ( "Motion", [ new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", 90), new FloatTag("", 90) ]) ]); $youranimal = Entity::createEntity(Pig::NETWORK_ID, $player->chunk, $nbt); $youranimal->spawnToAll(); } return true; return false; } }?> This came from a suggestion on a previous question, and the $player variable seems to be undefined even though I have included the player file from the pocketmine api.
You need to define the variable just because you include Foo class that dosent meant $foo will automatically be defined with class foo to do that, check of command sender is player then assign player as command sender, if it isnt instance of player: dont spawn(console and remote console can run commands too!!! and they dont have cords like players)
Thanks for that, it worked I am not getting a pig to spawn after executing command, am I missing something? do I need to set a spawn command or is $youranimal->spawnToAll(); enough?