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

Problem with setting more NETWORK ids

Discussion in 'Development' started by Poustmal12, Dec 17, 2018.

  1. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    Hello,I have made a working collision plugin and I want to make player collide with Zombie,etc. how will I add all that types of entities in my plugin?
    I have already that code:
    public const NETWORK_ID = self::ZOMBIE;

    but I can't add the other types of entities
    When I tried to add a comma( ,)or =, I had errors.
    Also when I tried to add and second line
    public const NETWORK_ID = self::HUSK;
    It says cannot redefine etc.
     
  2. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    You should make it an array
    Code:
    const NETWORK_ID = [52, **]
    
    Then, you can use ```in_array()``` to validate.

    PS: I don't really know how this works, I lost all my PMMP Knowledge.
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    https://php.net/constants
    Learn PHP before trying to add more classes. You are totally misunderstanding the point of the line "public const NETWORK_ID = self::ZOMBIE".
     
  4. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    Im beginner at coding on PHP, but I have plans for now to learn more things at coding when I have time.
     
  5. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    And I think I know some basic things for now.
     
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    The name 'NETWORK_ID' indicates that it's an ID. Why don't you take a look at other PMMP Member' Source Code on this?
    It might help you have a basic idea on how stuffs work instead of you getting obliterated here in the Forums xD
     
  7. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    I thought forums was the best and fastest solution for taking help and answers.Anyway thanks for your help.
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It isn't possible to help you without writing an extremely long (which is not fast) post, which basically repeats on the PHP language basics. Please, try to learn the language first.
    Meanwhile your own post didn't make much sense either...
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I knew it earlier :D
     
  10. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    Yes,I should learn the PHP basics first to prevent having any problem like this,but I made an almost finished plugin with some working codes and I want the full correct code to make the plugin work.And also, from codes, I'll try to understand or maybe I'll understand soon the meaning of the code and I'll know maybe how to use it correctly.I just need the code,I don't ask something so big.
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And how can we help you if you don't show your current code? Programming isn't some drag and drop magic that would work as long as you copy something into your program. We need to see your whole picture to solve your problem.
    What's happening right now is that you already have a solution, but you are having trouble to add two entities, and we totally don't understand what's so hard about it unless you show what you have already got.
     
    EdwardHamHam likes this.
  12. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    I have that file:

    Code:
    PHP:
    <?php
    namespace Saxavlax001\PECollide;
    use 
    pocketmine\entity\Living;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
    use 
    pocketmine\Player;
    class 
    PECollide extends Living{

            
    in_array(self$name);

            public const 
    NETWORK_ID = [self::ZOMBIEself::HUSKself::CREEPERself::SKELETONself::SPIDER];

      

            public 
    $scale 1;
            public 
    $baseSize 0.51;
            public 
    $height 0;
            public 
    $width 0;

            public 
    $speed 0;
            
    /** @var Vector3 */
            
    public $hitMotion null;

            public function 
    __construct(Level $levelCompoundTag $nbt){
                    
    $this->height = ($this->baseSize $this->scale) * $this->baseSize;
                    
    $this->width = ($this->baseSize $this->scale) * $this->baseSize;
                    
    $this->motion $this->hitMotion = new Vector3();
                    
    parent::__construct($level$nbt);
            }

            public function 
    getName(): string{
                    return 
    "PECollide";
            }

            public function 
    entityBaseTick(int $tickDiff 1): bool{
                    if(
    $this->hasMovementUpdate()){
                            
    $forceX 0.1// motion force for x
                            
    $forceZ 0.1// motion force for z
                            
    $forceY 0// motion force for y
                            
    $velDS 0.08//how fast the velocity decreases
                            
    $stopSpeed 0.01//speed where the entity or player stops

                            
    $vel $this->getMotion();

                            if(
    $this->onGround){
                                    if(
    $this->speed <= $stopSpeed){
                                            return 
    parent::entityBaseTick($tickDiff);
                                    }

                                    
    $bounceX abs($this->hitMotion->$vel->x);
                                    
    $bounceZ abs($this->hitMotion->$vel->z);

                                    if(
    $vel->=== 0){
                                            
    $vel->$vel->+ ((-$this->hitMotion->x) * $forceX);
                                    }elseif(
    $bounceX 0.15){
                                            
    $vel->$vel->+ (($this->hitMotion->$forceX) + 0.075);
                                    }

                                    if((
    $vel->=== 0) && ($this->hitMotion->< -0.1)){
                                            
    $vel->= -$this->hitMotion->$forceY;
                                    }

                                    if(
    $vel->=== 0.0){
                                            
    $vel->$vel->+ ((-$this->hitMotion->z) * $forceZ);
                                    }elseif(
    $bounceZ 0.15){
                                            
    $vel->$vel->+ (($this->hitMotion->$forceZ) + 0.075);
                                    }

                                    
    $this->speed -= $velDS;

                                    
    $this->setMotion($vel);
                                    
    $this->hitMotion $vel;
                            }
                    }
                    return 
    parent::entityBaseTick($tickDiff);
            }

            public function 
    onCollideWithPlayer(Player $player): void{
                    
    $direc $player->getDirectionVector();
                    if(!
    $player->onGround){
                            
    $direc->0.6;
                    }
                    if(!
    $player->isSprinting()){
                            
    $direc->divide(2);
                    }
                    
    $this->speed 1;
                    
    $this->setMotion($direc);
            }
    }
     
    Last edited: Dec 18, 2018
  13. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    Forget the whole code,I have problem only with the array code.
     
  14. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    I looked the php site,I searched on github about that in_array() code and I didn't take help.
     
  15. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi, please use Code Block to avoid seizure (For the people who are viewing).
     
    OnTheVerge likes this.
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    As I have said, programming isn't some drag and drop magic that would work as long as you copy it somewhere into your program. You are getting the whole thing wrong.

    "class PECollide extends Living" creates exactly one new entity type called PECollide. The "public const NETWORK_ID = self::ZOMBIE;" inside means that the entity will be rendered as a zombie.

    And don't look at @InspectorGadget's first post above. He is just posting random code; I already told you.

    But first of all... What do you mean by "make player collide with zombie"? From your code above, registering a new entity type is totally not something you should be doing.
     
    EdwardHamHam likes this.
  17. Poustmal12

    Poustmal12 Silverfish

    Messages:
    23
    GitHub:
    poustmal12
    PHP:
        public function canCollideWith(Entity $entity) : bool{
            return !
    $this->justCreated and $entity !== $this;
        }

        public function 
    canBeCollidedWith() : bool{
            return 
    $this->isAlive();
        }
    Ok I understood that,I want to make a player collide with entities,I have already a working onCollide code but the two codes above it seems they don't do nothing when I'm using them.I need to add something on one of two functions?
     
    Last edited: Dec 18, 2018
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Just handle the player movement event.
     
  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.