I'm a beginner in PHP programming, I made 2 plugins I want to put on Poggit for GitHub later, and I want them to work perfectly. One plugin crashes my server (a bunch of plugins won't load anymore). The second one, money doesn't work on my plugin (Example: $money = $money - strlen($msg);). Can you help me fix these 2 plugins? Plugin 1 – TellMeID: Server isn't loading 90% of all plugins if my plugin is on my server: PHP: <?phpnamespace WinterBuild7;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\Server;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\CommandExecutor;use pocketmine\utils\TextFormat;class Main extends PluginBase { public $prefix = "§7[§f§lTellMeID§r§7]§f "; public function onEnable() { $this->getLogger()->info($prefix . "by WinterBuild7 was loaded!"); } public function onCommand(CommandSender $sender, Command $command, array $args) { if($command->getName() === "tellmeid" && $sender->hasPermission("tellmeid.info")) { $sender->sendMessage($prefix . "TellMeID by WinterBuild7. Tells you the item in hand."); } if($command->getName() === "hand" && $sender->hasPermission("tellmeid.use")) { $id = $this->getInventory()->getItemInHand()->getID(); $meta = $this->getInventory()->getItemInHand()->getDamage(); $sender->sendMessage($prefix . "You are holding item ID: §7" . $id . ":" . $meta); } }} ----------------------- Plugin 2 – EconomyChat: I tried breaking wood, but it doesn't add money. Plus, it doesn't take away money too, when using the /pm command: PHP: <?phpnamespace WinterBuild\EconomyChat;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\CommandExecutor;use pocketmine\command\CommandMap;use pocketmine\event\Listener;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\utils\TextFormat;use pocketmine\utils\Config;use pocketmine\permission\ServerOperator;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerPreLoginEvent;use pocketmine\command\ConsoleCommandSender;use pocketmine\event\block\BlockBreakEvent;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->saveDefaultConfig(); } public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { $money = 100; $plname = "§7[§e§lPM§r§7]§f "; $errortag = "§7[§c§lPM§r§7] "; if($cmd->getName() === "pm" || $cmd->getName() === "privatemsg") { if($args[0] === "about") { $sender->sendMessage($plname . "EconomyChat/PM by WinterBuild. Send private messages to players with in-game money."); } if($args[0] === "send") { if(isset($args[1])) { if(isset($args[2])) { if($money >= strlen($args[2])) { $msg = $args[2]; $me = $sender->getName(); $money = $money - strlen($msg); $tousr = $sender->getServer()->getPlayer($args[1]); if($tousr instanceof Player) { $usrtag = "§7[PM: §f§l" . $me . "§r§7->§f§l" . $tousr->getName() . "§r§7] §f"; $sender->sendMessage($usrtag . $msg); $tousr->sendMessage($usrtag . $msg); } else { $sender->sendMessage($errortag . "There's no player with that name or is offline!"); } } else { $sender->sendMessage($errortag . "You don't have enough money! Your money:" . $money); } } else { $sender->sendMessage(§errortag . "You cannot send an empty message!"); } } else { $sender->sendMessage($errortag . "How to use: /pm send <player> <private-message>"); } } if($args[0] === "money") { $sender->sendMessage($plname . "You have $" . $money . "."); } if(!isset($args[0]) || $args[0] === "help") { $tutorial = $this->getConfig()->get("HowToGetMoney"); $sender->sendMessage("§7---------- §e§lPM Commands §r§7----------"); $sender->sendMessage("§7§lEconomyChat PM§r§f - Send PrivateMessages (PMs) to other players with in-game money."); $sender->sendMessage($tutorial); $sender->sendMessage("§7/pm help" . " §f- Show all EconomyChat/PM commands."); $sender->sendMessage("§7/pm about" . " §f- About EconomyChat/PM"); $sender->sendMessage("§7/pm send <player> <message>" . " §f- Send a PrivateMessage (PM) to a player."); $sender->sendMessage("§7/pm money" . " §f- See how much money you have."); $sender->sendMessage("§7-------------------------------------"); } } } public function onBreak(BlockBreakEvent $event) { $blockbreak = $this->getConfig()->get("BlockBreak"); $moneyget = $this->getConfig()->get("BreakMoney"); if($event->getBlock()->getId() === $blockbreak) { $money = $money + $moneyget; } }}
If you have multiple plugins using the same namespace, the plugins will interfere with each other when they are constructed. PHP: <?phpnamespace WinterBuild7;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\Server;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\CommandExecutor;use pocketmine\utils\TextFormat;class Main extends PluginBase { public $prefix = "§7[§f§lTellMeID§r§7]§f "; public function onEnable() { $this->getLogger()->info($prefix . "by WinterBuild7 was loaded!"); } public function onCommand(CommandSender $sender, Command $command, array $args) { if($command->getName() === "tellmeid" && $sender->hasPermission("tellmeid.info")) { $sender->sendMessage($prefix . "TellMeID by WinterBuild7. Tells you the item in hand."); } if($command->getName() === "hand" && $sender instanceof Player && $sender->hasPermission("tellmeid.use")) { //make sure the sender is a player $id = $sender->getInventory()->getItemInHand()->getID(); //use $sender instead of main class $meta = $sender->getInventory()->getItemInHand()->getDamage(); //use $sender instead of main class $sender->sendMessage($prefix . "You are holding item ID: §7" . $id . ":" . $meta); } }}
when you are setting the amount of money for each player, set the data to a global array using the player names as the keys
How? I never did that before. Code? I know how to use array and keys, but I don't know how to make it really.
you are trying to make an economy system correct? You need a way to track each player's money amount. You need to use an array.
Yes. But how can I add the player's name to the array, plus, how much money this player has? Also, do I need to add those?
You need to learn more about how to program before asking these questions on this forum. We are here to help with PMMP API, not generic php.
I gave up with my plugins, don't need help with that anymore. But I'm still wondering why my plugin no. 1 isn't working. Plus, if any more replies here, then admins, please move this to 'Development', I'll be more careful with forum categories.