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

List of all MCPE Events?

Comments in 'Plugin Development' started by Huntereb, Sep 12, 2013.

  1. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Looking to learn PHP in the coming days, I have a link to all of the available API's, but in order to use most of them I'd need to know the events I can use to trigger them.

    Sorry if this is incredibly too obvious, and thanks!
  2. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    Darklust likes this.
  3. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Awesome, sorry for looking like an idiot and asking the obvious.

    Thanks!
  4. ZacHack
    Offline

    ZacHack Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    325
    Plugins:
    6
    Minecraft User:
    _ZacHack_
    Hey @InusualZ do you know the difference between player.connect and player.join?
  5. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    My guess is "player.connect" means the player has connected to the server, and "player.join" means the player has actually spawned in the game.
  6. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    Exacly
  7. ZacHack
    Offline

    ZacHack Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    325
    Plugins:
    6
    Minecraft User:
    _ZacHack_
    Oh ok I tried both of them and I thot the action came at the same time
  8. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    No he didn't spawned in the game,
    pocketmine just loaded the player data
    Last edited: Sep 13, 2013
  9. ZacHack
    Offline

    ZacHack Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    325
    Plugins:
    6
    Minecraft User:
    _ZacHack_
    Yah @InusualZ and @Huntereb the action i make it do in my plugin does it at the same time on both events
  10. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    433
    Plugins:
    14
    Minecraft User:
    shoghicp
    Official docs~. in 1.4~~
  11. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Could someone write me up a basic plugin that basically does the following: "If a player chats, then broadcast a message"? I'm unsure how to use target specific variables in an event (Like saying a specific word, etc.). Has anyone yet written a guide to help better understand the way Pocketmine handles plugins, and how to set up your script? I've been looking at a few recent simple plugins and I am not exactly certain how to set up API's and look for events. I know that you can call an API and set it's values, but I'm unsure how to call out the API after I have set its data.

    Just a heads up, I just started trying to understand this today from a basic tutorial to PHP. I have a basic understanding of how to get things rolling, like "if", "Else", and "Functions". I can go a little more in-depth than that though.

    Thanks for the help.
  12. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    First learn PHP. Second see the example in the wiki of pocketmine github
  13. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Alright, can anyone write me up an example of a config function? Like, creating the config and reading a specific value from it? I'm modifying one of Antisober552's plugins to work how I want it, where instead of counting down over time and deleting the chunks so the server resets them after turning back on (Which doesn't currently work), it will just delete the previous map and replace it with a map from another file (Which I think I already have down to a basic form). The only issue I have with this is that the original plugin would reset the map after 12 hours, which is short enough that, if you had to reset the server, those 12 hours would pass fairly fast. But in my plugin I have it set at a total time of 3 days, which is much too long to have to go back through if the server has to reset manually. That's why I want a config that can read the initial time value, and store the passed time value. All I really need though is an example of how to create a config file function, then I can probably figure out the rest myself.

    I'm at school, so I can't do much research on external projects, this would be very helpful for me.

    Thanks!
  14. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    You can make a yaml config file like this:
    PHP:
    $this->config = new Config($this->api->plugin->configPath($this) . "config.yml"CONFIG_YAML, array(
          
    'option1' => false,
          
    'option2' => true,

    ));
    The first argument is the location of the config file, in this case in the folder from the plugin.
    The second argument is the type of config file, if you want to make a yml file you want to set it to CONFIG_YAML
    if you want a list ( a list of names for exemple ) you can use CONFIG_LIST.
    these are the most used types, but here's a list of all the available types:
    Code:
    CONFIG_PROPERTIES
    CONFIG_CNF
    CONFIG_JSON
    CONFIG_YAML
    CONFIG_SERIALIZED
    CONFIG_LIST
    The last argument needs to be an array ( can be an empty array ) that contains the default values,
    if a key of the array doesn't exist in the config file, it will create it again and set the default value.

    Get the value of a key:
    PHP:
    $this->config->get('option1');

    Set the value of a key:
    PHP:
    $this->config->set('option1'true);

    Set a value to all keys:
    PHP:
    $this->config->setAll(true);

    Save the config to his file:
    PHP:
    $this->config->save();

    Reload a config file:
    PHP:
    $this->config->reload();

    Check if a key exist:
    PHP:
    $this->config->exist('option1');
    Returns true if exists, false otherwhise


    Remove a key:
    PHP:
    $this->config->remove('option1');

    Get all the keys:
    PHP:
    $this->config->getAll(true);
    if you set the argument to false it will return the config file

    These are not all functions, but the most important for me.

    If you want to import the yml file to an array you can do this:
    PHP:
    $this->config $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "config.yml");
    Last edited: Sep 13, 2013
    ZacHack and Huntereb like this.
  15. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Thank you wies! I couldn't have ask for a better definition, this will help me so much (As soon as I can get looping working in Windows)!
  16. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    I've got an issue with a specific area and trying to get it to work exactly how I want it, take a look at this code:

    PHP:
    public function init () {
        
    $this->nr0;
        
    //time() + 60 * 60 *  => current + 12 hours;
        
    $this->api->schedule(120, array($this"mapTime"), array(), true);
        
    $leval $this->server->api->level->getDefault()->getName();
        
    $this->Notice = array(
                    
    "[Notice] Map reset in 11 hours",
                    
    "[Notice] Map reset in 10 hours",
                    
    "[Notice] Map reset in 09 hours",
                    
    "[Notice] Map reset in 08 hours",
                    
    "[Notice] Map reset in 07 hours",
                    
    "[Notice] Map reset in 06 hours",
                    
    "[Notice] Map reset in 05 hours",
                    
    "[Notice] Map reset in 04 hours",
                    
    "[Notice] Map reset in 03 hours",
                    
    "[Notice] Map reset in 02 hours",
                    
    "[Notice] Map reset in 01 hour",
                    
    "[Notice] Map reset",
                    );
            }

    public function 
    mapTime(){
                
    $this->api->chat->broadcast($this->Notice[$this->nr]);
                
    $this->nr++;
                if (
    $this->nr == count($this->Notice)-1) {
                    
    $this->mapReset();
                }
            }
    On line 2, what is "$this->nr= 0;" doing? Is that the initial time, like before I have defined a different time?

    On line 4, could I set "120" to "$value = $this->config->get('option1')" to grab the time set in the config file?

    Is the function named "mapTime" counting down? If so, how?

    I'm trying to make it so when the timer counts down it records it to the config file, so in case the server ends it will keep the previous time. Don't tell me exactly how to do it because I want to learn how to do it myself, but if you could answer the questions above that would be great. Thanks for all the help!
  17. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    The code uses the variable $this->nr to know how many hours passed.

    The code you're using won't work, the time needs to be 20*60*60 to be an hour, 120 is 6 seconds. and $value = $this->config->get('option1') was an exemple to store the value from option1 to the variable $value. First of all you need to make a config file, then you can get the value from the config file with, for exemple $this->config->get('time')

    In the init you define that the server needs to run the function mapTime every 120 ticks ( needs to be 72000 ). so if you know that 20 ticks = 1 second then the server will run the function mapTime every hour. then the function maptime will broadcast the msg from the array $this->Notice with the key $this->nr and then it will add 1 to $this->nr.
    Then it will check if $this->nr is the same as the total notice msg, if so it will run the function mapreset
    Last edited: Sep 13, 2013
  18. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Yeah, I have the config file set up and with my desired values, I just used the default you gave me to ask if it was possible to put it there, so is it?

    And 120 was a placeholder number, I understand how the time works there.

    Oh I see, so it keeps refreshing "nr" by adding 1 to it, and each time an hour passes it runs the next line in the array that matches the number on "nr". I might experiment with that later on to change the interval of it, for longer times, etc. I actually might even just create a command that lets users type /timeleft in the chat to see how much time is remaining (I'd have to figure out how to convert ticks to regular time, but don't worry about it right now).

    Where exactly is it telling the code to keep counting down? I need to change it so the countdown works through the config file and keep refreshing whenever the timer goes down (Or at least every certain amount of ticks, just so it's not constantly writing).
  19. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Nothing is counting down.
    It checks how many notice msg are in the array $this->notice,
    if it's equal to $this->nr + 1 it will reset the map
  20. Huntereb
    Offline

    Huntereb Active Member

    Joined:
    Sep 6, 2013
    Posts:
    41
    Minecraft User:
    Huntereb
    Damn, a lot simpler than I thought. Though, it doesn't work exactly how I want it. I think I'm going to try re-writing it so it works as a countdown that intermittently writes the value to the config file.

Share This Page

Advertisement