Does anyone know how to add certain armor to the armor slot instead of your inventory. I want players to spawn with armor instead of having to epuip them.
I think LDXs AdminArmor plugin has an open source version downloadable from the plugin repository. Try looking at his code and see if that helps.
From LDX AdminArmor plugin: PHP: $issuer->setArmor(0,$this->getArmor(310)); $issuer->setArmor(1,$this->getArmor(311)); $issuer->setArmor(2,$this->getArmor(312)); $issuer->setArmor(3,$this->getArmor(313));
Can you insert the code inside spawnwithitems? PHP: <?php/* __PocketMine Plugin__name=SpawnWithItemsdescription=When you connect to a server, give you selected items automatically.version=1.5author=MinecrafterJPNclass=SpawnWithItemsapiversion=9,10,11,12*/// Updated API by LDXdefine("INVENTORY_SLOT", 35);class SpawnWithItems implements Plugin{ private $api; private $path; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } public function init(){ $this->api->addHandler("player.spawn", array($this, 'eventHandler'), 10); $this->api->addHandler("player.respawn", array($this, 'eventHandler'), 10); $this->api->console->register("swi", "Give items to all joiners automatically when they connect", array($this, "commandHandler")); $this->path = $this->api->plugin->createConfig($this, array()); } public function eventHandler($data, $event){ switch($event){ case "player.spawn": if($data->getGamemode() === "creative") break; $cfg = $this->api->plugin->readYAML($this->path . "config.yml"); foreach($cfg as $info){ if($info['ID'] === 'money'){ $this->api->dhandle("money.handle", array( 'username' => $data->username, 'method' => 'grant', 'amount' => $info['count'] )); }else{ $fullFlag = true; $item = BlockAPI::getItem($info['ID'], $info['meta'], $info['count']); for($i = 0; $i < INVENTORY_SLOT; $i++){ if($data->getSlot($i)->getID() === 0){ $data->setSlot($i, $item); $fullFlag = false; break; } } if($fullFlag){ $this->api->chat->sendTo(false, "[SpawnWithItems]Your inventory is full.", $data->username); break; } } } break;case "player.respawn": if($data->getGamemode() === "creative") break; $cfg = $this->api->plugin->readYAML($this->path . "config.yml"); foreach($cfg as $info){ if($info['ID'] === 'money'){ $this->api->dhandle("money.handle", array( 'username' => $data->username, 'method' => 'grant', 'amount' => $info['count'] )); }else{ $fullFlag = true; $item = BlockAPI::getItem($info['ID'], $info['meta'], $info['count']); for($i = 0; $i < INVENTORY_SLOT; $i++){ if($data->getSlot($i)->getID() === 0){ $data->setSlot($i, $item); $fullFlag = false; break; } } if($fullFlag){ $this->api->chat->sendTo(false, "[SpawnWithItems]Your inventory is full.", $data->username); break; } } }break; } }// SWI on death added by LDX public function commandHandler($cmd, $params, $issuer, $alias){ $output = ""; switch($cmd){ case "swi": if($issuer !== "console"){ $output .= "Must be run on the console.\n"; break; } if(!isset($params[0])){ console("Usage: /swi <itemID> [count] [meta] or /swi money <amount>"); break; } if($params[0] === "money"){ if(!is_numeric($params[1]) or $params[1] < 0){ console("[SpawnWithItems]<amount> : numeric and plus"); break; } $dat = array( array( 'ID' => 'money', 'count' => $params[1], 'meta' => 0 ) ); $this->overwriteConfig($dat); console("[SpawnWithItems]Money : $params[1]"); }else{ if(!is_numeric($params[0])){ console("[SpawnWithItems]<itemID> : numeric"); break; } $itemID = $params[0]; if(isset($params[1])){ if($params[1] === "MAX"){ $count = BlockAPI::getItem($itemID)->getMaxStackSize(); }else if(is_numeric($params[1])){ $count = trim($params[1]); }else{ console("[SpawnWithItems][count] : numeric"); break; } }else{ $count = BlockAPI::getItem($itemID)->getMaxStackSize(); } if(isset($params[2])){ if(is_numeric($params[2]) === false){ console("[SpawnWithItems][meta] : numeric"); break; } $meta = trim($params[2]); }else{ $meta = 0; } $dat = array( array( 'ID' => $itemID, 'count' => $count, 'meta' => $meta ) ); $this->overwriteConfig($dat); console("[SpawnWithItems]$itemID : $count : $meta"); } break; } return $output; } private function overwriteConfig($dat){ $cfg = array(); $cfg = $this->api->plugin->readYAML($this->path . 'config.yml'); $result = array_merge($cfg, $dat); $this->api->plugin->writeYAML($this->path.'config.yml', $result); } public function __destruct(){ }}
Add this in player.spawn PHP: $issuer->setArmor(0,$this->getArmor(310)); $issuer->setArmor(1,$this->getArmor(311)); $issuer->setArmor(2,$this->getArmor(312)); $issuer->setArmor(3,$this->getArmor(313));
thats wrong code actually. $issuer as i understand corresponds to people who issued a command for example, so this might not work.
i just copied/pasted these lines to show you the function you need to add pieces of armor; setArmo(slot,$this->api->block->getItem(armorid))
That's pretty cool. I didn't think it could be done as the hot bar cant be read. Yeah i know it isn't actually the hot bar.