Code: $this->db["BlueHome"] = array('x'=>(int)$player->getX(),'y'=>(int)$player->getY(),'z'=>(int) $player->getZ()); $this->database->setAll($this->db); $this->database->save(); Code: $this->db["RedHome"] = array('x'=>(int)$player->getX(),'y'=>(int)$player->getY(),'z'=>(int)$player->getZ()); $this->database->setAll($this->db); $this->database->save(); Code: if(isset($this->db["blue"]) && ($this->db["red"])){ $this->db["blue"]->setSpawn(new Vector3($this->db["BlueHome"] -> ["x"], ["y"], ["z"])); $this->db["red"]->setSpawn(new Vector3($this->db["RedHome"] -> ["x"], ["y"], ["z"])); } It says "syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'" (EXCEPTION) in here $this->db["blue"]->setSpawn(new Vector3($this->db["BlueHome"] -> ["x"], ["y"], ["z"])); $this->db["red"]->setSpawn(new Vector3($this->db["RedHome"] -> ["x"], ["y"], ["z"]));
Please look at my answers: https://forums.pmmp.io/threads/wrong-and-error-with-array-and-setrespawnposition.9234/#post-69675 https://forums.pmmp.io/threads/wrong-and-error-with-array-and-setrespawnposition.9234/#post-69683
Sorry I saw but I tried to make another way. So I think many things solved but here is one left. it crash and says "Call to a member function setSpawn() on null" (EXCEPTION) in " here is the code Code: if(isset($this->db["blue"]) && ($this->db["red"])){ $blueplayerNames = $this->db["blue"]; $redplayerNames = $this->db["red"]; $blueplayers = $this->getServer()->getPlayer($blueplayerNames); $redplayers = $this->getServer()->getPlayer($redplayerNames); $BlueHome = $this->db["BlueHome"]; $RedHome = $this->db["RedHome"]; $blueplayers->setSpawn(new Vector3($BlueHome["x"], $BlueHome["y"], $BlueHome["z"])); $redplayers->setSpawn(new Vector3($RedHome["x"], $RedHome["y"], $RedHome["z"])); }
That code won't work, not even close. Please look at the example I provided in my second answer and try to understand it. PHP is not numPy, if you want to operate on an array, you will need to do it one element at a time using a foreach loop.
I edit. You mean use foreach like this? Code: if(isset($this->db["blue"]) && ($this->db["red"])){ $blueplayerNames = $this->db["blue"]; $redplayerNames = $this->db["red"]; foreach($blueplayerNames as $blueplayerNamesFE){ $blueplayers = $this->getServer()->getPlayer($blueplayerNamesFE); $BlueHome = $this->db["BlueHome"]; $blueplayers->setSpawn(new Vector3($BlueHome["x"], $BlueHome["y"], $BlueHome["z"])); }//foreach foreach($redplayerNames as $redplayerNamesFE){ $redplayers = $this->getServer()->getPlayer($redplayerNamesFE); $RedHome = $this->db["RedHome"]; $redplayers->setSpawn(new Vector3($RedHome["x"], $RedHome["y"], $RedHome["z"])); }//foreach } but is says "Invalid argument supplied for foreach()"