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

How to make players slowly heal in a certain area.

Discussion in 'Facepalm' started by xXSirButterXx, May 31, 2017.

  1. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    I was wondering how to slowly heal people in a certain box. I want to create a certain area on my server that slowly adds hearts and hunger points to people every second they are in that area, but stop when they hit full points. Thanks
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You could start a repeating task whenever a player moves into a certain area. When the task runs, you could heal and restore food at whatever rate you want. You could cancel the task for that player when they leave the area or get full health. I suppose you could perform a simple check every time the task runs to see if the player needs health, or you could check their health after the task is run, and cancel the task if needed.
     
    Sandertv likes this.
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Alternatively you could schedule a repeating task at the enabling of the plugin and foreach the online players, then check if the player is within a box of two Vector3s.
     
    corytortoise likes this.
  4. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    Could I get a snippet of code on how to do this. I'm still a little bit newer to php.
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    persudo code
    PHP:
    private $spot,$distance
    function task_construct(Location$point,numeric$distance 3){
    setToSelf($point,$distance);
    }
    function 
    task _onRun(){
    $lvPlayers $spot->getLevel->getPlayers;
    foreach (
    $lvPlayers){
    if (
    $pos->dist($lvPlayer) <= $dist AND ($player->isNotFull OR $player->isFullyHeale)) $lvPlayer->healHp(0.1)->feedFood(0.1);
    }
    }
    some things are the things i wish i know are in PHP, some just wont work if you copy and paste it, some are just abstractions too simple and pointless to be pointed out
    either ways like i said again this is persudo code DO NOT TRY TO COPY IT INTO PMMP plugin
    warning aside that SHOULD work just register a repeating task for each points with a distance, the rate of task is the rate of healing

    IMO there's no reason to deregister it just to have a task to check and re register it or even worse register it onMove
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    that's another way of doing an area check, but i prefer passing on constructor as it feels more flexible and not just a hardcoded magicvalue
     
  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.