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

Solved Item shop

Comments in 'Plugin Development' started by Creeperface, Aug 15, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    hi im trying to make shop with items but it doesnt work properly. :/
    PHP:
    public function clickItem(Player $pItem $buyItemItem $costItem){
            
    $inv $this->players[strtolower($p->getName())]['items']; //saved inventory object
            
    $cost $costItem->getCount();
            
    $remove = [];
            foreach(
    $inv->getContents() as $slot => $item){
                if(
    $cost >= 1){
                    if(
    $item->getId() === $costItem->getId() && $item->getDamage() === $costItem->getDamage() && $item->getCount() >= 1){
                        if(
    $item->getCount() > $cost){
                            
    $this->remove[$slot] = Item::get($item->getId(), $item->getDamage(), $item->getCount() .- $costItem->getCount());
                            
    $cost 0;
                            continue;
                        }
                        
    $this->remove[$slot] = Item::get(000);
                        
    $cost $cost .- $item->getCount();
                        continue;
                    }
                }
                else{
                    foreach(
    $remove as $sl => $it){
                        
    $inv->setItem($sl$it);
                    }
                    
    $inv->addItem($buyItem);
                    
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::GREEN."Bought {$buyItem->getName()}");
                    return;
                }
            }
            
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::RED."You don't have enough ".$costItem->getName());
        }
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OMG it is so easy :D
    PHP:
    public function clickItem(Player $pItem $buyItemItem $costItem){
            
    $inv $this->players[strtolower($p->getName())]['items'];
            if(
    $inv->contains($costItem)){
                
    $inv->removeItem($costItem);
                
    $inv->addItem($buyItem);
                
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::GREEN."Purchased {$buyItem->getName()}");
                return;
            }
            
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::RED."You don't have enough ".$costItem->getName());
        }
    DunxandMinecraft likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How much did you copy from PocketMine? :p
    Creeperface and jojoe77777 like this.
  4. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    He probably copied some other shop plugins.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Everyone is not like you :p By the way i didnt see this code in any plugin i saw. I just though method contains search only per slot and removeItem too.
    PEMapModder likes this.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Dont be so ccritical pleaseā€¦

Share This Page

Advertisement