Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to add armor in armor slot

Comments in 'Plugin Development' started by Legomite, Apr 26, 2014.

  1. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    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.
  2. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    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.
    Darunia18 likes this.
  3. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    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));
  4. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    Does (1, tell what slot to use? And the thong in (311) is a diamond chestplate?
  5. Legomite
    Offline

    Legomite Active Member Plugin Developer

    Joined:
    Sep 8, 2013
    Posts:
    470
    Plugins:
    2
    Minecraft User:
    Legomite
    Can you insert the code inside spawnwithitems?
    PHP:
    <?php

    /*
     __PocketMine Plugin__
    name=SpawnWithItems
    description=When you connect to a server, give you selected items automatically.
    version=1.5
    author=MinecrafterJPN
    class=SpawnWithItems
    apiversion=9,10,11,12
    */

    // Updated API by LDX

    define("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(){
        }
    }
  6. Anton Magsino
    Offline

    Anton Magsino Active Member

    Joined:
    Jan 17, 2014
    Posts:
    58
    Minecraft User:
    MinecrafterPH
    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));
  7. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    thats wrong code actually. $issuer as i understand corresponds to people who issued a command for example, so this might not work.
  8. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    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))
  9. DopeteK
    Offline

    DopeteK Active Member

    Joined:
    Aug 24, 2013
    Posts:
    393
    Minecraft User:
    DTeK
    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.

Share This Page

Advertisement