Tryed to make AI and it worked, but only one thing that movements are 'jerky' First tried update movement with packets PHP: $this->lastX = $this->x;$this->lastY = $this->y;$this->lastZ = $this->z;$this->lastYaw = $this->yaw;$this->lastPitch = $this->pitch;$pk = new MovePlayerPacket();$pk->eid = $this->id;$pk->x = $this->x;$pk->y = $this->y - $this->height / 2; // Else it jumps (teleports) up and falls down looks really ugly$pk->z = $this->z;$pk->yaw = $this->yaw;$pk->pitch = $this->pitch;$pk->bodyYaw = $this->yaw; Then setMotion() PHP: $this->setMotion($this->x, $this->y, $this->z); And this bad BAD BAD (testing) code PHP: if(mt_rand(0, 10) === mt_rand(0, 10)){$this->setMotion($this->x += rand(-1, 1) * self::$speed,$this->z += rand(-1, 1) * self::$speed,$this->y);} Should I give up the idea of a smooth AI?
ifteam makes a.i system (。+・`ω・´)b, entitymanager is very smooth, and entitymanager is support api 1.13.0 + api 2.0.0
PHP: Skip to contentThis repository SearchPull requestsIssuesGist@iDirtniverseYou don’t have any verified emails. We recommend verifying at least one email.Email verification helps our support team verify ownership if you lose account access and allows you to receive all the notifications you ask for.Watch 5 Star 20 Fork 14 alejandroliu/bad-pluginsBranch: master bad-plugins/Mobsters/src/aliuly/mobsters/idiots/Zombie.php3bba524 on Jul 17@alejandroliu alejandroliu Mobsters-0.5.01 contributorRawBlameHistory 273 lines (241 sloc) 7.48 KB<?php/*** ____ _ _ __ __ _ __ __ ____* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|** This program is free software: you can redistribute it and/or modify* it under the terms of the GNU Lesser General Public License as published by* the Free Software Foundation, either version 3 of the License, or* (at your option) any later version.** @author PocketMine Team* @link http://www.pocketmine.net/***/namespace aliuly\mobsters\idiots;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\item\Item as Item;use pocketmine\network\protocol\AddEntityPacket;use pocketmine\network\Network;use pocketmine\network\protocol\MovePlayerPacket;use pocketmine\network\protocol\MoveEntityPacket;use pocketmine\math\AxisAlignedBB;use pocketmine\Player;use pocketmine\entity\Monster;use pocketmine\entity\Entity;use pocketmine\math\Vector3;class Zombie extends Monster{ const NETWORK_ID = 32; public static $range = 32; public static $speed = 0.2; public static $jump = 2.5; public static $attack = 1.5; public $width = 0.6; public $length = 0.6; public $height = 1.8; public $stepHeight = 0.5; public $knockback = 0; public function getName(){ return "ZombieIdiot"; } public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->eid = $this->getId(); $pk->type = self::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->speedX = $this->motionX; $pk->speedY = $this->motionY; $pk->speedZ = $this->motionZ; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); parent::spawnTo($player); } /* public function getData(){ //TODO $flags = 0; $flags |= $this->fireTicks > 0 ? 1 : 0; //$flags |= ($this->crouched === true ? 0b10:0) << 1; //$flags |= ($this->inAction === true ? 0b10000:0); $d = [ 0 => ["type" => 0, "value" => $flags], 1 => ["type" => 1, "value" => $this->airTicks], 16 => ["type" => 0, "value" => 0], 17 => ["type" => 6, "value" => [0, 0, 0]], ]; return $d; }*/ public function getDrops(){ $drops = []; $rnd = mt_rand(0,1); if ($rnd) { $drops[] = Item::get(Item::FEATHER, 0, $rnd); } if($this->lastDamageCause instanceof EntityDamageByEntityEvent and $this->lastDamageCause->getEntity() instanceof Player){ if(mt_rand(0, 199) < 5){ switch(mt_rand(0, 2)){ case 0: $drops[] = Item::get(Item::IRON_INGOT, 0, 1); break; case 1: $drops[] = Item::get(Item::CARROT, 0, 1); break; case 2: $drops[] = Item::get(Item::POTATO, 0, 1); break; } } } return $drops; } public function zupdateMovement(){ if($this->x !== $this->lastX or $this->y !== $this->lastY or $this->z !== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch){ $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; $pk = new MovePlayerPacket(); $pk->eid = $this->id; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->bodyYaw = $this->yaw; foreach($this->hasSpawned as $player){ $player->dataPacket($pk); } } if(($this->lastMotionX != $this->motionX or $this->lastMotionY != $this->motionY or $this->lastMotionZ != $this->motionZ)){ $this->lastMotionX = $this->motionX; $this->lastMotionY = $this->motionY; $this->lastMotionZ = $this->motionZ; foreach($this->hasSpawned as $player){ $player->addEntityMotion($this->id, $this->motionX, $this->motionY, $this->motionZ); } } } public function getBoundingBox(){ $this->boundingBox = new AxisAlignedBB( $x = $this->x - $this->width / 2, $y = $this->y - $this->height / 2 + $this->stepHeight, $z = $this->z - $this->length / 2, $x + $this->width, $y + $this->height - $this->stepHeight, $z + $this->length ); return $this->boundingBox; } private function findTarget(){ $lv = $this->getLevel(); $ps = $lv->getPlayers(); if(!count($ps)){ return [null,null]; } $target = null; $dist = null; foreach($ps as $pl){ if($pl->isCreative()){ continue; } $cd = $this->distance($pl); if(($cd > self::$range)||($dist && $cd > $dist)||$pl->getHealth()<1){ continue; } $dist = $cd; $target = $pl; } return [$target,$dist]; } public function onUpdate($currentTick){ if ($this->knockback) { if (time() < $this->knockback) { return parent::onUpdate($currentTick); } $this->knockback = 0; } $hasUpdate = false; $this->timings->startTiming(); // Handle flying objects... $tickDiff = max(1, $currentTick - $this->lastUpdate); $bb = clone $this->getBoundingBox(); $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0; if(!$onGround){ // falling or jumping... $this->motionY -= $this->gravity; $this->x += $this->motionX * $tickDiff; $this->y += $this->motionY * $tickDiff; $this->z += $this->motionZ * $tickDiff; //echo ("Falling...\n"); }else{ $this->motionX = 0; // No longer jumping/falling $this->motionY = 0; $this->motionZ = 0; if ($this->y != floor($this->y)) $this->y = floor($this->y); // Try to attack a player list($target,$dist) = $this->findTarget(); if($target !== null && $dist > 0){ $dir = $target->subtract($this); $dir = $dir->divide($dist); $this->yaw = rad2deg(atan2(-$dir->getX(),$dir->getZ())); $this->pitch = rad2deg(atan(-$dir->getY())); if ($dist > self::$attack) { // $x = $dir->getX() * self::$speed; $y = 0; $z = $dir->getZ() * self::$speed; $isJump = count($this->level->getCollisionBlocks($bb->offset($x, 1.2, $z))) <= 0; if(count($this->level->getCollisionBlocks($bb->offset(0, 0.1, $z))) > 0){ if ($isJump) { $y = self::$jump; $this->motionZ = $z; } $z = 0; } if(count($this->level->getCollisionBlocks($bb->offset($x, 0.1, 0))) > 0){ if ($isJump) { $y = self::$jump; $this->motionX = $x; } $x = 0; } //if ($y) echo "Jumping\n"; $ev = new \pocketmine\event\entity\EntityMotionEvent($this,new \pocketmine\math\Vector3($x,$y,$z)); $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) return false; $this->x += $x; $this->y += $y; $this->z += $z; }else { $attack = mt_rand(0,4); if ($attack < 2 && $attack > 0) { $source = new EntityDamageByEntityEvent($this,$target,EntityDamageEvent::CAUSE_ENTITY_ATTACK,$attack); $target->attack($attack,$source); } } } } $bb = clone $this->getBoundingBox(); $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0; $this->onGround = $onGround; $this->timings->stopTiming(); $hasUpdate = parent::onUpdate($currentTick) || $hasUpdate; return $hasUpdate; } public function knockBack(Entity $attacker, $damage, $x, $z, $base = 2){ echo __METHOD__.",".__LINE__."\n"; //##DEBUG parent::knockBack($attacker,$damage,$x,$z,$base); $this->knockback = time() + 1;// Stunned for 1 second... }}Status API Training Shop Blog About Pricing© 2015 GitHub, Inc. Terms Privacy Security Contact Help credit : ALIULY https://github.com/alejandroliu/bad...obsters/src/aliuly/mobsters/idiots/Zombie.php
Once You download it... Do you put the phps in the plugin folder?!? Or somewhere else?like the mobs and such....
download the zip folder... add it to pmt.mcpe.me . receive your .phar file and add it to your plugins folder
Next time find a person to ask on PM (Personal Message), so you wont go off-topic, just like i did now.