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

Should this work?

Comments in 'Plugin Development' started by Robotbuilder, Feb 6, 2014.

  1. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    Ok so I have been trying to create a command-based shop plugin. Basically all it does so far is create a
    config file, then read the data from the file. The config file contains data about what the shops sells and the price. I have a function for when a player runs the /shopbuy <item> but I don't know how to give a player an item and take away items. Could you please help me with this? I basically need help finishing the plugin. Thanks for the help! I really appreciate it!
  2. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    I know I'm a newbie.
  3. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    Oh here is the code:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=SimpleShop
    description=A simple configurable  shop for your players!
    version=1.0
    author=R0b0tbuilder
    class=shop
    apiversion=11
    */

    class shop implements Plugin{
       private 
    $api;

       public function 
    __construct(ServerAPI $api$server false){
         
    $this->api $api;
       }
       public function 
    init(){
        
        
    $this->config = new Config($this->api->plugin->configPath($this)."config.yml"CONFIG_YAML, array(
        
    "item-to-sell" => "Apple",
        
    "item-to-sell-amount" => 5,
        
    "price" => "Stick",
        
    "price-amount" => 10,
        ));
      
        
    $this->config->save();
      
        
    $item-to-sell $this->config->get('item-to-sell');

        
    $item-to-sell-amount $this->config->get('item-to-sell-amount');

    $price $this->config->get('price');

        
    $price-amount $this->config->get('price-amount');

    $name "shopbuy " $item-to-sell

         $this
    ->api->console->register($name,"Buy stuff from the shop.", array($this"shopbuy"));
       }

       public function 
    shopbuy($cmd$args$issuer$item-to-sell$item-to-sell-amount$price$price-amount)
    {

    //Add code here to take away the //$price and give the $item-to-sell

         
    $username $issuer->username;
         
    $this->api->chat->sendTo(false"Transaction completed!"$username);

    }

       public function 
    __destruct()
       {

       }
    }

    ?>
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    First of all don't call the class name "shop". If everyone uses that name it will crash when working with other plugins.
    Secomd although there is a chat API, the best method to send a chat is $issuer->sendChat("blah"), where $issueris the player object.
    Third it is not necessary but good practice to make a private $config field in the class after $api, since you use it.
    Fourth you really gotta learn programming. At least look at my tutorial of JavaScript at https://github.com/Connor4898/ModPE-Scripts/wiki/_pages (the first one, basic js tutorials). Because variables can only have names of A-Z, a-z, "_" and 0-9.
    Fifth, in response to your question, the answer is $issuer->addItem($type, $damage, $count) or similar. Search at https://github.com/PocketMine/PocketMine-MP/tree/master/src/Player.php for "function addItem" to find the answer.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Just to extend description of the class name, in each server, each class name must be unique, or an error about redeclaring class will occur. And I hope plugin reviewers will refuse this kind of plugins. (Will you?)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oppositely, you don't need to put hythens in the config. Just use space.
  8. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    To add onto what he said, maybe try learning a bit more PHP from codecademy.com or php.net
    PEMapModder likes this.
  9. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    Ok, so I fixed it. I need to check if a player has the $price_item in there inventory.
    Would it be like this? if(getSlot(3, 245) = true){ }
  10. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    Or maybe I could use hasItem()?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes but it does not show the amount.
    You can use the code in InfoEssentials that counts the inventory. No credit needed :)
    Robotbuilder likes this.
  12. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    BTW The convention developers use is, instead of $item_to_sell, we use $itemToSell.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And also please add tabs.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Line 135 missing close quotation mark.

    Use notepad++ to edit. It is much more convenient to debug.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You totally don't understand the function of register. Read some more tutorials and look at more people's code.
    And command handlers always have 4 parameters: $cmd, $params, $issuer, $alias.
    If you don't know PHP you can read my tutorial at javascript. It is helpful to learn PHP.
  18. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    Ok thanks I do understand object oriented programming. I will fix those errors. I have notepad++
  19. Robotbuilder
    Offline

    Robotbuilder New Member

    Joined:
    Jan 19, 2014
    Posts:
    23
    Minecraft User:
    r0b0tbuilder
    What do you mean by 'tabs'?
  20. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    Tabs as in spacing or indenting. It makes the code easier to read and helps us find and fix any errors easier, as well as for the plugin reviewers to read the code easier as well :)

Share This Page

Advertisement