Spoiler: Code PHP: public function PlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent $event){ if(!file_exists($this->getDataFolder() . "help.yml")) { @mkdir($this->getDataFolder()); } $this->helpcfg = new Config($this->getDataFolder()."help.yml", Config::YAML); $command = explode(" ", strtolower($event->getMessage())); $player = $event->getPlayer(); if($command[0] === "/help" or $command[0] === "/?") { foreach($this->helpcfg->get("page.1") as $page1){ $player->sendMessage($page1); $event->setCancelled(); } if($command[1] === "1" or $command[1] === "one") { foreach($this->helpcfg->get("page.1") as $page1){ $player->sendMessage($page1); $event->setCancelled(); } }elseif($command[1] === "2" or $command[1] === "two") { foreach($this->helpcfg->get("page.2") as $page2){ $player->sendMessage($page2); $event->setCancelled(); } } }elseif($command[1] === "3" or $command[1] === "three") { foreach($this->helpcfg->get("page.3") as $page3){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "4" or $command[1] === "four") { foreach($this->helpcfg->get("page.4") as $page4){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "5" or $command[1] === "five") { foreach($this->helpcfg->get("page.5") as $page5){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "6" or $command[1] === "six") { foreach($this->helpcfg->get("page.6") as $page6){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "7" or $command[1] === "seven") { foreach($this->helpcfg->get("page.7") as $page7){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "8" or $command[1] === "eight") { foreach($this->helpcfg->get("page.8") as $page8){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "9" or $command[1] === "nine") { foreach($this->helpcfg->get("page.9") as $page9){ $player->sendMessage($page2); $event->setCancelled(); } }elseif($command[1] === "10" or $command[1] === "ten") { foreach($this->helpcfg->get("page.10") as $page10){ $player->sendMessage($page10); $event->setCancelled(); } }} It does work all the way till /help 10, just that it spams the console with... Notice: Undefined offset: 1 in /home/testify/plugins/RumBenFX_v1/src/RumBenCoreaft/Main.php on line 1108 (The line containing elseif($command[1] === "x"))
Well first of all I think you're missing one } at the end. Secondly, I think you forgot to change the message that will be sent to the player on help 3-9. Hope that works
First, thats one hell of a dynamic code. Second, I don't see "elseif($command[1] === "x")" anywhere? PHP: var_dump($command); To see what the variable contains.
PHP: if($command[1] > 0 && $command[1] < 11){$stuff = $this->helpcfg->get("page." . $command[1]);foreach($stuff as $p){// Do something}} And about the error: $command[number here] is not set, means the command is only /help
Seriously? that is what a LOOP is for. If I want to add 1 more page, you'll need to add more code. Compared to the mathod Craft showed you, it is very static.
Okay well, whatever you say, I'm just a student... I've made the plugin, here it is, but I'm still getting some console errors, though the plugin works well and the messages are delivered on point... and at this point, I think it's... PocketMine's fault? GitHub: https://github.com/Muqsit/Help
Please post the code and errors here. It's not our job to read through your code, try it out and find the errors.
Spoiler: Main.php PHP: <?phpnamespace Muqsit;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerCommandPreprocessEvent;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{public function onEnable(){if(!file_exists($this->getDataFolder() . "help.yml")) {@mkdir($this->getDataFolder());file_put_contents($this->getDataFolder() . "help.yml",$this->getResource("help.yml"));}$this->saveDefaultConfig();$this->getServer()->getPluginManager()->registerEvents($this, $this);}public function PlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent $event){$this->helpcfg = new Config($this->getDataFolder()."help.yml", Config::YAML);$command = explode(" ", strtolower($event->getMessage()));$player = $event->getPlayer();$protect = $this->helpcfg->get("pages");if($command[0] === "/help" or $command[0] === "/?"){if($command[1] > 0 && $command[1] < $protect + 1){$messages = $this->helpcfg->get("page." . $command[1]);foreach($messages as $msges){$player->sendMessage($msges);$event->setCancelled();}}elseif($command[1] < 1 or $command[1] > $protect){$helpInitial = $this->helpcfg->get("page.1");foreach($helpInitial as $helpInit){$player->sendMessage($helpInit);$event->setCancelled();}}}}} Gives undefined offset 1 on the line containing $command[1]