Getting the players target.

Discussion in 'Plugin Development' started by Orcem12, Mar 31, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Orcem12

    I'm developing a server manager combining with basic commands, spells, class and party system. I'm about 50% there, however, I need some help doing what the topic says: For example; If the player is looking at Player A and he types a command lets say "ht" (heal target) how would Player B be healed by the caster?

    Model:
    Player A: +
    Player B: +

    + ------> + (20 blocks away)

    I tried searching through some source coding to try and find a reference, but everyone has their own way. Thanks for all incoming advice if any.
     
  2. Offline

    TopGear93

    Really? I thought you were an experienced dev on these forums.

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = null;
            if ((sender instanceof Player)) {
                player = (Player)sender;
                if (label.equalsIgnoreCase("ht")) {
                    if (args.length == 1) {
                            name = args[0];
                            target = Bukkit.getPlayer(name);
                            if(sender.equals(name)){
                                player.sendMessage(" you cant heal yourself.");
                                return false;
                            }
                            name = args[0].toLowerCase();
                            target = Bukkit.getPlayer(name);
                            if(target != null){
                              target.setHealth(x);
                                return true;
                            }
                          player.sendMessage("Player not available");
                            return false;
                        }
                    }
                }
     
  3. I think you kinda misunderstood him. He wants to get the player B that player A targets with his cursor and not specifying the other player in the command.
     
  4. Offline

    Orcem12

    This ^
    Getting the players name using an argument would be simple enough but that's last resort.
     
  5. you gcan get the target block, and calculating what players are near it
     
  6. Offline

    Orcem12

    That would make sense. What would be the most efficient method to doing this? I understand what your saying, but would I just register a shape out of said targeted block and check if a player is inside said shape?
     
  7. I dont know ann ways to do it whoever
     
  8. Offline

    dsmyth1915

    cool effect, maybe you could send a smoking projectile toward your crosshairs, and any other entities said projectile encounters, get's healed.
     
  9. Offline

    Orcem12

    Interesting idea. I'll attempt this, actually not even that hard.

    @TopGear93
    I know how to do that, I think you misunderstood my question ^^" :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  10. Offline

    colony88

    What you could possibly do is make it an onPlayerInteractEvent for example for Healing hands or something like that...
     
  11. Offline

    dsmyth1915

    Orcem12 Did you ever find a successful way to accomplish this?
     
  12. Offline

    Orcem12

    As Colony suggested, a simple pat on a back from the player and the spell starts. Worked like a charm.
     
  13. Offline

    dsmyth1915

    Glad it works :) even though OP says you wanted it to be up to 20 blocks away.
     
Thread Status:
Not open for further replies.

Share This Page