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

[YET UNRESLOVED]I need help with my code for my mini-game plugin.

Comments in 'Plugin Development' started by iiDeathStrokeii, Apr 5, 2015.

  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Im new to coding and the code below doesn't do what I want it to do, in other words it doesn't work.

    PHP:
    public function onMove(PlayerMoveEvent $event){
             

                
    $PlayerMoveCheck $event->getPlayer();
                if (isset (
    $SpleefOnePlayerOne) and $this->SpeefOneInProgress == null){
                 
                 
                                            if (
    $PlayerMoveCheck == $SpleefOnePlayerOne){
                                         
                                             
                                            
    $event->setCancelled();
                                            
    $event->getPlayer()->sendMessage("Movement stuff seems to be working :)");
                                             
                                             
                                             
                                            }
                 
                }
                }
                }
    The concept of the code above is basically if a mini-game lobby is yet not started (indicated by $SpeefOneInProgress) and if the first mini-game position/player has been allocated to a player ($SpleefOnePlayerOne which was set earlier on in my plugin), as you can see this is all wrapped in a PlayerMoveEvent function so the code checks all the players who move (indicated by $PlayerMoveCheck) and back to the code from before, so if the $PlayerMoveCheck is the same as $SpleefOnePlayerOne whilst $SpleefOneInProgress == null it should send the player a message and also stop them from moving as the event is cancelled.

    The code doesn't do anything and I have no errors in my PocketMine console, so what is that im doing wrong?
    Help would be much appreciated, thanks in advance.



    Could it be that it is because $SpleefOnePlayerOne is yet not set?

    Heres the code that sets that specific variable:

    PHP:
    private $SpleefOnePlayerOne;
    PHP:
    if (!isset($SpleefOnePlayerOne) or $this->getServer()->getPlayer($this->SpleefOnePlayerOne)->isOnline() == false) {
                  
                            
    $this->SpleefOnePlayerOne = ($this->getName());
                            
    $event->getPlayer()->teleport(new Vector3(-120626280));
                            
    $player->sendMessage("[Spleef] Please Wait.");
                            
    $item Item::get(256,0,1);
                            
    $player->getInventory()->addItem($item);
                          
                        }
    Last edited: Apr 5, 2015
  2. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  3. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
  4. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
  6. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Curse my keyboard, yes now you may all commence the LOLs
    Goerick and LDX like this.
  7. Goerick
    Offline

    Goerick Active Member

    Joined:
    Jan 24, 2014
    Posts:
    250
    Minecraft User:
    goerick
    LOL
  8. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    umm still doesn't seem to work with this simple patch/spelling error.
  9. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    PHP:
     public function onMove(PlayerMoveEvent $event){

               

                
    $PlayerMoveCheck $event->getPlayer();
                if (isset (
    $SpleefOnePlayerOne) and $this->SpleefOneInProgress == null){
                   
                   
                                            if (
    $PlayerMoveCheck == $SpleefOnePlayerOne){
                                           
                                               
                                            
    $event->setCancelled();
                                            
    $event->getPlayer()->sendMessage("Movement stuff seems to be working :)");
                                               
                                               
                                               
                                            }
                   
                }
                }
  10. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Try replacing $PlayerMoveCheck = $event->getPlayer(); with $PlayerMoveCheck = $event->getPlayer()->getName();
  11. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Gosh, still doesn't work :(
  12. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    I even tried:
    PHP:
     public function onMove(PlayerMoveEvent $event){

               

                
    $PlayerMoveCheck = ($this->getName());
                if (isset (
    $SpleefOnePlayerOne) and $this->SpleefOneInProgress == null){
                   
                   
                                            if (
    $PlayerMoveCheck == $SpleefOnePlayerOne){
                                           
                                               
                                            
    $event->setCancelled();
                                            
    $event->getPlayer()->sendMessage("Movement stuff seems to be working :)");
                                               
                                               
                                               
                                            }
                   
                }
                }
    Last edited: Apr 5, 2015
  13. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    I still require help :(
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Obviously $SpleefOnePlayerOne is undefined. Suppose you should use isset($this->SpleefOnePlayerOne) instead?

    Also, I can see that you are going to make $this->SpleefOne $this->SpleefTwo blah. Why don't you make an array and use a foreach() loop to simplify your code instead?
    LDX likes this.

Share This Page

Advertisement