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.
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.
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".
Im beginner at coding on PHP, but I have plans for now to learn more things at coding when I have time.
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
I thought forums was the best and fastest solution for taking help and answers.Anyway thanks for your help.
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...
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.
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.
I have that file: Code: PHP: <?phpnamespace 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::ZOMBIE, self::HUSK, self::CREEPER, self::SKELETON, self::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 $level, CompoundTag $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->x - $vel->x); $bounceZ = abs($this->hitMotion->z - $vel->z); if($vel->x === 0){ $vel->x = $vel->x + ((-$this->hitMotion->x) * $forceX); }elseif($bounceX < 0.15){ $vel->x = $vel->x + (($this->hitMotion->x * $forceX) + 0.075); } if(($vel->y === 0) && ($this->hitMotion->y < -0.1)){ $vel->y = -$this->hitMotion->y * $forceY; } if($vel->z === 0.0){ $vel->z = $vel->z + ((-$this->hitMotion->z) * $forceZ); }elseif($bounceZ < 0.15){ $vel->z = $vel->z + (($this->hitMotion->z * $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->y = 0.6; } if(!$player->isSprinting()){ $direc->divide(2); } $this->speed = 1; $this->setMotion($direc); }}
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.
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?