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

Solved I need to sub command my plugin as / buy (chicken, cow

Discussion in 'Development' started by ppaalo, May 11, 2020.

  1. ppaalo

    ppaalo Spider

    Messages:
    7
    GitHub:
    ppaalo
    Someone can help me hitting my head 2 days ago
     
  2. ppaalo

    ppaalo Spider

    Messages:
    7
    GitHub:
    ppaalo
    Make a buy sub
    PHP:
        public function onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
          switch(
    $cmd->getName()){
              case 
    "comprar":{
                  
    $sender->sendMessage("§5§lLoja §r§7para ver item da loja utilize: /comprar lista");
                  return 
    true;
              }
              case 
    "comprar lista":{
                  
    $sender->sendMessage("§fCaixa Normal §7(200 De Cash)");
                  
    $sender->sendMessage("§fCaixa Ultra §7(400 De Cash)");
                  
    $sender->sendMessage("§fCaixa Master §7(600 De Cash)");
                  
    $sender->sendMessage("§fUtilize /comprar key (normal,ultra,master)");
          return 
    true;
              }
          }
        }
    }
     
  3. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Hmmmmm
    PHP:
    public function onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
          switch(
    $cmd->getName()){
              case 
    "comprar":
                if(
    $args[0] === null){
                  
    $sender->sendMessage("§5§lLoja §r§7para ver item da loja utilize: /comprar lista");
                  return 
    true;
              }
            if(
    $args[0] === 1){
           switch (
    $args[1]){
           case 
    "cow":
          
    //code
          
    break;
          }
    }
              case 
    "comprar lista":{
                  
    $sender->sendMessage("§fCaixa Normal §7(200 De Cash)");
                  
    $sender->sendMessage("§fCaixa Ultra §7(400 De Cash)");
                  
    $sender->sendMessage("§fCaixa Master §7(600 De Cash)");
                  
    $sender->sendMessage("§fUtilize /comprar key (normal,ultra,master)");
          return 
    true;
              }
          }
        }
     
  4. ppaalo

    ppaalo Spider

    Messages:
    7
    GitHub:
    ppaalo
    Here is giving error ne
    PHP:
    case "comprar":
                if(
    $args[0] === null){
     
  5. Parzival JBC

    Parzival JBC Creeper

    Messages:
    1
    Try this?

    PHP:
    case "comprar":
              if(!isset(
    $args[0])) {
     
              }
     
  6. ppaalo

    ppaalo Spider

    Messages:
    7
    GitHub:
    ppaalo
    And to create a sub of /comprar example /comprar cow
     
  7. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    $args is an array with the arguments of the command, what means if I type /buy thing 300, $args[0] is thing and $args[1] is 300.
    Check if $args[0] equals to the argument desired and if it does, do whatever you want.
     
    HimbeersaftLP likes this.
  8. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    $args basically is an array
    When you typed a command. For example:
    /give BadderNTT dirt 2
    So in this command
    $cmd->getName() will return the name of the command (give)
    $args is an array that every word behind the command's name is a value in this array
    $args[0] is BadderNTT
    $args[1] is dirt
    $args[2] is 2
     
    HimbeersaftLP likes this.
  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.