Hi all. I am trying to get if a player joins my server they spawn in the hub each time they join, but I keep getting this error. Code: Undefined offset: 3 in C:\Users\user\Documents\PocketMine x64\plugins\Basic\src\Basic\Main.php on line 67 Code: Array to string conversion in phar://C:/Users/user/Documents/PocketMine x64/PocketMine-MP.phar/src/pocketmine/level/Position.php on line 108 My code for Main is: Code: public function onjoin(PlayerJoinEvent $pje){ $player = $pje->getPlayer(); $name = $player->getName(); $spawnloc = array($this->getConfig()->getNested("SPAWN_POS")); if($this->getConfig()->get("FORCEHUB") === TRUE && $spawnloc[3] !== $player->getLevel()->getName()){ $player->teleport(new Position($spawnloc[0], $spawnloc[1], $spawnloc[2], $spawnloc[3])); } } I want to check the config file for the x,y,z and level position and make sure if the player is not in the level when joining, they teleport to the hub. Could someone point me in the right direction. Thanks
That means 3 isn't in your config. Please learn PHP and google errors before you make a forum post over a simple error.
Assuming your config to be like this: Code: SPAWN_LOC: - 100 - 256 - 50 - "world" You are putting an array inside an array. PHP: $spawnloc = array($this->getConfig()->getNested("SPAWN_POS")); So $spawnloc looks something like this: Code: $spawnloc = [ 0 => [ 0 => 100, 1 => 256, 2 => 50, 3 => "world" ] ]; There's no need of putting an array inside an array. PHP: $spawnloc = $this->getConfig()->getNested("SPAWN_POS");$spawnloc[3] = Server::getInstance()->getLevelByName($spawnloc[3]);if($spawnloc[3] !== NULL){ $player->teleport(new Position(...$spawnloc));}
Ok thanks for the info and Jasonwynn10 instead of just typing Facepalm section on every post why not just try and help.
I think he tries to help, he just meant that the Question is a Question for beginners and should be because of that moved in there.