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

how can i assign $player to a player?

Comments in 'Plugin Development' started by CoolGuyPL, Nov 1, 2014.

  1. CoolGuyPL
    Offline

    CoolGuyPL New Member

    Joined:
    Sep 24, 2014
    Posts:
    43
    Minecraft User:
    CoolGuyPlays
    well $player = $server-> blah idk pls help?
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    What player do you want to assign it to?
  3. CoolGuyPL
    Offline

    CoolGuyPL New Member

    Joined:
    Sep 24, 2014
    Posts:
    43
    Minecraft User:
    CoolGuyPlays
    any player name like a variable.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If you are inside the plugin class you can do:
    PHP:
    $player $this->getServer()->getPlayer($name);
    Where $name is the username of the player. You should also check that $player !== null unless you are sure they will be online.
    iJoshuaHD and CoolGuyPL like this.
  5. CoolGuyPL
    Offline

    CoolGuyPL New Member

    Joined:
    Sep 24, 2014
    Posts:
    43
    Minecraft User:
    CoolGuyPlays
    thanks!
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Since the PocketMine API is messy with some functions returning null and some returning false on failure/empty, I recommend using instanceof Player to check as a practice.
    Falk likes this.
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That would require a use statement and I didn't want to confuse :)
    getPlayer() returns null and has done since API 1.0.0
    PEMapModder likes this.

Share This Page

Advertisement