I need some help, Is it Possible to Make a Plugin where on a Certain Command, All players in a Certain World Have a Certain Effect Removed. If it is Please Help me
Yes Code: '/er <world> <effect>' er factions speed PHP: removeEffectFromWorld(Level $world, $effectId){$effectName = Effect::getEffect($effectId)->getName();foreach($world->getPlayers() as $p){if($p->hasEffect($effectId)){$p->removeEffect($effectId);$p->sendMessage('[EffectRemover] '.$effectName.' effect has been taken away');}}$this->getServer()->broadcastMessage('[EffectRemover] '.ucfirst($effectName).' effect have been taken away from '.$world->getName().' world');return true;}
sorry but Its a Little hard for me Since I've never used Something like this when I code, Could u help please
PHP: <?phpnamespace SM11\EffectRemove;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\effect\Effect;class Main extends PluginBase{ public function onEnable(){ $this->getLogger()->info("EffectRemove have been Enabled!"); } public function onDisable(){ $this->getLogger()->info("EffectRemove Have been Enabled!"); } public function onCommand(CommandSender $sender,Command $cmd,$label, array $args) { RemoveEffectFromWorld(Level $world $effectId){ $effectName = Effect::getEffect($effectId)->getName(); foreach($world->getPlayers() as $p){ if($p->hasEffect($effectId)){ $p->removeEffect($effectId); $p->sendPopup('[SSM] '.$effectName.'You May now Begin'); } } $this->getServer()->SendPopup('[SSM] '.ucfirst($effectName).'Game May Now Begin'.$world->getName().' world'); return true; } }}
On line 21 you need to add a comma between $world and $effectId. Primus had it in his code he posted you must have missed it when you copyed it. Just make sure your line 21 looks like the first line of his code.
Shouldn't be. What's the error now? And can you post your new code so I can make sure u changed it correctly.
PHP: <?phpnamespace SM11\EffectRemove;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\effect\Effect;class Main extends PluginBase{ public function onEnable(){ $this->getLogger()->info("EffectRemove have been Enabled!"); } public function onDisable(){ $this->getLogger()->info("EffectRemove Have been Enabled!"); } public function onCommand(CommandSender $sender,Command $cmd,$label, array $args) { if ($cmd->getName() != "EffectRemove") return false; if (count($args) != 0) return false; RemoveEffectFromWorld(Level $world, $effectId){ $effectName = Effect::getEffect($effectId)->getName(); foreach($world->getPlayers() as $p){ if($p->hasEffect($effectId)){ $p->removeEffect($effectId); $p->sendPopup('[SSM] '.$effectName.'You May now Begin'); } } $this->getServer()->SendPopup('[SSM] '.ucfirst($effectName).'Game May Now Begin'.$world->getName().' world'); return true; } }}
Noo , you must put that function outside onCommand(); and call in it. like this: $this->removeEffectFromWorld($args[0], $args[1]);