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

When i use entity->getId() it returns entity count in the server

Discussion in 'Development' started by OguzhanUmutlu, Jan 5, 2021.

  1. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    When i use entity->getId() it returns entity count in the server
    My anti-lag:
    PHP:
    public function onspawnentity(EntitySpawnEvent $e) {
            
    $entity $e->getEntity();
            if(!
    in_array($entity->getId(), [63,64,-1,1])) {
                
    $entity->kill();
                
    $this->getLogger()->info($entity->getId());
            }
        }
     
  2. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    Am i supposed to use this? Is there any short way? (Because i don't want this code to kill my slappers and i know i can use Slapper's entity type but is there any other short way?)
    PHP:
    $entity instanceof Player
     
  3. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    $entity->getId() doesn't return entity count on the server. It returns unique id for the entity in int. That id is got by increasing one int (Entity::$entityCount) so it may be similar to entity count, however, if you despawn some entity, it's irrelevant to call it entity count. Btw, what this code is supposed to do and where is the problem with it?
     
    Last edited: Jan 5, 2021
    Primus likes this.
  4. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    I want to kill every mob without Players, Items and other plugin's custom entities.
    Problem is entity->getId not returns the id of the entity
    (thanks for replying)
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    For network id you can use $entity::NETWORK_ID, but using check $entity instanceof ... is better as network ids are kinda deprecated
     
    Last edited: Jan 5, 2021
  6. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    PHP:
    if(!($entity instanceof Player) && !($entity instanceof pocketmine\entity\ItemEntity) && !($entity instanceof jojoe77777\slapper\entities\SlapperEntity)) {
                
    $entity->kill();
                
    $this->getLogger()->info($entity->getId());
            }
    I used that but it didnt work. It still kills items and slappers. But not kills me.
    (I am gonna try network id)
     
    Last edited: Jan 5, 2021
  7. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    NETWORK_ID doesnt work. I tried on armor stand and in armor stand's code there is not property named NETWORK_ID.
     
  8. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Armor stands are not implemented yet. You can find it's network id here. If there is no property named NETWORK_ID then you have implemented armor stand entity wrong.
     
  9. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    I am using Altay can it make problem?
     
  10. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    :facepalm: use altay's forums then ...if they even have any
     
    Last edited: Jan 5, 2021
  11. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    I
    tried on pocketmine. It doesnt work. I cannot be the first developer that used entity getId
     
  12. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    use

    if($entity instanceof ItemEntity || $entity instanceof ....)
     
  13. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    i used but it doesnt work.
     
  14. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    This code works for me

    PHP:
    foreach ($this->level->getEntities() as $entity)
            {
                if (
    $entity instanceof ItemEntity)
                {
                    
    $entity->flagForDespawn();
                }
            }
     
    GamakCZ likes this.
  15. OguzhanUmutlu

    OguzhanUmutlu Witch

    Messages:
    63
    GitHub:
    OguzhanUmutlu
    thx i am gonna try
     
  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.