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

Stop if already clicked item

Discussion in 'Development' started by Enrico Angelon, Feb 14, 2018.

  1. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Hi, i'm new on pmmp, i learned apis and now i started developing, but i'm noob at the moment.
    that's a piece of my code:

    public function onTouch(PlayerInteractEvent $event){

    $player = $event->getPlayer();
    $item = $event->getItem();

    if($item->getId() == 345){

    $player->getInventory()->clearAll();
    $player->getInventory()->addItem(Item::get(267,0,1));
    $player->sendMessage(TextFormat::GRAY . ">-------------------------------------------<");
    $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non usare hacks" . TextFormat::GRAY . "!");
    $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non spammare" . TextFormat::GRAY . "!");
    $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non chiedere OP" . TextFormat::GRAY . "!");
    $player->sendMessage(TextFormat::GRAY . ">-------------------------------------------<");

    }elseif($item->getId() == 267) {

    $event->getPlayer()->sendMessage(TextFormat::RED . "- " . TextFormat::GRAY . "PvP Mode Correctly " . TextFormat::WHITE . "Activated!");

    $player->getInventory()->clearAll();
    $player->getInventory()->addItem(Item::get(267,0,1));
    $player->getInventory()->addItem(Item::get(306,0,1));
    $player->getInventory()->addItem(Item::get(307,0,1));
    $player->getInventory()->addItem(Item::get(308,0,1));
    $player->getInventory()->addItem(Item::get(309,0,1));
    $player->getInventory()->addItem(Item::get(261,0,1));
    $player->getInventory()->addItem(Item::get(262,0,64));
    $player->getInventory()->addItem(Item::get(331,0,1));

    $this->hubpvp = true;

    }elseif ($this->hubpvp == true) {

    $e->setCancelled();
    }


    but when i get the sword and click one time, it giev me right itemes but i can reclick the sword and it will reset inventory and guve new sword, new and also i don't know why i cant wear armor directly clicking, its blocked but i can only whith inventory opened. Thanks
     
  2. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Sorry i want to help you but i dont really understand wath do you want to do?

    PHP:
    $e->setCancelled();
    the variable $e is undefined
    PHP:
    $event->getPlayer()->sendMessage(TextFormat::RED "- " TextFormat::GRAY "PvP Mode Correctly " TextFormat::WHITE "Activated!");
    you have already defined $player then you can replace $event->getPlayer(); by $player
     
    xXNiceAssassinlo YT likes this.
  3. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Thanks for the correction, I had not noticed. Basically I want that when I click the sword, the command that runs rejoices to make clear inventory and put another sword etc, functions only once is already active does not go. Because now the players are repeating the sword many times, the function starts all over again.
     
  4. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    Just rename the sword everytime and check for the names for your code to run
     
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    public $click = array();

    PHP:
    public function onTouch(PlayerInteractEvent $event){
    $player $event->getPlayer();
    $item $event->getItem();

    if(
    $item->getId() == 345){
    // do things
    $this->click[strtolower($p->getName())] = $p->getName();
     }
    if(
    in_array(strtolower($p->getName()), $this->click)){
    $event->setCancelled(true);
    }else{
    $event->setCancelled(false);
    }
    }
     
  6. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    i tryed this method but actually is not working for me :L no errors, but not workin
     
  7. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    PHP:
    /** @var int[] $touched */
    protected $touched = [];

    public function 
    onTouch(PlayerInteractEvent $event){

            
    $player $event->getPlayer();
            
    $item $event->getItem();

            if(isset(
    $this->touched[$player->getXuid()])){
                    
    $event->setCancelled();
                    return;
            }
    //things to do...
    $this->touched[$player->getXuid()] = 1;
    }
     
    kazuya 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.