Here is the code, now how would I make it live? @Glitchmaster_PE An do I have any errors? PHP: <?php/* __PocketMine Plugin__ name=SignProdescription= Live Signs at its best!version=1.0author=NIMclass=Signapiversion=11*/class Sign implements Plugin{ private $api, $server; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; $this->server = ServerAPI::request(); } public function init(){ $this->api->addHandler("tile.update", array($this, "eventHandler"), 10); } public function eventHandler($data, $event){ switch ($event) { case "tile.update": if ($data->class === TILE_SIGN) { if ($data->data['Text1'] != "[Server]") return; $data->setText(".count($this->api->player->getAll())."/".$this->server->maxClients)); } } } public function __destruct(){ } }
This only makes it, making it live is a whole new thing. If I do it for you, that takes the fun out of it
Get a Tile object by TileAPI, then call the Tile's non-static function $tile->setText($text1,$text2,$text3,$text4)
I have an idea. do you know how the autocommandbot plugin. maybe you can fit in the $this->api->schedule code in to the live sign plugin so it will check how much players are on every 5 seconds
I am up to signs too recently. Here is a pre-release version of my API: NOTE: DO NOT REDISTRIBUTE THIS PLUGIN OR ANY OF ITS MODIFICATIONS. PEMapModder UPHOLDS ALL RIGHTS TO USE IT. PHP: <?php/*__PocketMine Plugin__author=PEMapModdername=DST_APIdescription=DynamicSignTechnology APIapiversion=10,11version=0.0.0.0class=DSTLoadable*//*@Copyright 2014 PEMapModder@author PEMapModderDo not redistribute this plugin or any modifications of it.However, you can make plugins that call function in this plugin by: ServerAPI::request()->api->plugin->get("DST_API")->registerDS(...)*//*ChangeLogEdition | Version | Build | Testant | Description0(alpha)| 0 | 0 | 0 | Initial commit: only functions 1 | 0 | Changed to an API-like thing*/class DSTAPI implements Plugin{ ////API//// private $api,$b,$c,$p,$t,$pn,$s; ////DB//// private $cfg; private $db; ////RAM//// private $signsUpdate=array();/* public $dummyDsFullChange=array( "pos"=>new Position(0,0,0,LevelAPI::get("world")), "status"=>0, "partialLines"=>false, "texts"=>array( array( "line0", "line1", "line2", "line3" ), array( "line0", "line1", "line2", "line3" ) ) ); public $dummyDsPartialChange=array( "pos"=>new Position(1,1,1,LevelAPI::get("world")), "status"=>0, "partialLines"=>true, "texts"=>array( array( "line0", "line1", "line2", "line3" ), array("newLine0","newLine1") ) );*/ public function __construct(ServerAPI $a,$s=0){//**PMStuff $this->api=$a; $this->b=$a->block; $this->c=$a->console; $this->p=$a->player; $this->t=$a->tile; $this->pn=$a->plugin; } public function init(){//**PMStuff $this->s=ServerAPI::request(); $this->initCmds(); $this->initEvts(); $this->s->schedule(20,array($this,"secondTick")); $this->cfg=new Config($this->pn->configPath($this)."config.yml",CONFIG_YAML,array( )); $this->db=new Config($this->pn->configPath($this)."database.yml",CONFIG_YAML,array( "DSs"=>array() )); $dss=$this->db->get("DSs"); if($dss!==array())$this->importDSs($dss); $this->s->dhandle("dst.inited",array()); } public function __destruct(){//**PMStuff $this->save(); } public function initCmds(){//**PMStuff } public function initEvts(){//**PMStuff $this->s->addHandler("player.block.touch",array($this,"evH")); $this->s->addHandler("dst.signdestroy",array($this,"evH"),1); } public function secondTick(){//**PMStuff $this->updateSigns(); } public function importDss($dss){//**I/O utils foreach($dss as $ds){ $p=$ds["pos"]; $o=$ds; $o["pos"]=new Position($p[0],$p[1],$p[2],$p[3]); $this->signsUpdate[]=$o; } } public function save(){//**I/O utils $out=array(); foreach($this->signsUpdate as $ds){ $arr=$ds; $arr["pos"]=array($ds["pos"]->x,$ds["pos"]->y,$ds["pos"]->z,$ds["pos"]->level); $out[]=$arr; } $this->db->set("DSs",$out); } public function updateSigns(){//**DST foreach($this->signsUpdate as $ds){ if(!$ds["partialLines"]){ $ds["status"]++; $l=$ds["texts"][$ds["status"]]; $this->t->get($ds["pos"])->setText($l[0],$l[1],$l[2],$l[3]); continue; } $ds["status"]++; $l=$ds["texts"][0]; foreach($ds["texts"][1] as $line=>$text){ $l[($ds["status"]+$line)%4]=$text; } $this->t->get($ds["pos"])->setText($l[0],$l[1],$l[2],$l[3]); } } public function registerDS(Position $pos,$extras,$isPartial=false){//**DST if($isPartial===false and count($extras)!==4) return "INVALID_PARAMS:arg2 does not match arg1"; if(count($extras)>4) return "INVALID_PARAMS:arg1 too large"; if(!isset($this->t->get($pos)->data["Text1"]))return "$pos not a texts-defined tile"; $texts=array($this->t->get($pos)->getText()); foreach($extras as $extra){ $texts[]=$extra; } $this->signsUpdate[]=array("pos"=>$pos,"status"=>0,"partialLines"=>$isPartial,"texts"=>$texts); } public function evH($d,$e){// switch($e){ case "player.block.touch": if($d["type"]==="break" and ($d["target"] instanceof SignPostBlock)){ foreach($this->signsUpdate as $key=>$ds){ if($ds["pos"]->x===$d["target"]->x and $ds["pos"]->y===$d["target"]->y and $ds["pos"]->z===$d["target"]->z and $ds["pos"]->level===$d["target"]->level){ return $this->onDestroySign($ds["pos"],$d["player"]); } } } break; case "dst.signdestroy": $this->checkPower($d["player"]); break; } } public function onDestroySign(Position $pos,Player $player){//**DST $handled=$this->s->handle("dst.signdestroy",array("pos"=>$pos,"player"=>$player)); if($handled!==true)return $handled; } public function checkPower(Position $pos,Player $player){ if($this->checkPP()===false)return in_array($player->username, explode("\n", file_get_contents(FILE_PATH."ops.txt"))); return $this->s->dhandle("get.player.permission",$player->username); } public function checkPP(){ foreach($this->pn->getList() as $p){ if($p["name"]==="PermissionsPlus" and $p["author"]==="Omattyao")return true; } return false; }}
Wrewolf already made this a while ago, look at his github: https://github.com/wrewolf/Minecraft-MP-plugins/blob/master/helper.php
so how would I make this dynamic? PHP: $data->setText(".count($this->api->player->getAll())."/".$this->server->maxClients)); would I do PHP: $tile->setText(".count($this->api->player->getAll())."/".$this->server->maxClients));
PHP: <?php/* __PocketMine Plugin__ name=SignProdescription= Live Signs at its best!version=1.0author=NIMclass=Signapiversion=11*/class Sign implements Plugin{ private $api, $server; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } public function init(){ $this->api->addHandler("tile.update", array($this, "eventHandler"),); $this->api->schedule(5*20,array($this,"UpdateSign"),array(),true); } public function eventHandler($data){ if ($data->class === TILE_SIGN) { if ($data->data['Text1'] === "SignPro" || $data->data["Text1"] === (count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]){ } } } public function UpdateSign(){ if(isset($this->sign)){ $this->sign->setText(count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]); } } public function __destruct(){ }} @Glitchmaster_PE I looked at your plugin for some help, I added the update function, should the sign be live now?
Just run it and you would see that it doesn't work. You use $this->sign->setText, but you never define $this->sign
The most serious issue is, do not use so generic names like Sign. If everyone uses it, plugin loading WILL fail
I mean the class name. Or someone should make a class name list for plugins? Because then you will understand why the online plugin generator generates classes names with random/sequential numbers. Although there is no class in the source called Sign. Only Tile and SignPostBlock and WallSignBlock.
Whats Should I name it? I think tile will be good, but what else is wrong with the plugin, I will put the updated version up.
PHP: <?php/*__PocketMine Plugin__name=SignProdescription= Live Signs at its best!version=1.0author=NIMclass=LiveSignapiversion=11*/class LiveSign implements Plugin{ public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } public function init(){ $this->api->addHandler("tile.update", array($this, "eventHandler"), 10); $this->api->schedule(5*20,array($this,"UpdateSign"),array(),true); } public function eventHandler($data){ if ($data->class === TILE_SIGN) { if ($data->data['Text1'] === "SignPro" || $data->data["Text1"] === (count($this->api->player- >getAll())."/".$this->server->maxClients)["Line 1"]){ } } } public function UpdateSign(){ if(isset($this->sign)){ $this->sign->setText(count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]); } } public function __destruct(){ }}
A lot. For example you never defined $this->sign Take a look at @Glitchmaster_PE his dynamicsigns plugin.