Despawn command into core

This commit is contained in:
ArkQuark 2022-06-05 01:53:41 +03:00
parent f484c90f7b
commit 133f398a42

View file

@ -82,6 +82,7 @@ class EntityAPI{
$this->server->schedule(25, array($this, "updateEntities"), array(), true); $this->server->schedule(25, array($this, "updateEntities"), array(), true);
$this->server->api->console->register("summon", "<mob>", array($this, "commandHandler")); $this->server->api->console->register("summon", "<mob>", array($this, "commandHandler"));
$this->server->api->console->register("spawnmob", "<mob>", array($this, "commandHandler")); $this->server->api->console->register("spawnmob", "<mob>", array($this, "commandHandler"));
$this->server->api->console->register("despawn", "", array($this, "CommandHandler"));
} }
public function commandHandler($cmd, $args, $issuer, $alias){ public function commandHandler($cmd, $args, $issuer, $alias){
@ -163,30 +164,45 @@ class EntityAPI{
$output .= $amount." ".$baby.$this->mobName[$type].$plural." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; $output .= $amount." ".$baby.$this->mobName[$type].$plural." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ.".";
break; break;
} }
elseif(strtolower($args[1]) == 'baby'){//summon <mob> [baby] elseif(strtolower($args[1]) == 'baby'){//summon <mob> [baby]
if($type > 13){ if($type > 13){
$output .= "Baby can be only animals!"; $output .= "Baby can be only animals!";
break;
}
else{
$spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP);
$spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP);
$spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP);
$spawnLevel = $issuer->entity->level;
$entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array(
"x" => $spawnX,
"y" => $spawnY,
"z" => $spawnZ,
"Health" => $this->hp[$type],
"isBaby" => 1,
));
$this->spawnToAll($entityit, $level);
$output .= "Baby ".$this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ.".";
break;
}
break; break;
} }
else{ case 'despawn':
$spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP); $cnt = 0;
$spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP); $l = $this->server->query("SELECT EID FROM entities WHERE class = ".ENTITY_MOB.";");
$spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP); if ($l !== false and $l !== true){
$spawnLevel = $issuer->entity->level; while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
$entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( if ($e instanceof Entity){
"x" => $spawnX, $this->remove($e->eid);
"y" => $spawnY, $cnt++;
"z" => $spawnZ, }
"Health" => $this->hp[$type], }
"isBaby" => 1,
));
$this->spawnToAll($entityit, $level);
$output .= "Baby ".$this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ.".";
break;
} }
} $output .= $cnt." mobs has been despawned!";
break;
} }
return $output; return $output;
} }