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

Command not working

Comments in 'Plugin Development' started by Megatum, May 19, 2014.

  1. Megatum
    Offline

    Megatum New Member

    Joined:
    May 18, 2014
    Posts:
    4
    Minecraft User:
    Megatum
    Hello pocketmine community. Recently I have been trying to make a plugin that adds a command called /heal to the game. For those of you that play PC minecraft, you will probably be familiar with it. For those who don't, basically doing /heal regenerates your health back to 20. When I try to issue the command /heal , it says that the command does not exist. I am using the old api and my plugin is attached. I would really appreciate it if somebody who is experienced with Pocketmine plugins would tell me what im doing wrong. Many thanks. ~Megatum

    Attached Files:

    • Heal.php
      File size:
      844 bytes
      Views:
      14
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Look:
    PHP:
    $this->api->console->register($command$description, array($this$function));
    You the $function needs to be the same in
    Code:
    public function $function(){}
    You registered the command with the function "heal" (that doesn't exist in the code) and registered the desired function with the name "cmd". That's why it doesn't work :p
    PEMapModder, Megatum and Falk like this.
  3. Megatum
    Offline

    Megatum New Member

    Joined:
    May 18, 2014
    Posts:
    4
    Minecraft User:
    Megatum
    *facepalm*
    Lol thanks for pointing it out. The command now works but instead of healing it just crashes the server.... Here is my dump log. Do you know why it is crashing?
    Code:
    ```
    # PocketMine-MP Error Dump Mon May 19 17:51:40 UTC 2014
    Error: array (
      'type' => 'E_ERROR',
      'message' => 'Call to a member function heal() on a non-object',
      'file' => '/Users/emretekcan/Desktop/POCKETMINE/plugins/Heal.php',
      'line' => 30,
    )
    
    THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.
    Code:
    [21]                 $this->api->console->register("heal", "Heal yourself back to full health", array($this, "heal"));
    [22]         }
    [23]    
    [24]      public function heal($cmd, $args, $issuer){
    [25]         switch($cmd){
    [26]             case "heal":
    [27]            if($args[0] == ""){
    [28]                $username = $issuer->username;
    [29]                     $output = "You have been healed!";
    [30]                      $player->entity->heal(20, $username, true);
    [31]
    [32]                     return $output;
    [33]                 }
    [34]         }
    [35]      }
    [36]
    [37]     
    [38]
    [39]
    [40]                
    
    
    PocketMine-MP version: Alpha_1.3.12 #620 [Protocol 14; API 12]
    Git commit: 0000000000000000000000000000000000000000
    Source SHA1 sum: e5f2f82202587903385681486b0d3626ae31b569
    uname -a: Darwin Emres-MacBook-Air.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
    PHP Version: 5.5.9
    Zend version: 2.5.0
    OS : Darwin, mac
    Debug Info: array (
      'tps' => 18.814499999999999,
      'memory_usage' => '26.05MB',
      'memory_peak_usage' => '26.69MB',
      'entities' => 1,
      'players' => 1,
      'events' => 24,
      'handlers' => 32,
      'actions' => 30,
      'garbage' => 0,
    )
    
    
    Parameters: array (
      'input' =>
      array (
      ),
      'commands' =>
      array (
      ),
      'flags' =>
      array (
      ),
    )
    
    
    server.properties: array (
      'server-name' => '-=MEGALIZED-CRAFT=-',
      'server-port' => 19132,
      'memory-limit' => '256M',
      'gamemode' => 0,
      'max-players' => 10,
      'spawn-protection' => '-1',
      'white-list' => false,
      'enable-query' => false,
      'enable-rcon' => true,
      'rcon.password' => '******',
      'send-usage' => true,
      'description' => 'Server run by Megatum',
      'motd' => 'Welcome @player to MegalizedCraft',
      'server-ip' => '',
      'server-type' => 'normal',
      'last-update' => 1400520386,
      'announce-player-achievements' => true,
      'view-distance' => '10',
      'allow-flight' => false,
      'spawn-animals' => true,
      'spawn-mobs' => true,
      'hardcore' => false,
      'pvp' => true,
      'difficulty' => 3,
      'generator-settings' => '',
      'level-name' => 'world',
      'level-seed' => '',
      'level-type' => 'DEFAULT',
      'auto-save' => true,
    )
    
    
    Loaded plugins:
    ChatBot 0.8 by BlinkSun
    Claymores 1.0 by Darunia18
    Disguise 0.0.1 by Falk
    EconomyAirport 1.1.0 by onebone
    EconomyAirportPlus 1.1.1 by onebone
    EconomyAPI 1.4.1 by onebone
    EconomyAuction 1.0.11 by onebone
    EconomyCasino 1.0.6 by onebone
    EconomyJob 1.0.11 by onebone
    EconomyLand 1.4.6 by onebone
    EconomyProperty 1.0.4 by onebone
    EconomyPShop 1.1.8 by onebone
    EconomySell 1.1.15 by onebone
    EconomySellPlus 1.0.3 by onebone
    EconomyShop 1.2.4 by onebone
    EconomyShopPlus 1.0.6 by onebone
    EconomyTax 1.0.8 by onebone
    Heal 1.0.0 by Megatum
    Reacram 1.0.1 by MinecrafterJPN
    SimpleWarp 0.2.2 by Falk
    SimpleWorlds 0.3.1 by PocketMine Team
    Suggestions 1.0.0 by Megatum
    UChat 2.10 by 1ron_pon3
    WorldEditor 0.9.1 by shoghicp
    
    
    Loaded Modules: array (
      'Core' => '5.5.9',
      'date' => '5.5.9',
      'ereg' => false,
      'pcre' => false,
      'sqlite3' => '0.7-dev',
      'zlib' => '2.0',
      'bcmath' => false,
      'ctype' => false,
      'curl' => false,
      'fileinfo' => '1.0.5-dev',
      'filter' => '0.11.0',
      'hash' => '1.0',
      'json' => '1.2.1',
      'standard' => '5.5.9',
      'SPL' => '0.2',
      'pcntl' => false,
      'posix' => false,
      'pthreads' => '0.1.0',
      'Reflection' => '$Id: 31d836a7ac92a37b5c580836d91ad4736fe2f376 $',
      'shmop' => false,
      'sockets' => false,
      'mysqlnd' => 'mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $',
      'mysqli' => '0.1',
      'tokenizer' => '0.1',
      'yaml' => '1.1.1',
      'zip' => '1.11.0',
    )
    Memory Usage Tracking:
    AwA=
    
    I left out the random symbols bit :P
    
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Here you have some optimizations:
    PHP:
    public function heal($cmd$args$issuer){
         if(
    count($args) == 0){
              
    $issuer->setHealth(20);
              return 
    "You have been healed"
         
    }
    }
    Megatum and Falk like this.
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    PHP:
    $issuer->entity->setHealth(20"generic"true);
    PEMapModder, Megatum and iksaku like this.
  6. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Here, use this:

    Attached Files:

    Megatum likes this.
  7. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Use this:
    Megatum likes this.
  8. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Lol I posted the same time as @iksaku. xD
    Megatum likes this.
  9. Megatum
    Offline

    Megatum New Member

    Joined:
    May 18, 2014
    Posts:
    4
    Minecraft User:
    Megatum
    Thanks guys my plugin works just like I want it to now! Have a nice day :)
    Falk likes this.
  10. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    You're welcome ;)

    But I wrote it in my phone :p And also do a research on the API docs :p (yes, the current one xD)
    Megatum likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think he wanted
    PHP:
    $player $this->api->player->get(isset($args[0]) ? $args[0]:$issuer->username)
  12. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Without ternary logic:
    PHP:
    if(isset($args[0])) $player $this->api->player->get($args[0]);
    else 
    $player $issuer;
    PEMapModder likes this.

Share This Page

Advertisement