Hey can someone help me about this. I want a command that when type /buycoin 1. When the command executed it will reduce player money with 10000 and with /buycoin 5 it will reduce player money to 50000
use dispatchCommand. Like this: PHP: $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "takemoney " . $sender->getName() . " 10000"); Or a full: PHP: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){switch($cmd->getName()){ case "buy": if(isset($args[0])){ switch($args[0]){ case "coin": if($sender instanceof Player){ $args[1] >= 1; $economy = EconomyAPI::getInstance(); $mymoney = $economy->myMoney($sender); if(isset($args[1])){ if(is_numeric($args[1])){ if($mymoney >= 10000){ $economy->reduceMoney($sender, $args[1] ."0000"); $sender->sendMessage("§c»§a Bạn đã mua thành công §d " . $args[1] . "§a coins."); return true; } else { $sender->sendMessage("§c»§e Bạn không đủ tiền."); } } } }
I Think it will lead to an bug that when u type /buy coin 100000. The command dont care about the price it just check if the player has more than 10000 it will give Or a full: PHP: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){switch($cmd->getName()){ case "buy": if(isset($args[0])){ switch($args[0]){ case "coin": if($sender instanceof Player){ $args[1] >= 1; $economy = EconomyAPI::getInstance(); $mymoney = $economy->myMoney($sender); if(isset($args[1])){ if(is_numeric($args[1])){ if($mymoney >= 10000){ $economy->reduceMoney($sender, $args[1] ."0000"); $sender->sendMessage("§c»§a Bạn đã mua thành công §d " . $args[1] . "§a coins."); return true; } else { $sender->sendMessage("§c»§e Bạn không đủ tiền."); } } } } [/QUOTE] I Think it will lead to an bug that when u type /buy coin 100000. The command dont care about the price it just check if the player has more than 10000 it will give the player 100000 coins