I need to get the player'a name in a world what I did is PHP: $name = Server::getInstance()->getLevelByName("knockback")->getPlayers()->getName(); Error: "call to a member function getName() on array" I've been searching on Google how to fix this but no luck PHP: public function onDeath(PlayerDeathEvent $ev){ $return = Server::getInstance()->getLevelByName("spawn"); foreach(Server::getInstance()->getLevelByName("knockback")->getPlayers() as $all){ if(count($all) == 1){ $name = Server::getInstance()->getLevelByName("knockback")->getPlayers()->getName(); foreach($this->getServer()->getOnlinePlayers() as $onlineplayers){ $onlineplayers->sendMessage("§b[KB]§e$name has won KB!"); } $all->teleport($return->getSpawnLocation()); } } } }
The error is self-explanatory. $level->getPlayers() returns an array of Players. How can you get a single name of a group of players? Even if there is only one player in a level, it will still return that name in an array.
PHP: $name = Server::getInstance()->getLevelByName("knockback")->getPlayer()->getName(); Error: Call to undefined method pocketmine/level/level::getPlayer() Sorry I'm new to this thing I usually get the sender name
How do I get it, when the player dies of fall damage or being pricked by a cactus will it find the player who last hit the dead player?
My KillCounter plugin has this implemented. The code isn't too neat but you can see it here: https://github.com/BlockHorizons/Ki...KillCounter/listeners/PlayerEventListener.php Look for lastPlayerDamageCause
If the player fell or killed by a cactus but you hit the player before it happened will it still register as you who killed the player
Yes it will, as I mentioned. Look at the EntityDeathEvent where it checks if the death cause it NOT another entity.
PHP: public function onDeath(PlayerDeathEvent $ev){ $return = Server::getInstance()->getLevelByName("spawn"); $lastPlayerAttacker = null; $entity = $ev->getPlayer(); foreach(Server::getInstance()->getLevelByName("knockback")->getPlayers() as $all){ if(count($all) == 1) { $cause = $entity->getLastDamageCause(); if($cause !== EntityDamageEvent::CAUSE_ENTITY_ATTACK) { $lastPlayerAttacker = $this->getServer()->getPlayer($this->getLastPlayerAttacker($entity)); if($lastPlayerAttacker !== null) { $name = $lastPlayerAttacker->getName(); foreach($this->getServer()->getOnlinePlayers() as $onlineplayers){ $onlineplayers->sendMessage("§b[KB]§e$name has won KB!"); } $all->teleport($return->getSpawnLocation()); } } } } } Dunno what I did wrong Call to undefined method KnockBack\Main::getLastPlayerAttacker()
The error says exactly the issue you are having... You shouldn't need someone to tell you. You have an undefined function in your class. That is a php issue, not something about PMMP API. Issues such as those should go to StackOverflow.
Yeah I'm noob at this, I'm still learning I just recognize a few errors by having the errors repeatedly
While modern computers have been developed with marvelous artificial intelligence, they have not yet been taught to read minds yet. There are many players in a world, and nobody from computers to robots to humans to aliens to can guess what you want to do. You may want to get the player who got hurt in cactus, or the player who pushed another player onto the cactus, or the player who placed the cactus, or the player who granted the permission to place cacti, or many more possibilities.