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

[ERROR] help with getid()

Comments in 'Plugin Development' started by jerlegoman, Jun 15, 2014.

  1. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    :)Hi my name is jerlegoman I am developing a new plugin (FOR OLD API!) and I an having an error that says
    # PocketMine-MP Error Dump Mon Jun 16 01:18:21 HKT 2014
    Error: array (
    'type' => 'E_ERROR',
    'message' => 'Call to a member function getID() on a non-object',
    'file' => 'C:\\Users\\Jeremy Haft\\Desktop\\PocketMine-MP use only\\plugins\\TOspawn.php',
    'line' => 19,
    )
    HERE is the code!
    PHP:
    [10] class spaplus implements Plugin {
    [
    11] private $api;
    [
    12] public function __construct(ServerAPI $api,$server false) {
    [
    13$this->api $api;
    [
    14] }
    [
    15] public function init() {
    [
    16$this->api->addHandler("player.action",array($this,"touch"));
    [
    17] }
    [
    18] public function touch($data) {
    [
    19] if($data["item"]->getID() == 345) {
    [
    20]
    [
    21] echo($data->sendChat("** Have Fun and BE CARE FULL!"));
    the numbers are just to tell you the numbers of the lines
    Thanks :)
    LDX likes this.
  2. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    player.action is checking what you have in your hand
  3. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    echo doesn't work in mcpe
  4. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    player.action is when you have that item and you touch that screen. let me give you an example
    PEMapModder likes this.
  5. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    oh I didn't know but the error is on line 19
  6. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    here. this by me and blinksun. so give him credit :)
    Code:
    <?php
    
    /*
    __PocketMine Plugin__
    name=DrinkBucketWater
    description=Drink Bucket Water to Heal (1 heart)
    version=1.0
    author=BlinkSun,swagboy47
    class=DrinkBucketWater
    apiversion=11,12
    */
    
    class DrinkBucketWater implements Plugin
    {
        private $api;
    
        public function __construct(ServerAPI $api, $server = false) {
            $this->api = $api;
        }
    
        public function init() {
            $this->api->addHandler("player.action", array($this, "eventHandle"), 50);
        }
    
        public function eventHandle($data, $event) {
            switch ($event) {
                case "player.action":
                    $player = $data["player"];
                    $item = $player->getSlot($player->slot);
                    if($item->getID() === BUCKET and $item->getMetaData() === WATER and $player->entity->getHealth() < 20) {
                        $player->entity->heal(2, "drinking");
                        $player->setSlot($player->slot, BlockAPI::getItem(BUCKET, AIR, 1));
                    }
                    break;
            }
        }
    
        public function __destruct() {
        }
    }
    
    jerlegoman likes this.
  7. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    you didnt do
    $item = $player->getSlot($player->slot);
  8. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    ok yes and in TPcompass plugin has that too
  9. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and do
    $player = $data["player"];
    its much easier to work with
  10. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    i can fix it if you gave me the full code
  11. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    do I need eventhandle too
  12. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    nah if that's all that I need to fix then ill fix it my self
  13. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    yes you do
  14. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    if you need more help PM me and i well answer
  15. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    yep
    jerlegoman likes this.
  16. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    ok thanks ill give you some credit when I publish the plugin but when im done the plugin it is going to tp to spawn when you tap on the compass
  17. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    tip: its kind of simple. when i published a simple plugin they didn't approve it
    jerlegoman likes this.
  18. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    once I learn the new API yes
  19. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    player.action haven't been added to pocketmine 1.4 i think
  20. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    even if they don't approve it it will still be special because it would be my first good plugin
    LDX and swagboy47 like this.

Share This Page

Advertisement