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

[Urgent] Player Name String to Object????

Comments in 'Plugin Development' started by Samueljh1, Jan 21, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Ok, Say I have a variable of someone's player name. EG: "Steve". Is there a way i can get a player object out of this string?

    EG: Say i wanted steve to teleport somewhere.... so i would get the object from the player name, and run the command.

    The question is HOW?

    "Steve"->getPlayer() would obviously not work :p

    Thanks.
  2. mclab
    Offline

    mclab Active Member

    Joined:
    Dec 24, 2014
    Posts:
    49
    Minecraft User:
    Dragonflex
    $player->teleport(new Vector3(x, y, z));
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Lol. I know that :p the issue is getting the $player object from a string (or the players name). Thanks anyway :p
  4. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Ok, Lol found it out :pPPP

    Just to help everyone who is a noob like me :pPP, to convert a string name to a player object, use:

    $this->getServer()->getPlayer($thevariablethatholdstheplayersnamelol);
  5. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Don't worry, I've done it :p (i use a player join event anyway so this shouldn't matter :p:p:p)
  6. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    PHP:
    echo $Samueljh1->getAwesomeness();

    99999999

    Lol :p
  7. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    O yea now I am no longer a noob at pocket mine or php :D
  8. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    So if you're inside an event, use:

    PHP:
    public function onPlayerJoin(PlayerJoinEvent $event){
      
    $player $event->getPlayer();
    }
  9. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Lol ik, I'm using this in my skywars mod... And it stores the players inventory before joining (so they ddon't have extra stuff etc) - but I need to clear the player object to detect that they left, so I store the name and convert it back :p (Player Objects are the entity ID, and when your rejoin that changes!!)
  10. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    1. These aren't MODs, they're Plugins
    2. To detect when they leave, use the PlayerQuitEvent ;)
  11. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Lol i Know tht , xD ive already used that, its the fact player objects sre the entity ids and when u rejoin it changes!! The clearing is for the sake of like s billion background tasks checking for that! It all makes sense when u see the code!
  12. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    and omg my phone keyboard is MESSED UP!
  13. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Then why do you use the EntityID? Use the player name instead ;) And you don't need to make background tasks to check that xD just use an event and done!
  14. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    OK lol I'm making loads of mistakes. By baclground tasks, I meant events :p AND I don't use entity IDS. That was my point... Lol why does everyone on this website ALWAYS have to correct every single midget mistake? xD
  15. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You just told that you used player's entity ID .-.
  16. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    O yea I should of used that instead of ->get player(); :p
  17. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    ...damn u AUTOCORRECT
  18. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Use $player->getName(), not the ID nor the Object
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For a single session, storing things with integers (in this case entity IDs) is faster. But if you want to save permanently, you should save with names.
    In LegionPE, each registered name has an autoincrement user ID. Then I just need to fetch the player's ID when he joins using his name, then use the ID instead of the username for future operations, including database saving keys.

Share This Page

Advertisement