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

Need Help With A Plugin...

Comments in 'Plugin Development' started by TryoneLegendZzz, Jun 4, 2015.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    Ok So I Am Creating A Hunger Plugin And When I Use CallBackTask And Try To Add
    public function hunger20(){
    $p = $this->getServer()->getPlayer();
    $p->setHealth(20);

    }
    it says...
    unidenified variable: getServer() please help
  2. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Does the class extend PluginBase?
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    yes it does
  4. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Could you show all the code in your file, then?
    I feel maybe you forgot to use a "using" statement, but I could be wrong.

    Edit:
    Also, if there's a moderator, this is obviously not in the right section.
    @TryoneLegendZzz whenever you need help, post a thread in Plugin Development, not the Resources section.
  5. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    here

    Attached Files:

  6. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Hmm...I can't find the problem. I opened it up in Netbeans and added it to my project just to test it out. Code completion worked in the file upon using $this, and showed all the functions inherited from PluginBase (which indicates that getServer() was defined).
    Maybe you configured your project wrong?
  7. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    i am sorry i am new to the new API what do you mean?
  8. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    No, it's ok.
    Your IDE is what program you use to code PHP (like Netbeans, PHPStorm, etc). If that program is showing an "undefined variable" error, then you likely forgot to reference the pocketmine files. Take a look at this, to see what I mean by referencing (that is for netbeans; instructions may be slightly different for other IDE's).
  9. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    but the terminal is showing this error
  10. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    I tried running a server with your plugin and it spits out a bunch of InvalidArgumentCountException 's, all about Server::getPlayer(). Nothing about getServer() being undefined.
    Couple tips:
    • getPlayer() needs a string argument, so the server can return the player found with that name. That'll get rid of the exceptions.
      e.g.
      PHP:
      $p $this->getServer()->getPlayer($playerName);
      //not just $this->getServer()->getPlayer();
    • your functions using getPlayer() dont have a string parameter to supply getPlayer() with. You need a parameter to do so.
      e.g.
      PHP:
      public function hunger19($player){ //string parameter to pass
          
      $p $this->getServer()->getPlayer($player);
          
      $p->setHealth(19);
          
      $p->sendMessage("Your Health Is 19!");
      }

    About the "unidentified" error, I don't know any other possibilities except the IDE. Anyone else have input on this?
  11. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    tested it with the code you gave me and this happened.... Screenshot_22.png
  12. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    It's saying that strtolower() expects a string parameter to be passed. $p is a Player object, not a string. To pass the player's name, use $p->getName().
    PHP:
    strtolower($p->getName());
  13. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    how do i set this up?
  14. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    @Falk wrong part of the forum?
    PEMapModder likes this.

Share This Page

Advertisement