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

Armor Not Showing Correctly

Comments in 'Plugin Development' started by WrackD, May 11, 2015.

  1. WrackD
    Offline

    WrackD New Member

    Joined:
    May 10, 2015
    Posts:
    7
    Minecraft User:
    WrackD
    Hey guys... Im quite new to PHP and plugins... I have a plugin set up perfectly... However, I have 2 signs Both with Join Team on the first line.... And on the second line, there is 'Diamond' for one and 'Gold' for the other one... Here is my code:
    PHP:
    public function onPlayerBlockTouch(PlayerInteractEvent $event){

            if(
    $event->getBlock()->getID() == 68){
                
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                
    $sign $sign->getText();
                if(
    $sign[0]=='Join Team'){
                   
                    if(
    $sign[1]=="Diamond")
                       
                        
    $event->getPlayer()->sendMessage($event->getPlayer()->getName()." joined the Team Diamond");
                        
    //Prevents most crashes
                    
    $event->getPlayer()->setNameTag("[Diamond] ".$event->getPlayer()->getName());
                    
    $event->getPlayer()->getInventory()->setHelmet(Item::get(310));
                    
    $event->getPlayer()->getInventory()->setChestplate(Item::get(311));
                    
    $event->getPlayer()->getInventory()->setLeggings(Item::get(312));
                    
    $event->getPlayer()->getInventory()->setBoots(Item::get(313));
                   
                   
                       
                }
               else if(
    $sign[1]=="Gold")
                       
                        
    $event->getPlayer()->sendMessage($event->getPlayer()->getName()." joined the Team Gold");
                        
                        
    $event->getPlayer()->setNameTag("[Gold] ".$event->getPlayer()->getName());
                    
    $event->getPlayer()->getInventory()->setHelmet(Item::get(314));
                    
    $event->getPlayer()->getInventory()->setChestplate(Item::get(315));
                    
    $event->getPlayer()->getInventory()->setLeggings(Item::get(316));
                    
    $event->getPlayer()->getInventory()->setBoots(Item::get(317));
                   
                }
                else{
                     
    $event->getPlayer()->getInventory()->setHelmet(Item::get(0));
                    
    $event->getPlayer()->getInventory()->setChestplate(Item::get(0));
                    
    $event->getPlayer()->getInventory()->setLeggings(Item::get(0));
                    
    $event->getPlayer()->getInventory()->setBoots(Item::get(0));
                   
                }
                
    $event->getPlayer()->getInventory()->sendArmorContents($event->getPlayer());

            }
    For some reason the diamond sign gives gold armor instead of diamond but sends the correct client message. And the gold one does not work at all....


    I also have another problem... :
    PHP:
    private $dollars = array();

    public function 
    onPlayerJoin(PlayerJoinEvent $pje){
            
    $name $pje->getPlayer()->getName();
           
            
    $this->$dollars[$name] = 100;
            
    $pje->getPlayer()->sendMessage("Gave ".$name." ".$this->$dollars[$name]." Dollars!!");
        }
    Whenever the Player joins it gives an error in the console saying :
    Code:
    [CRITICAL] Could not pass event pocketmine\event\player\PlayerJoinEvent to Pokedroid_PE v1.0.0: Undefined variable: dollars on WrackD\PokedroidPlugin\PokedroidPlugin
    13:16:19 [NOTICE] UndefinedVariableException: "Undefined variable: dollars" (E_NOTICE) in "/Pokedroid PE/src/WrackD/PokedroidPlugin/PokedroidPlugin" at line 41
    
    I would appreciate any help as soon as possible...
    Thanx in advance,
    Akharote1
  2. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Put
    PHP:
    $event->getPlayer()->getInventory()->sendArmorContents($event->getPlayer());
    in the else statement where you set the armour and add it to
    PHP:
    if($sign[1]=="Diamond")
     
    $event->getPlayer()->sendMessage($event->getPlayer()->getName()." joined the Team Diamond");//Prevents most crashes$event->getPlayer()->setNameTag("[Diamond] ".$event->getPlayer()->getName());$event->getPlayer()->getInventory()->setHelmet(Item::get(310));$event->getPlayer()->getInventory()->setChestplate(Item::get(311));$event->getPlayer()->getInventory()->setLeggings(Item::get(312));$event->getPlayer()->getInventory()->setBoots(Item::get(313));
    }
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It should be $this->dollars not $this->$dollars ;)
    iksaku likes this.
  4. WrackD
    Offline

    WrackD New Member

    Joined:
    May 10, 2015
    Posts:
    7
    Minecraft User:
    WrackD
    Still same problem.... It gives me gold for the diamond sign and the gold one does not work at all... Could it be something that my world is currupted?? I will try to load it from a backup where i had no code..... Also i fixed the second problem.... Thanx for trying to help.. :)
  5. WrackD
    Offline

    WrackD New Member

    Joined:
    May 10, 2015
    Posts:
    7
    Minecraft User:
    WrackD
    I fixed that one... The armor one is something which i have been trying since yesterday..... :(
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wat?
    Please note the short syntax for blocks in PHP:

    PHP:
    if(0){
      echo 
    "This only gets run if 1 is larger than zero.";
      echo 
    "Because I am in the curly braces {}, I still won't run unless 1 is greater than zero.";
    }
    echo 
    "This runs whether 1 is larger than zero or not
    ##########
    if(1 > 0)
      echo "
    I am only run because 1 is larger than 0; AND I am the first statement after the if().";
      echo "
    do not belong to the if() condition because only the first statement (or {} blockafter if() will be limited to the condition.";
    Please also note that PHP is indent-insensitive, line-break-insensitive (except line comments //) and space-insensitivie (unless you make two A-Z/a-z/0-9 characters that are supposed to be separated stick together).

    To understand all these easily, you can vase on these principles:
    • Code inside a {} (except class{} and function{}) is considered as one statement (one that groups child statements like other group statements or normal statements like function calls and return lines).
    • Only the first statement directly after if(), foreach() for(), while() (I am not sure if it applies to do, try, catch and finally) is affected by the condition in front of it (if/foreach/for/while). This statement can be a normal statement (like a function call, a return line or a variable assignment line) or a block statement (as mentioned in the first point). Therefore, using them without {} will only run the first statement after them.
    Finally, it is a good practice to stick to using {} only, since it would avoid stupid bugs.
    WrackD likes this.
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    could you give a new crashdump? Since the last error from the console you posted was about the $dollars variable :p
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is already fixed.

    And who told you it crashed? It just misbehaved.
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    He said there was still problems with it and I didn't know how to word it properly but I meant by crashdump was the errors that show up in the console :p
  10. WrackD
    Offline

    WrackD New Member

    Joined:
    May 10, 2015
    Posts:
    7
    Minecraft User:
    WrackD
    Thanx a lot to both of you.... All my problems are solved... :) I deleted one { by mistake and then copy and pasted it....:p
    iksaku and CrazedMiner like this.

Share This Page

Advertisement