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

help adding multiple returns on itemID

Comments in 'Plugin Development' started by mariusbjornor, Aug 6, 2015.

  1. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    Anyone wanna help adding so that itemID gets returned every time you tap item in hotbar?

    This is the code so far:

    PHP:
    public function onItemHeld(PlayerItemHeldEvent $event){
    $item $event->getItem();
    $player $event->getPlayer();
    if(
    $player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." §eI:eek: ".$item->getId(), 2); // More info about item that is held
    return true;
    }
    }
    it works perfect.. i just want it to return ID every time i tap it..
    Last edited by a moderator: Aug 6, 2015
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    try EntityBlockChangeEvent;
    and use [php ][/php ]
    mariusbjornor likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    But i dont know will it work if you tap same item :(
  4. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    PHP:

    namespace MariusB\ItemID;

    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\event\entity\EntityBlockChangeEvent;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener{

    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getLogger()->info("ItemID is enabled");
    }

    public function 
    onDisable(){
    $this->getLogger()->info("ItemID is Disabled");
    }

    public function 
    onItemHeld(PlayerItemHeldEvent $event){
    $item $event->getItem();
    $player $event->getPlayer();
    if(
    $player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." §eI:eek: ".$item->getId(), 2); // More info about item that is held
    return true;
    }
    }

    public function 
    onSlotChange(EntityBlockChangeEvent $event){
    $player->getEntity();
    if(
    $player instanceof Player){
    $item $event->getNewItem();
    $player->sendPopup($item->getName()." ".$item->getId().":".$item->getDamage()." x".$item->getCount(), 2);
    }
    }
    }
    Last edited by a moderator: Aug 6, 2015
  5. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    i added onSlotChange and [php ] [/php ]

    now nothing works... maybe i could find a code from LBSG's clock.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Dude remove space in [] then you will see php code box!
    LSBG clock?
  7. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    Yeah they have multiple tap action on item...
  8. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    Are you serious? Please make sure you know what you're saying before you say something. EntityBlockChange has nothing to do with inventory slots. :p The correct event to handle items held by a player is PlayerItemHeldEvent.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Well sorry Mr. Obvious for trying to help someone instead of judging! You could only said that i'm wrong not beeing so Ruude!
  10. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    I know you are trying to help(obviously), but if you give wrong solutions, you do more harm than help.
    Legoboy0215 and PEMapModder like this.
  11. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    This is what i use now.. it works fine but i want it to show ID every time i tap it..

    Code:
    <?php

    namespace MariusB\ItemID;

    use pocketmine\item\Item;
    use pocketmine\event\Listener;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\player\PlayerItemHeldEvent;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\Player;

    class Main extends PluginBase implements Listener{

    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("ItemID is enabled");
    }

    public function onDisable(){
    $this->getLogger()->info("ItemID is Disabled");
    }

    public function onItemHeld(PlayerItemHeldEvent $event){
    $item = $event->getItem();
    $player = $event->getPlayer();
    if($player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." §eI:eek: ".$item->getId(), 2); // More info about item that is held
    return true;
    }
    }

    public function onCommand(CommandSender $sender, Command $command, $label, array $args){
    if(strtolower($command->getName()) === "item"){
    if ($sender instanceof Player){
    if ($sender->hasPermission("item.command")){
    if (count($args) <1) {
    $inHandid = $sender->getInventory()->getItemInHand()->getId();
    $inHandname = $sender->getInventory()->getItemInHand()->getName();
    $sender->sendMessage("[ItemID]You are holding $inHandname ID $inHandid");
    return true;}
    else {$sender->sendMessage("[ItemID]what?what?");
    return true;}
    }else {$sender->sendMessage("[ItemID]You are not a Player");
    }
    return true;}
    }

    return true;}
    }
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please put your code inside [PHP][/PHP]
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    He is like that. It is not so rude :)
  14. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    like this??

    Code:
    PHP:

    namespace MariusB\ItemID;

    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener{

    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getLogger()->info("ItemID is enabled");
    }

    public function 
    onDisable(){
    $this->getLogger()->info("ItemID is Disabled");
    }

    public function 
    onItemHeld(PlayerItemHeldEvent $event){
    $item $event->getItem();
    $player $event->getPlayer();
    if(
    $player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." §eID: ".$item->getId(), 2); // More info about item that is held
    return true;
    }
    }

    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
      if(
    strtolower($command->getName()) === "item"){
      if (
    $sender instanceof Player){
      if (
    $sender->hasPermission("item.command")){   
      if (
    count($args) <1) {
      
    $inHandid $sender->getInventory()->getItemInHand()->getId();
      
    $inHandname $sender->getInventory()->getItemInHand()->getName();
      
    $sender->sendMessage("[ItemID]You are holding $inHandname ID $inHandid");
      return 
    true;}
      else {
    $sender->sendMessage("[ItemID]what?what?");
      return 
    true;}
      }else {
    $sender->sendMessage("[ItemID]You are not a Player");
      }
      return 
    true;}
      }

      return 
    true;}   
    }
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Does Pocketmine can handle same slot tap?
  16. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    112
    Minecraft User:
    MariusB
    I think so because LifeBoat SG has double that feature on clock..

    plugin works god now, i just need to tap another item before taping the same again to get ID..

Share This Page

Advertisement