1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Number

Discussion in 'Help' started by ZackyVN, Dec 20, 2018.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    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
     
    Kkora likes this.
  2. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    use dispatchCommand. Like this:
    PHP:
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "takemoney " $sender->getName() . " 10000");
    Or a full:
    PHP:
    public function onCommand(CommandSender $senderCommand $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.");
                    }
                }
                         }
                    }
            
     
    Last edited: Dec 20, 2018
  3. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    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 $senderCommand $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
     
  4. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    Just find that bug and fix. My server aren't having any issues with that.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.