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

Invincibility with timer

Comments in 'Plugin Development' started by Skullex, Dec 14, 2015.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Help me plz ;-; what's the code??
    Also with a message, tip..notifying you
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Look at plugins that utilize a Task instead of making threads asking.
  3. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I don't know what the code looks like so how am I supposed to identify it...like in github. I'm new to this so what would the code be exactly? I can understand a timer but invincibility???
  4. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Like, give me an example...anyone give me an example
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Skullex likes this.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Player::hidePlayer(Player $player)
    If you're new to this, don't start with a plugin like this
    Skullex and Vaivez66 like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is invincibility, not invisibility...
    @Gamecrafter meant to think about one plugin that does that, not to search for the code directly.

    The LegionPE Classic plugin does this: http://lgpe.co/csrc
    However, it depends on the LegionPE Theta framework, which you are not going to use. But basically, the concept is:

    • Make an array to store data
    • When player gets invincible for $x seconds, set the value in the array for that player to be microtime() + $x
    • When player gets hurt, if the value in the array for that player is greater than microtime(), cancel the hurt event.
    This method does not involve using a timer at all. And I cannot provide you with code, because how you implement it heavily depends on the structure of your plugin (unless you don't have a structure at all, which is likely when you don't even understand the code you are writing).
    Skullex likes this.
  8. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    TY anyways
    Last edited: Dec 15, 2015
  9. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    TY
  10. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Oops, misread it.
  12. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex

    How would I add
    PHP:
    Player::hidePlayer(Player $player)

    to

    <?php

    namespace ColorMatch\Arena;

    use 
    pocketmine\scheduler\PluginTask;

    use 
    ColorMatch\ColorMatch;
    use 
    ColorMatch\Arena\Arena;
    use 
    ColorMatch\Events\PlayerJoinArenaEvent;

    class 
    Task extends PluginTask {

        public 
    $plugin;
        public 
    $seconds;

          public function 
    __construct(Main $pluginPlayer $player$time) {
              
    parent::__construct($plugin);
              
    $this->plugin $plugin;
              
    $this->seconds 0;
          }

          public function 
    getPlugin() {
              return 
    $this->plugin;
          }

          public function 
    onRun($tick) {
              
    //Sends a message to the console with how many seconds the task has been running for
              
    $this->getPlugin()->getLogger()->info("Task has run for " $this->seconds "!");
                 
    Player::hidePlayer(Player $player);
              
    //Checks if $this->seconds has the same value of 10
              
    if($this->seconds === 10) {
                  
    //Tells the console that the task is being stopped and at how many seconds
                  
    $this->getPlugin()->getLogger()->info("A Task has run for " $this->seconds " and is now stopping...");
                  
    //Calls a function from your Main that removes the task and stops it from running
                  
    $this->getPlugin()->removeTask($this->getTaskId());
              }
              
    //Adds 1 to $this->seconds
              
    $this->seconds++;
          }
    }
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    If this isn't a joke, go learn PHP and thr Pocketmine-API again.
  14. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Well it was your code, I don't know how to add that code to an already made php that I never made. And Im not done learning php so this thread exists for one purpose...to help me with certain things like this what would I have to add to squeeze that into the php????
    iDirtPlayzMC likes this.
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Then do it with another code. It's the same. You have to understand things to use them.
  16. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I know, I know, I do understand! It basically says it :/ but I'll just read @PEMapModder 's github php learning guide now
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It was not code. It was a reference to a function. It basically means that you have a Player object and you have to pass a parameter Player $player to the hidePlayer function. How you got either object is dependent on your own code.
    This forum is for plugin development, not for learning basics of PHP. If you can't even understand what a class method is, please learn PHP.

    Also, his code is for invisibility, not invincibility.
  18. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I know it's for invisibility xD it says hide player and I am learning php, that's the thing

Share This Page

Advertisement