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

i want player first time break oak = Send Massage

Discussion in 'Development' started by GamingMan, Oct 31, 2021.

  1. GamingMan

    GamingMan Creeper

    Messages:
    5
    GitHub:
    DaGamingGuy
    i want player first time pickup (PickUpevent) oak = Send Massage (use config)
    How Can i Make It Any Developer Can Help Me?
     
  2. BloodyJohnRus

    BloodyJohnRus Silverfish

    Messages:
    19
    GitHub:
    GDSHNIK
    PHP:
    use pocketmine\event\inventory\InventoryPickupItemEvent;

    public function 
    onPickup(InventoryPickupItemEvent $e)
    {
    $item=$e->getItem();
    $id=$item->getId();
    if (
    $id===$oakid)
    {
    //yc
    }
    }
     
  3. Axon

    Axon Zombie

    Messages:
    276
    Make sure to define the $oakid lol
     
  4. BloodyJohnRus

    BloodyJohnRus Silverfish

    Messages:
    19
    GitHub:
    GDSHNIK
    Oh, if it is first time then:
    PHP:
    use pocketmine\event\inventory\InventoryPickupItemEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    public 
    $config;
    public function 
    onLogin(PlayerLoginEvent $e)
    {
    $n=$e->getPlayer()->getName();
    if(!
    $this->config->exists("oak$n"))
    {
    $this->config->set("oak$n","false");
    $this->config->save();
    }
    }
    public function 
    onPickup(InventoryPickupItemEvent $e)
    {
    $p=$e->getPlayer();
    $n=$e->getName();
    $item=$e->getItem();
    $id=$item->getId();
    if (
    $id===17 && $this->config->get("oak$n")=="false")
    {
    $this->config->set("oak$n","true");
    $this->getServer()->broadcastMessage("Player $n achieved 'First steps!' ");
    $this->config->save();
    }
    }
    public function 
    onEnable()
    {
    if(!
    is_dir($this->getDataFolder())
    {
    mkdir($this->getDataFolder());
    }
        
    $this->saveResource("config.yml");
        
    $this->config = new Config($this->getDataFolder() ."config.yml",Config::YAML);
    }
     
  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.