1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Make player look at position

Discussion in 'Development' started by ethaniccc, Apr 8, 2020.

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    I made an AimBot command for fun, and I made a repeating task for the sender to look at the other player, here is my code:
    PHP:
    case "aimbot":
                if(
    $sender->getName() == "coEthaniccc" or $sender->getName() == "Epicthic" or $sender->getName() == "WillamLin1128"){
                    if(!isset(
    $this->aimbot[$sender->getName()])){
                        
    $sender->sendMessage(TextFormat::BOLD TextFormat::RED "This is a test and should not be abused!");
                        
    $this->aimbot[$sender->getName()] = $sender->getName();
                        
    $this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function (int $currentTick) use($sender) : void{
                            if(isset(
    $this->aimbot[$sender->getName()])){
                                foreach(
    $this->getServer()->getOnlinePlayers() as $player){
                                    if(
    $player->getX() - $sender->getX() <= 10 and $player->getX() - $sender->getX() >= -10 or $player->getZ() - $sender->getZ() <= 10 and $player->getZ() - $sender->getZ() >= -10){
                                        if(
    $player->getPosition() !== $sender->getPosition()){
                                            
    $sender->lookAt($player->getPosition());
                                        }
                                    }
                                }
                            }
                        }), 
    1);
                    } else {
                        
    $sender->sendMessage(TextFormat::BOLD TextFormat::GREEN "Aimbot has been disabled!");
                        unset(
    $this->aimbot[$sender->getName()]);
                    }
                } else {
                    
    $player->sendMessage(TextFormat::BOLD TextFormat::RED "You don't have permission to use this command!");
                }
                return 
    true;
                break;
    I think you can't use lookAt for a player, is there any alternative?
    Thanks in advance!

    P.S: If you find an error with my code, please tell me
     
    Last edited: Apr 8, 2020
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.