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

Longer sendTIP

Comments in 'Plugin Development' started by iDirtPlayzMC, Dec 20, 2015.

  1. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    How do I send tip longer than 10 seconds?
  2. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I believe the only way is to repeat it.
  3. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    thanks for the ideas! but I need code xD
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    public function onPlayerJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $player->sendTIP("§l§eWelcome to §bPro§dxim§eity§7 - §eKitPvP!\n§eHave fun! , " $player->getName());
        }
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    You'll need a scheduleRepeatingTask.
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I am not aware of how to repeat certain task... :p Maybe have a look at:
    TimeCommander
    ColourMatch
    BasicHUD
  7. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Basichud use TICK
  8. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Look into Broadcaster's source code...
  9. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Not 100% sure how the RepeatingTask works, but you may be able to do a certain task when the variable $tick equals to certain amount, which can make a longer tip.
    In theory:
    When $tick is 1, send a tip
    When $tick is 3, send a tip
    etc
    (OMG the replies! They are so quick!)
  10. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    // ikr

    neither do i xD thats why im asking here
  11. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Oh yeah, just noticed it is in Plugin Development.
    I bet there will be like tons of thread that are similar to your request, so try searching.
    (10 replies in 8 minutes WTF?!)
  12. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I am, but search tools suck. so yeah.... couldnt find similiar one
  13. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
  14. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Only start the RepeatingTask on PlayerJoinEvent and run it every 10 ticks (if I'm not wrong, 10 ticks = 1 second), you'll need to define a variable $sec as 10 (seconds), and on your task, onRun($tick) do $sec = $sec - 1;
    When $sec != 0, send the tip, then stop the task. (I'm not in my PC, I can't send examples rn)
  15. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    OK, now I'm in my pc.

    Your Task file should be:
    PHP:
    <?php

    namespace example\Example;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    PopupTask extends PluginTask{
        public function 
    __construct(Main $pluginPlayer $player){
            
    $this->plugin $plugin;
            
    $this->player $player;
            
    parent::__construct($plugin);
        }
        public function 
    getPlugin(){   # < - You can use also $this->plugin
            
    return $this->plugin;
        }
        public function 
    onRun($tick){
            
    $this->sec -= 1;   # -= 1 is like = $sec - 1
            
    if($this->getPlugin()->sec == 1){
                foreach(
    $this->getPlugin()->getServer()->getOnlinePlayers() as $player){
                    
    $player->sendTip("Welcome " $player->getName());
                }
            }
        }
    }
    Don't forget to add
    PHP:
    public $sec 10# The amount of seconds.
    public function OnPlayerJoin(PlayerJoinEvent $event){
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new PopupTask($this), 10);
    }
    to your Main class.
    Skullex and Tim // robske Büba like this.
  16. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Aweosme!
  17. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    20 ticks = 1 second
  18. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    You can create it on the same file, just with different classes. I think this should work.
    PHP:
    <?php
    namespace whatever_name\tip;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\plugin\PluginTask;
    class 
    Main extends PluginBase
    {
        public 
    $tasks = [];
        public 
    $secs 10;
        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onJoin(PlayerJoinEvent $e)
        {
            
    $this->tasks[$e->getPlayer()->getName()] = $this->getServer()->getScheduler()->scheduleRepeatingTask(new TipTask($this$e->getPlayer()), 20*$this->secs);
        }
    }
    class 
    TipTask extends PluginTask
    {
        private 
    $main;
        private 
    $player;
        public function 
    __construct(Main $plugPlayer $p)
        {
            
    $this->main $plug;
            
    $this->player $p;
            
    parent::__construct($plug);
        }
        public function 
    onRun($currentTick)
        {
            
    $this->main->secs--;
            while(
    $this->main->secs 0)
            {
                
    $this->player->sendMessage("hi, noob");
            }
            if(
    $this->main->secs === 0)
            {
                
    $this->main->getServer()->getScheduler()->cancelTask($this->main->tasks[$this->player->getName()]->getTaskId());
            }
        }
    }
    iDirtPlayzMC likes this.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  20. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Write the sendTip multiple times

Share This Page

Advertisement