Hello, I have a problem... When a player arrives at the server, the sign adds a player but when he leaves, the sign does not removed the player... The plugin Main: PHP: <?phpnamespace HB;use pocketmine\Server;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\level\Level;use pocketmine\tile\Sign;use pocketmine\block\Block;use pocketmine\item\Item;use pocketmine\math\Vector3;use pocketmine\entity\Entity;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerQuitEventuse pocketmine\scheduler\Task;use HB\{SignTask, TaskEnd, TaskInv, TaskPvP};class Main extends PluginBase implements Listener{ public $status = array(); public $player = array(); public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("HotBlock Enabled !"); if(!isset($this->status['HB'])){ $this->status['HB'] = 0; } $this->getServer()->getScheduler()->scheduleRepeatingTask(new SignTask($this), 20 * 3); } public function onPlayerJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); array_push($this->player, $player->getName()); } public function onPlayerQuit(PlayerQuitEvent $event){ //Marche pas. $player = $event->getPlayer(); if(isset($this->player[$player->getName()])){ unset($this->player[$player->getName()]); $player->sendMessage("LEFT"); } } public function SignTask(){ $tile = $this->getServer()->getLevelByName("world")->getTile(new Vector3(133, 6, 128)); if($tile instanceof Sign){ if($this->status["HB"] == 0){ $tile->setText("[HotBlock]", "Map : End", "Players : ".count($this->player)." / 15", "TEST"); }else{ $tile->setText("[HotBlock]", "Map : End", "Players : ".count($this->player)." / 15", "In Game..."); } } }} The plugin Task: PHP: <?phpnamespace HB;use pocketmine\scheduler\PluginTask;use pocketmine\math\Vector3;use pocketmine\tile\Sign as SignTile;use HB\Main;class SignTask extends PluginTask{ public function __construct(Main $owner){ parent::__construct($owner); $this->owner = $owner; } public function onRun($currentTick){ $this->getOwner()->SignTask(); }} Thanks you for your help.
You need the key when using unset(). Use PHP: $array[array_search($name, $array)]; While $array is your array, and $name is the playername. array_search() returns the key. But... why don't you simply count all online players?
PHP: $player = $event->getPlayer(); $name = $player->getName(); $p1 = array_search($name,$this->players); unset($this->players[$p1]);//For unset solution..
Hello, I do not count online players because this code is not the real... (in truth, it's the players on arenas but I simplified the code). Thanks, I'll try ! I'll keep you informed.