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

why dosnt this work

Comments in 'Plugin Development' started by Puzzleo, Nov 22, 2013.

  1. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
    i am making a coords command to tpall and i thought it was right but it always crashes
    PHP:
    public function coords($cmd$args $issuer$x$y$z $level ){
    if(
    $issuer == 'console'){

    console("Please run this command in-game.");

    } else {
    $x $issuer->entity->x;
    $y $issuer->entity->y;
    $z $issuer->entity->z;
    $level $issuer->level;
    $this->api->chat->broadcast("You are at X: $x Y: $y Z: $z on the world: $level".$issuer);
  2. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    This should work:
    PHP:
    public function coords($cmd$args$issuer){
        if(
    $issuer === 'console'){
            return 
    'Please run this command in-game.';
        }
        return 
    'You are at X: '.$issuer->entity->x.' Y: '.$issuer->entity->y.' Z: '.$issuer->entity->z.' in the world: '.$issuer->level->getName();
    }
    Last edited: Nov 22, 2013
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    The coord variables are not needed, unless you want them:
    PHP:
    public function coords($cmd$args$issuer){
        if(
    $issuer === 'console'){
            return 
    'Please run this command in-game.';
        }
        return 
    'You are at X: '.$issuer->entity->x.' Y: '.$issuer->entity->y.' Z: '.$issuer->entity->z.' in the world: '.$issuer->level->getName();
    }
  4. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
    PHP:
    public function coords($cmd$args $issuer$x$y$z $level$params){
    if(
    $issuer == 'console'){

    console("Please run this command in-game.");

    } else {
    $input =$params[0];
    $x $issuer->entity->x;
    $x=round($rawz,2);
    $y $issuer->entity->y;
    $y=round($rawz,2);
    $z $issuer->entity->z;
    $z=round($rawz,2);
    $output ='player is at X: $x Y: $y Z: $z in the world: '.$issuer->level->getName();
    return 
    $output;
    }
    }
    what about this
  5. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    You label $x, $y, and $z twice and then don't label $rawz
  6. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
  7. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
    PHP:
    public function coords($cmd$args $issuer$x$y$z $level$params){
    if(
    $issuer == 'console'){

    console("Please run this command in-game.");

    } else {
    $input =$params[0];
    $rawx $issuer->entity->x;
    $x=round($rawx,2);
    $rawy $issuer->entity->y;
    $y=round($rawy,2);
    $rawz $issuer->entity->z;
    $z=round($rawz,2);
    $output ='player is at X: $x Y: $y Z: $z in the world: '.$issuer->level->getName();
    return 
    $output;
    }
    }
  8. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
    i got this code but it crashes isnt floor meant to round down
    PHP:
    public function coords($cmd$args $issuer$x$y$z $level$params$rawx $rawy $rawz){
    if(
    $issuer == 'console'){

    console("Please run this command in-game.");

    } else {
    $input =$params[0];
    $rawx floor($issuer->entity->x);
    $x=round($rawx,2);
    $rawx floor($issuer->entity->y);
    $y=round($rawy,2);
    $rawz floor($issuer->entity->z);
    $z=round($rawz,2);
    $output ="player is at X: $x Y: $y Z: $z in the world: '.$issuer->level->getName()'";
    return 
    $output;
    }
    }
  9. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    If you want round values do this:
    PHP:
    public function coords($cmd$args$issuer){
        if(
    $issuer === 'console'){
            return 
    'Please run this command in-game.';
        }
        
    $x round($issuer->entity->x);
        
    $y round($issuer->entity->y);
        
    $z round($issuer->entity->z);
        
    $levelName $issuer->level->getName();
        return 
    'You are at X: '.$x.' Y: '.$y.' Z: '.$z.' in the world: '.$levelName;
    }
  10. Puzzleo
    Offline

    Puzzleo Banned

    Joined:
    Sep 7, 2013
    Posts:
    88
    Minecraft User:
    puzzleo
    dont worry i already fixed it
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Is there any exception apart from Player and Console that can do cmds?
  12. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    Yes rcon
  13. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    Wies help.. does this work, im editing Your peacful spawn
    Code:
    public function healthchange($data){
            $player = $data['entity'];
            $t = new Vector2($player->x, $player->z);
            $s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
            if($t->distance($s) <= $this->server->api->getProperty('spawn-protection')){
            return 'You cant hurt player in spawn area.';
                return false;
            }      
        }
      
        public function __destruct(){}
    
    }
  14. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    No it won't, you need to use $player->sendChat('You cant hurt player in spawn area.');
    JassperBeastHD likes this.
  15. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    Where though what line
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In function cmdHandler(), PocketMine API collects the returned value and prints to the console/player chat message as [CMD] $string
    However, in function eventHandler(), PocketMine API collects the returned value as a boolean (true/false) and if it is false stops calling the functions in the priority after it. (parameter 3 in addHandler())
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Moreover, the lines after a value is returned in a function are dead code (unless it is in an if block). So you can't return multiple values. (Judging on the tabspaces, you seem to give the wrong code, swapping lines)

Share This Page

Advertisement