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

Delete item and give

Discussion in 'Development' started by Matrox, Aug 14, 2018.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Hi how i could do that when i do the command / test it removes me 5 diamond and it gives me 10 chicken ?
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Have you attempted to do this yourself?
     
  3. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    No no because I am a beginner
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Do you know how to register and handle commands?

    If you do, start with that. Then, in your PluginBase file, you would have a member function onCommand. Assuming this is the only command you have registered, you don't need to worry about the Command or the arguments. I would do something like this after that:
    PHP:
     /** CommandSender $sender */
     
    if($sender instanceof Player) {
       if(
    $sender->getInventory()->contains(Item::get(Item::DIAMOND05))) {
         
    $sender->getInventory()->addItem(Item::get(Item::COOKED_CHICKEN010));
       }
     }
    If you don't understand commands or PHP basics like conditionals(if, else, etc.), you need to research those before asking questions like this.
     
    Muqsit and xXNiceAssassinlo YT like this.
  5. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    [​IMG]

    Don't Work
     
  6. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Try adding
    PHP:
    break;
    after the case ends.
     
  7. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    How that I do not understand (I am a French it is very hard to learn php pocketmine)
     
  8. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
  9. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You don't need to break; when you return values.

    I would guess the code isn't being executed, or you would see an error. Can we see the switch() code?
     
    RumDaDuMCPE likes this.
  10. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    [​IMG]
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Which line in your code is 82?
     
  12. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    [​IMG]
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Replace the ; after case "plastron" with a :

    Also, if you could send the code itself, or a screenshot, that would be much easier. Photos taken from an external device makes it hard to see small details.
     
    RyanShaw likes this.
  14. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    can you do the code before if i do not understand and the : did not laugh change
     
  15. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I'm sorry, I don't know what you mean.

    I could fix your problem if you posted it in code blocks, like this:
    Code:
    [PHP] *Your code* [/PHP]
     
  16. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    PHP:
    <?php

    namespace grade;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\enchantment\EnchantmentEntry;


    class 
    Main extends PluginBase{
     
      public function 
    onEnable(){
        
    $this->getLogger()->info("Plugin activer !!");
      }
     
      public function 
    onDisable(){
        
    $this->getLogger()->info("Plugin Desactiver !!");
      }

            public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool {
                  switch (
    $cmd->getName()){
                 
                    case 
    "vip";
                      
    $sender->sendMessage("====§aVip§r====");
                      
    $sender->sendMessage("Acces au command:");
                      
    $sender->sendMessage("- /feed");
                      
    $sender->sendMessage("- /broadcast");
                      
    $sender->sendMessage("- /fly");
                      
    $sender->sendMessage("Items:");
                      
    $sender->sendMessage("- 5 box Extreme");
                      
    $sender->sendMessage("- 20 000$");
                    return 
    true;
             
                       case 
    "vip+";
                       
    $sender->sendMessage("====§aVip+§r===="); 
                       
    $sender->sendMessage("Acces au command:");
                       
    $sender->sendMessage("- /feed");
                       
    $sender->sendMessage("- /broadcast");
                       
    $sender->sendMessage("- /heel");
                       
    $sender->sendMessage("- /fly");
                       
    $sender->sendMessage("Items:");
                       
    $sender->sendMessage("- 6 box Extreme");
                       
    $sender->sendMessage("- 2 box simple");
                       
    $sender->sendMessage("- 40 000$");
                        return 
    true;
               
                       case 
    "claziapack";
                         
    $sender->sendMessage("====§aClaziaPack§r===="); 
                         
    $sender->sendMessage("Acces au command:");
                         
    $sender->sendMessage("- /feed");
                         
    $sender->sendMessage("- /broadcast");
                         
    $sender->sendMessage("- /heel");
                         
    $sender->sendMessage("- Fly");
                         
    $sender->sendMessage("Items:");
                         
    $sender->sendMessage("- 6 box Extreme");
                         
    $sender->sendMessage("- 6 box simple");
                         
    $sender->sendMessage("- Full Clazia");
                            return 
    true;
               
               
                            case 
    "skyler";
                         
    $sender->sendMessage("====§aSkyler§r===="); 
                         
    $sender->sendMessage("Acces au command:");
                         
    $sender->sendMessage("- /feed");
                         
    $sender->sendMessage("- /broadcast");
                         
    $sender->sendMessage("- /heel");
                         
    $sender->sendMessage("- Message en rouge");
                         
    $sender->sendMessage("- /fly");
                         
    $sender->sendMessage("Items:");
                         
    $sender->sendMessage("- 6 box Extreme");
                         
    $sender->sendMessage("- 10 box simple");
                         
    $sender->sendMessage("- 100 000$");
                         
    $sender->sendMessage("- Full Clazia");
                         
    $sender->sendMessage("- 5 pommes de notch");
                           
                           case 
    "plastron";
                             
                      if(
    $sender instanceof Player) {
                         if(
    $sender->getInventory()->contains(Item::get(Item::DIAMOND05))) {
                    
    $sender->getInventory()->addItem(Item::get(Item::COOKED_CHICKEN010));
                     }
                    }

                      return 
    true;
                           
                         
                   }
                             
             
          }
             
    }
     
  17. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    PHP:
    <?php

    namespace grade;

        use 
    pocketmine\Server;
        use 
    pocketmine\Player;
        use 
    pocketmine\event\Listener;
        use 
    pocketmine\command\CommandSender;
        use 
    pocketmine\plugin\PluginBase;
        use 
    pocketmine\command\Command;
        use 
    pocketmine\item\Item;
        use 
    pocketmine\item\enchantment\Enchantment;
        use 
    pocketmine\item\enchantment\EnchantmentEntry;


    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getLogger()->info("Plugin activer !!");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("Plugin Desactiver !!");
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool {
            switch (
    $cmd->getName()) {

                case 
    "vip":
                    
    $sender->sendMessage("====§aVip§r====");
                    
    $sender->sendMessage("Acces au command:");
                    
    $sender->sendMessage("- /feed");
                    
    $sender->sendMessage("- /broadcast");
                    
    $sender->sendMessage("- /fly");
                    
    $sender->sendMessage("Items:");
                    
    $sender->sendMessage("- 5 box Extreme");
                    
    $sender->sendMessage("- 20 000$");
                    return 
    true;
                    break;

                case 
    "vip+":
                    
    $sender->sendMessage("====§aVip+§r====");
                    
    $sender->sendMessage("Acces au command:");
                    
    $sender->sendMessage("- /feed");
                    
    $sender->sendMessage("- /broadcast");
                    
    $sender->sendMessage("- /heel");
                    
    $sender->sendMessage("- /fly");
                    
    $sender->sendMessage("Items:");
                    
    $sender->sendMessage("- 6 box Extreme");
                    
    $sender->sendMessage("- 2 box simple");
                    
    $sender->sendMessage("- 40 000$");
                    return 
    true;
                    break;

                case 
    "claziapack":
                    
    $sender->sendMessage("====§aClaziaPack§r====");
                    
    $sender->sendMessage("Acces au command:");
                    
    $sender->sendMessage("- /feed");
                    
    $sender->sendMessage("- /broadcast");
                    
    $sender->sendMessage("- /heel");
                    
    $sender->sendMessage("- Fly");
                    
    $sender->sendMessage("Items:");
                    
    $sender->sendMessage("- 6 box Extreme");
                    
    $sender->sendMessage("- 6 box simple");
                    
    $sender->sendMessage("- Full Clazia");
                    return 
    true;
                    break;


                case 
    "skyler":
                    
    $sender->sendMessage("====§aSkyler§r====");
                    
    $sender->sendMessage("Acces au command:");
                    
    $sender->sendMessage("- /feed");
                    
    $sender->sendMessage("- /broadcast");
                    
    $sender->sendMessage("- /heel");
                    
    $sender->sendMessage("- Message en rouge");
                    
    $sender->sendMessage("- /fly");
                    
    $sender->sendMessage("Items:");
                    
    $sender->sendMessage("- 6 box Extreme");
                    
    $sender->sendMessage("- 10 box simple");
                    
    $sender->sendMessage("- 100 000$");
                    
    $sender->sendMessage("- Full Clazia");
                    
    $sender->sendMessage("- 5 pommes de notch");
                    return 
    true;
                    break;

                case 
    "plastron":
                    if (
    $sender instanceof Player) {
                        if (
    $sender->getInventory()->contains(Item::get(Item::DIAMOND05))) {
                            
    $sender->getInventory()->addItem(Item::get(Item::COOKED_CHICKEN010));
                        }
                    }
                    return 
    true;
            }

        }

    }
     
    Last edited: Aug 17, 2018
    corytortoise 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.