Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Whats wrong with this code??

Comments in 'Plugin Development' started by Hittmana, Feb 14, 2016.

  1. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    PHP:
    <?php
    namespace Hittmana\TradePro;
    /*
    *  
    *      VERSION 0.3.5
    *
    *      TradePro was created by @Hittmana to aid the process of trading on PocketMine servers.
    *     By using TradePro you will allow your users to easily and safely trade items without
    *     having to worry about the other person lying and not giving the items they said they would.
    *     TradePro can also be found on GitHub and if you wish you can send a fork request to add to
    *     this project. Please ask if you do wish to fork this to use in your own project.
    */                       
    use pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\Item;
    class 
    MainClass extends PluginBase implements Listener
    {
        public function 
    onEnable()
            {
            
    $this->getLogger()->info("TradePro enabled v0.3.5");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
        public function 
    onDisable()
            {
            
    $this->getLogger()->info("TradePro disabled v0.3.5zx");
            }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
            {
            if(
    $sender instanceof Player)
            {
                
    $name $sender->getName();
                    if (
    $command->getName() == "trade")
                        {
                        
    $this->getLogger()->info("[TradePro]" "IT WORKS!!" $name "USED IT!!!!");
                        
    $recipient $this->getServer()->getPlayer($args[0]);
                            if(
    $recipient instanceof Player)
                                {
                                
    $trader $sender->getName();
                                
    $recipient->sendMessage("[TradePro]" $trader " wants to trade with you!"); 
                                
    $sender->sendMessage("[TradePro]" "You sent a trade request " $recipient ". Lets hope they say YES!");
                                
    $item1 $args[1];
                                
    $amount1 $args[2];
                                
    $item2 $args[3];
                                
    $amount2 $args[4];
                                return 
    true;
                                }
                                else
                                {
                                    
    $this->getLogger()->info("Must be run ingame!");
                                    return 
    false;
                            
    // /trade 0<player> 1<item youll trade> 2<amount youll trade> 3<what you want> 4<amount you want>
                                
    }
                if (
    $command->getName() == "tradeaccept")
                    {
                        
    $sender->sendMessage("[TradePro]" "You accepted trade request from " $trader);
                        
    $trader->sendMessage("[TradePro]" $sender " accepted!");
                        
    $player $sender;
                        
    $player->getInventory()->setItem(0Item::get($item1,0,$amount1));
                        
    $this->getServer()->getPlayer($trader)->getInventory()->removeItem(Item::get($item10$amount1));
                        
    $trader->sendMessage("[TradePro]" "You traded " $item1 "x" $amount1 "with " $player); 
                        
    $player->sendMessage("[TradePro]" "You traded " $item2 "x" $amount2 "with " $trader);
                        
    $trader->getInventory()->setItem(0Item::get($item2,0,$amount2));
                        
    $this->getServer()->getPlayer($player)->getInventory()->removeItem(Item::get($item20$amount2));
                    return 
    true;
                    }
                if (
    $command->getName() == "tradedecline")
                    {
                        
    $sender->sendMessage("[TradePro]" "You declined the trade request from " $trader);
                        
    $trader->sendMessage("[TradePro]" $sender " declined your trade request");
                    return 
    true;
                    }  
            }
        }  
      return 
    false;
      }
    }
    Ok whats wrong with this code?!?! I do the command /trade Hittmana 1 1 3 1 and it sends the request, but when i do /tradeaccept Hittmana it does NOTHING not even in console.
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    undefined $trader
  3. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    $trader is defined as $sender->getName()
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    and will be undefined when the player types /tradeaccept, it just defines it when he types /trade, then it'll be completely gone.
  5. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Then how can I make it so I can use it in the next command?
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    $this->trader, but then it'll not work for multiple players though, and other things have to be done like using unset() when trade is accepted
  7. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    :/ I just use unset(varname) right?
    PocketKiller likes this.
  8. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Is that how I do it?
    PocketKiller likes this.
  9. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ok can someone correct my code please? I really need help on this.
  10. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    Ugh don't attempt to make a plugin if you don't have the knowledge and need help along the whole way this is like your tenth forum about this

    I'm not saying your not supposed to ask for help but asking every step along the way is too much

    I have no further time to waste
    Last edited: Feb 14, 2016
    applqpak likes this.
  11. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Don't answer if you aren't gonna help.
  12. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    I wrote the rest of this and I need help with this part. So unless you going to help don't bother replying.
  13. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    My friend whaat is problem ? Do You have crash ?
  14. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    No it simply does nothing when i do /tradeaccept Hittmana
  15. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Please Give me your crash
  16. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
  17. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Read the posts. I asked if unset(NameOfVariable) is the correct declaration.
  18. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Ritch there is no crash it does nothing and shows nothing in console.
  19. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Hmmm.... Okay
    PHP:
            $this->getLogger()->info("Must be run ingame!");
                                    return 
    false;
                                      break;
                            
    // /trade 0<player> 1<item youll trade> 2<amount youll trade> 3<what you want> 4<amount you want>
                                
    }
  20. Hittmana
    Offline

    Hittmana Active Member

    Joined:
    Jul 26, 2015
    Posts:
    224
    Minecraft User:
    move_it
    Says i can't use break; Says it must be in a for, foreach, etc. Statement

Share This Page

Advertisement