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

When it comes to NPC

Discussion in 'Development' started by Fermix, May 12, 2017.

  1. Fermix

    Fermix Creeper

    Messages:
    3
    GitHub:
    fermixdev
    How to do when you approach the NPC, the action takes place?
    Sorry my bad English D:
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Are you looking for a way to trigger an action by proximity?
     
  3. Fermix

    Fermix Creeper

    Messages:
    3
    GitHub:
    fermixdev
    In the plugin GoldSTD, when you go to the dealer, he's texting. Climbed the entire code, can't find
     
  4. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    I think I understand what you're wanting, here is a snippet of code :).
    PHP:
    //$npc MUST be an entity.
    //$p MUST be an player
    //the code here would be used on PlayerMoveEvent

    if($p->getLevel() !== $npc->getLevel())
    {
        return; 
    //we dont want to execute useless code that would slow the server down even more
    }

    $minDistance 2//distance a player must be before "entity" starts talking to them

    $distance round($p->distance($npc)); //we are rounding the number because the distance could be a decimal and a player would be spammed
    if($distance $minDistance)
    {
        return; 
    //the player is too far away
    }

    //your code here
     
  5. Fermix

    Fermix Creeper

    Messages:
    3
    GitHub:
    fermixdev
    Yes, thank You very much :)
     
    0x15f likes this.
  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.