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

How do args work ?

Comments in 'Plugin Development' started by MyAJVideo, Jul 12, 2015.

  1. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Hey im not sure how to work args corectly so im asking. I cant find anything in the docs.
    For example:
    If you do /kill [player] the player is an argument but how do i program it ?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is not documented because it is a function parameter.

    It is a string array created by splitting the text behind the command with spaces. For /kill [player], [player] is the first item in the array, namely $args[0]

    It doesn't have to be $args. You can call it whatever you like.
    iksaku likes this.
  3. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Ok so if i do / tell $args[0] $args [1]
    ? so it is name then message how would i put the name do i have to do $args[0] = getPlayer ()-> getDisplayName () ?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait, what do you want to do? What context are you in?
  5. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Im trying to understand how i agruments work. In still trying to write my staff plugin but im not sure how i should add staffs to my staffs list by command. But i think i will do it by config file. But i want that you can send a message to a staff without /tell
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    $args is an array containing all parameters of the given command.
    Every argument (or parameter as you like to call it) is split by space
    For example if you have this command: /give [player] [item] [quantity]
    $args[0] is the first parameter ([player])
    $args[1] is the second parameter ([item])
    $args[2] is the third parameter ([quantity])
    As @PEMapModder said before, you can call the variable as you like (for example: $par, $arguments, $parameters...)
    iksaku and MyAJVideo like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Just use
    PHP:
    $player->sendMessage("message");
    -_-#
  8. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    No i mean with a command like / staff [player] we have a problem and this player i dont know how to add
  9. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    So i dont have to say that $args [0] is a player ?
  10. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Thanks man
  11. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    One little qustion. Is it able to only send op's a message ?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait, what do you want to do at all?

    $msg = implode(" ", $args);

    This converts the $args back to a string containing the message, $msg.

    $Server->broadcast($message, Server::BROADCAST_CHANNEL_ADMINISTRATIVE) ;

    This sends $message to all players with the Server::BROADCAST_CHANNEL_ADMINISTRATIVE (pocketmine.broadcast.admin) permission node.
    iksaku and MyAJVideo like this.
  13. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Awesome thanks il put my plugin out soon
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Server::BROADCAST_CHANNEL_ADMINISTRATIVE???
    I never heard of it... LOL
  15. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    It's the permission node for ops, stored in a Constant
    MyAJVideo and Legoboy0215 like this.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The op only permission node pocketmine.broadcast.admin
  17. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    Where can i find the permission node?
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What do you mean by "find"ing it?
  19. MyAJVideo
    Offline

    MyAJVideo Active Member

    Joined:
    May 16, 2015
    Posts:
    148
    Minecraft User:
    mrAJV2010
    is there a list of permissions ?
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder

Share This Page

Advertisement