I try to make plugin that when player step on and they get effect... heres code PHP: public function onMove(PlayerMoveEvent $ev){ if ($ev->isCancelled()) return; $cfg = $this->getConfig(); $effectid = $cfg->get("effectid"); $duration = $cfg->get("duration"); $blockid = $cfg->get("blocks"); $to = $ev->getTo(); $id = $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1, $to->getZ()); if (isset($this->$blockid[$id])) { $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration)); } please check If i miss or did anything wrong ;-; Im suck at this
isset() checks whether the Index $id is set in the Array. Example: Code: #config: blocks: #Index 1: - 123 #Index 2: - 456 # Index 3: - 789 # etc... So if you use isset() in an array, it will search the Index, not whether the ID is set in the config. You can use in_array.
Try this: PHP: public function onMove(PlayerMoveEvent $ev){ if ($ev->isCancelled()) return; $cfg = $this->getConfig(); $effectid = $cfg->get("effectid"); $duration = $cfg->get("duration"); $blockid = $cfg->get("blocks"); $to = $ev->getTo(); $id = $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1, $to->getZ()); if (in_array($id, $blockid)) { $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration)); }
Code: [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'BlockEffect v1.0.0': in_array() expects parameter 2 to be array, integer given on iDirtniverse\BlockEffect\Main 22:01:04 [WARNING] InvalidArgumentException: "in_array() expects parameter 2 to be array, integer given" (E_WARNING) in "/BlockEffect/src/iDirtniverse/BlockEffect/Main" at line 62 all code : PHP: <?phpnamespace iDirtniverse\BlockEffect;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\math\vector3;use pocketmine\utils\TextFormat;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\level;use pocketmine\event\player\PlayerChatEvent;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\Player;use pocketmine\entity\Effect;use pocketmine\utils\Config;class Main extends PluginBase implements Listener{ private $players = array(); public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info(TextFormat::DARK_GREEN . "Im Enabled"); $this->path = $this->getDataFolder(); @mkdir($this->path); $this->config = new Config($this->path . "config.yml", Config::YAML, array( "blocks" => 133, "effectid" => 1, "duration" => 1500, )); $this->saveDefaultConfig(); $this->reloadConfig(); } //On Disable. public function onDisable() { $this->getLogger()->info(TextFormat::DARK_RED . "Im Disabled"); $this->saveDefaultConfig(); } public function onCommand(CommandSender $sender, Command $command, $label, array $args) { $cmd = strtolower($command->getName()); switch ($cmd) { case "be": $sender->sendMessage(TextFormat::GREEN . "Place block of emerald block and step on it!"); } } public function onMove(PlayerMoveEvent $ev) { if ($ev->isCancelled()) return; $cfg = $this->getConfig(); $effectid = $cfg->get("effectid"); $duration = $cfg->get("duration"); $blockid = $cfg->get("blocks"); $to = $ev->getTo(); $id = $to->getLevel()->getBlockIdAt($to->getX(), $to->getY() - 1, $to->getZ()); if (in_array($id, $blockid)) { $ev->getPlayer()->addEffect(Effect::getEffect($effectid)->setDuration($duration)); } }}?>