Solved Get location behind player and have NPC always teleport

Discussion in 'Plugin Development' started by Xp10d3, Sep 18, 2020.

  1. Offline

    Xp10d3

    Hello! So, I've posted many threads already, so sorry for yet another one. I am attempting to use Citizens and want to get the location behind the player. This is for a anti-aura plugin and since I need to check if the player is hitting a player behind them, I need to spawn an NPC behind the player, check if they are hitting it, and if they are, do stuff. It would be best to have a variable that stores the angle so I can check if the player is hitting the NPC from all angles. However, I do have a piece of code that does this, but the issue is that Citizens only allows npc#spawn to use Location, not double. Here is the code:
    Code:java
    1.  
    2. double test = player.getLocation().getDirection().angle(player.getLocation().getDirection()) / 180 * Math.PI;
    3.  

    That get's the location behind the player (180*, of course), but this:
    Code:java
    1.  
    2. npc.spawn(loc);
    3.  

    Only allows Location. What do I do?

    Also, if you can let me know how to always teleport the NPC to a certain location, please tell me xD Note that I am using Citizens API.
     
  2. Offline

    Xp10d3

  3. Offline

    gochi9

    Ok so what is the problem with the code that i gave you in the last post.Something like this should work just fine

    Code:
            Player player = ev.getPlayer();
            Location entityLoc = player.getLocation().add(player.getLocation().getDirection().multiply(-1));
           
            player.getWorld().spawnEntity(entityLoc, EntityType.ARMOR_STAND);
     
  4. Offline

    Xp10d3

    I didn't say there was any problem... although I should've referred to that originally. I assumed that was for pushing entities to another location, but I was stupid and didn't think of recoding it. Apologies gochi9. Will think this through in the future. Thanks for the help. Marking as solved.
     

Share This Page