1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

HELP, PLAYER NAME WITH SPACE

Discussion in 'Development' started by GalonAquaa, Oct 22, 2020.

  1. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    please help, how to solve this problem. example: I make keyshop with code. if a player uses a name with a space number (for example: Steve 123) and buys the item, the number of items received does not match the config, but the total is 123 items, the same as the player's gamertag number. This applies if the player uses spaces


    $this->getServer()->dispatchCommand(new \pocketmine\command\ConsoleCommandSender(), "key Common ".$sender->getName()." ".$this->getConfig()->get("common.amount"));
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    That is one of the reasons why dispatching commands are discouraged! Why don't you use the plugin's API to give the key?
     
    GalonAquaa likes this.
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    I'd suggest looking into what Primus wrote, but if you insist on doing it your way, it is of course possible to solve this issue.
    All arguments which contain spaces and are used in a command string should be encapsulated in quotation marks.

    Example:
    Instead of "key Common Steve 123" you should use this as the command string:
    key Common "Steve 123"

    That way Steve and 123 are interpreted as a single command argument, hence "Steve 123".
     
    Primus, GalonAquaa and IvanCraft623 like this.
  4. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    can you give me a sample code pls?
     
  5. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    if I use the API, can you provide a sample code? pls
     
  6. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Why do you need a sample code? You really just have to add quotation marks around the player name:
    PHP:
    $playerName "Steve 123";
    $cmdString "key Common \"".$playerName."\""// Notice the use of the backslash in \" which is used to escape the " character
     
    GalonAquaa likes this.
  7. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    sorry, if I use this code it only works with the player name steve 123? Isn't it for all players with space names?
     
  8. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    No, this works for all player names, even those without any spaces at all. You just have to replace the variable $playerName.
     
  9. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    Use this code:

    PHP:
    $keyAmount $this->getConfig()->get("common.amount"));
    $lowercaseCrateType "Common";
    $this->getServer()->getPluginManager()->getPlugin("
    MysteryCrate
    "
    )->giveKey($sender$lowercaseCrateType$keyAmount);
    $sender->sendMessage("§aYou got one Common Key")
     
  10. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    sorry, I tried and there were some error

    ErrorException: "Undefined variable: lowercaseCrateType" (EXCEPTION)
     
  11. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    You forgot to define $lowercaseCrateType
     
  12. GalonAquaa

    GalonAquaa Spider

    Messages:
    12
    i was add define $lowercaseCrateType
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.