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

How to do PlayerInteractEvent to an Spectator?

Discussion in 'Help' started by LewBr, Apr 16, 2018 at 2:01 AM.

  1. LewBr

    LewBr Zombie

    Messages:
    295
    GitHub:
    lewbr
    Hello, it is possible to register a InteractEvent with an item to an Spectator player? when i try to do that whit an player with gamemode 3 it doesn't works..

    If not, how can i detect when a player change the selected number of slot? like index and then make some things when select that?
     
  2. CortexPE

    CortexPE Witch

    Messages:
    53
    GitHub:
    cortexpe
    you can detect item interaction on spectator mode with a separate packet handler... (re-inventing how pocketmine handles item interaction)

    and for the second question, listen for PlayerItemHeldEvent.
     
  3. LewBr

    LewBr Zombie

    Messages:
    295
    GitHub:
    lewbr
    PlayerItemHeldEvent works for players with gamemode 3? and how can i do exactly this separate packet handler?
     
  4. CortexPE

    CortexPE Witch

    Messages:
    53
    GitHub:
    cortexpe
    Yep.

    Register an EventListener that listens for DataPacketReceiveEvent, Check if the packet is an instance of InventoryTransactionPacket, Check if the transaction type is `InventoryTransactionPacket::TYPE_USE_ITEM`, Check if the action type is `InventoryTransactionPacket::USE_ITEM_ACTION_CLICK_BLOCK` and you can finally do stuff from there...
     
    LewBr likes this.
  5. LewBr

    LewBr Zombie

    Messages:
    295
    GitHub:
    lewbr
    Thank you, it helps me a lot!
     
    CortexPE likes this.
  6. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    485
    GitHub:
    dktapps
    I broke spectator-mode interaction events some time ago with a fix-all fix... I've been meaning to fix it properly for a while.
     
    LewBr likes this.

Share This Page