Solved Skeletons without bows.... Again

Discussion in 'Plugin Development' started by fresser123, Apr 3, 2013.

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

    fresser123

    I know that its impossible to add bows to spawned skeletons atm. (Else, please help me ;))

    But.
    Im creating an arena, where there needs to be turrets. These turrets needs to shoot. If i cant use skeletons (Im controlling their targets) then i dont know what to do.

    Any ideas?
     
  2. Offline

    kreashenz

    I have only experienced this as a bug in the Nether.. I don't think its very normal in the over world.
     
  3. Offline

    MylesIsCool

    I've been having it too, quite an annoying bug. Happens when spawning skeles for me in any world.
     
  4. Offline

    fresser123

    Found the soluion.
    Code:
    NexusRed1.getEquipment().setItemInHand(new ItemStack(Material.BOW,1));
    
    Worked as a charm. (Discovered myself)

    Does anybody know if i can modify the damage of the skeleton?
    Code:
    NexusRed1.damage(8);
    Didnt work..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    MylesIsCool likes this.
  5. Offline

    LucasEmanuel

    You could just calculate a vector that points at the target then spawn an arrow with that vector. No need to have skeletons. But it might be looking a bit better with skeletons :)
     
    microgeek likes this.
  6. Offline

    fresser123

    "You could just" - Sorry, i can not "just" make it.
    Im pretty new to both java and bukkit. So some help would be appreciated, if you want ;)
     
  7. Offline

    MCForger

    On damage by entity event if the arrow shot at the entity came from one of your skeletons or turrets then add damage.
     
  8. Offline

    fresser123

    MCForger
    Ty, haven't got that a thought.
    However, is it possible to change the arrow-frequency, or do i need LucasEmanuel 's method there?
     
  9. Offline

    LucasEmanuel

    fresser123
    Well I was pretty much just brainstorming. :) Right after that post I tried doing it myself but it turned out pretty darn difficult. I got the yaw working, the pitch thou just didn't want to work. I have yet to learn how to calculate a vector pointing from one point in 3d space to an other. :)
     
  10. Offline

    fresser123

    LucasEmanuel
    You could maybe just fire the arrow in a really high speed. Then you dont need to think about y coordinates.
     
  11. Offline

    LucasEmanuel

    fresser123
    My test code could aim at the player only horizontally, it couldn't aim up or down. :)
     
  12. Offline

    fresser123

    LucasEmanuel
    Well.
    Couldnt you download the code from MCP in the original minecraft? :)
     
  13. Offline

    MCForger

    fresser123 LucasEmanuel
    Run a scheduler and as long as the arrow hasn't stopped set the velocity towards the players location. When it has stopped cancel the task
     
  14. Offline

    LucasEmanuel

    fresser123 MCForger
    I got it working :D It seemed that all i had to do was take a walk with my dog to clear my head :)

    Code:
    final Player player = (Player) sender;
     
    final Location location = player.getLocation().clone().add(0, 1, 0);
     
    final double x = location.getX();
    final double y = location.getY();
    final double z = location.getZ();
     
    plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
        public void run() {
         
            if(location.distanceSquared(player.getLocation()) <= 100) {
             
                double dX, dY, dZ;
             
                dX = x - player.getLocation().getX();
                dY = y - (player.getLocation().getY() + player.getEyeHeight());
                dZ = z - player.getLocation().getZ();
                 
                double yaw = Math.atan2(dZ, dX);
                double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
             
                double X = Math.sin(pitch) * Math.cos(yaw);
                double Y = Math.sin(pitch) * Math.sin(yaw);
                double Z = Math.cos(pitch);
             
                Vector vector = new Vector(X, Z, Y);
             
                location.getWorld().spawnArrow(location, vector, (float) 2, (float) 0);
            }
        }
    }, 20L, 10L);
     
    microgeek likes this.
  15. Offline

    fresser123

    LucasEmanuel
    May i understand that "100" is distance away from place theres spawning the arrow?
    And this will work at any distance? :D (Got some trolling ideas...)
     
  16. Offline

    LucasEmanuel

    fresser123
    No, the 100 defines that the "turret" only fires on the player if he is within a radius of 10 (10 squared is 100) blocks :)
     
  17. Offline

    fresser123

    LucasEmanuel

    Oh, ty.
    Can i write:
    location.distanceSphered(player.getLocation())
    or something?
     
  18. Offline

    LucasEmanuel

    Code:
    location.distanceSquared(player.getLocation());
    Returns how far it is between the location and the player squared :)
     
  19. Offline

    fresser123

  20. Offline

    LucasEmanuel

    fresser123
    Well, when they call it squared they refer to that the area of a square is the width times itself (width * width). You could also call it "to the power of two" (width^2). Then there is cubed, referring to that the area of a cube is the width times it self three times (width * width * width), also called "to the power of three" (width^3).

    It's just easier to say that something is squared or cubed when something is multiplied with itself 2 or 3 times :)

    So 10 squared equals to 10 * 10 which is 100 :)

    10 * 10 = 100 = 10^2
     
  21. Offline

    fresser123

    LucasEmanuel
    I know ;)
    But, can i get it circular?
    Instead of square.
     
  22. Offline

    TheButlah

    fresser123
    Ummm.... Wha?
    Is this supposed to be a trololol question?
     
    ferrybig and MCForger like this.
  23. Offline

    fresser123

    TheButlah
    You know what a circle and a square is? - You know the difference? - Right.
     
  24. fresser123 think better...., it returns (x difference wiht both location) ^ 2 + (y difference wiht both location) ^2 + (z difference wiht both location)
     
  25. Offline

    fresser123

    I see...
    LucasEmanuel
    Using your code this way:
    Code:
    final Location location = new Location(plugin.w,505.5,37,188.5); //Location of my turret
    plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    public void run() {
    for (Player p: Bukkit.getOnlinePlayers()) {
    final double x = location.getX();
    final double y = location.getY();
    final double z = location.getZ();
    final Player player = p;
    if(location.distanceSquared(player.getLocation()) <= 100) {
    player.sendMessage("DUMP ASS"); //Some kind of debug  ^_^
    double dX, dY, dZ;
     
    dX = x - player.getLocation().getX();
    dY = y - (player.getLocation().getY() + player.getEyeHeight());
    dZ = z - player.getLocation().getZ();
     
    double yaw = Math.atan2(dZ, dX);
    double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
     
    double X = Math.sin(pitch) * Math.cos(yaw);
    double Y = Math.sin(pitch) * Math.sin(yaw);
    double Z = Math.cos(pitch);
     
    Vector vector = new Vector(X, Z, Y);
     
    location.getWorld().spawnArrow(location, vector, (float) 2, (float) 0);
    }
    }
    }
    }, 20L, 10L);
    Does not detect the player. What have i done wrong? :O
     
  26. Offline

    LucasEmanuel

    Change this
    Code:
    if(location.distanceSquared(player.getLocation()) <= 100) {
    to this
    Code:
    if(location.distanceSquared(p.getLocation()) <= 100) {
    and these
    Code:
    final double x = location.getX();
    final double y = location.getY();
    final double z = location.getZ();
    to
    Code:
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    and remove this line
    Code:
    final Player player = p;
     
  27. Offline

    fresser123

    Code:
    final Location redSpawn = new Location(plugin.w,526,40,213);
    plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    public void run() {
    for (Player p: Bukkit.getOnlinePlayers()) {
    if(((Team) p.getMetadata("Team").get(0).value()) == Team.BLUE){
    final double x = redSpawn.getX();
    final double y = redSpawn.getY();
    final double z = redSpawn.getZ();
    final Player player = p;
    if(redSpawn.distanceSquared(player.getLocation()) <= 144) {
    double dX, dY, dZ;
     
    dX = x - player.getLocation().getX();
    dY = y - (player.getLocation().getY() + player.getEyeHeight());
    dZ = z - player.getLocation().getZ();
     
    double yaw = Math.atan2(dZ, dX);
    double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
     
    double X = Math.sin(pitch) * Math.cos(yaw);
    double Y = Math.sin(pitch) * Math.sin(yaw);
    double Z = Math.cos(pitch);
     
    Vector vector = new Vector(X, Z, Y);
     
    Arrow arrow = (Arrow) redSpawn.getWorld().spawnArrow(redSpawn, vector, (float) 2, (float) 0);
    arrow.setMetadata("Spawnarrow", new FixedMetadataValue(plugin, Spawnarrow.TRUE));
    }
    }
    }
    }
    }, 20L, 2L);
    Worked for me.
     
Thread Status:
Not open for further replies.

Share This Page