Archer class : LongShot

Discussion in 'Plugin Development' started by TCO_007, Mar 22, 2014.

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

    TCO_007

    Hey guys! I am making an Archer kit for my kits server. Basically what I want it to do is when the shooter hits the enemy and the enemy was 30 blocks away, I want it to double the damage and message the player LongShot! Damage doubled! Any help guys? Thanks!
    This is the code I have so far but I am not sure what to do next.
    Code:java
    1. public void ArcherShot(EntityDamageByEntityEvent e){
    2. Player p = (Player) e.getEntity();
    3. Player d = (Player) e.getDamager();
    4. if (plugin.Archer.contains(d.getName())){
    5. if (e.getDamager() instanceof Player && e.getEntity() instanceof Player){
    6. if ( )
    7.  
    8. }
    9. }
    10.  
    11. }
    12.  
     
  2. Offline

    tommyhoogstra

    Id assume it would be something like
    if(p.getLocation().getBlockX() == d.getLocation().getBlockX() + 30){

    }

    Untested, so not sure if it works like that
     
  3. Offline

    TCO_007

    I put that in and it made me get rid of the X to say it works. What would I do after that though to double the damage? I already tried p.getLastDamage() * 2 but it said the left side but be a variable. This is my code now...
    Code:java
    1. public void ArcherShot(EntityDamageByEntityEvent e){
    2. Player p = (Player) e.getEntity();
    3. Player d = (Player) e.getDamager();
    4. if (plugin.Archer.contains(d.getName())){
    5. if (e.getDamager() instanceof Player && e.getEntity() instanceof Player){
    6. if(p.getLocation().getBlock().equals(d.getLocation().getBlockX() + 30));{
    7.  
    8.  
    9. }
    10.  
    11. }
    12. }
    13.  
    14. }
    15. }
     
  4. Offline

    tommyhoogstra


    Try
    Code:java
    1. if(event.getCause() == DamageCause.PROJECTILE){
    2. if(event.getDamager() instanceof Arrow){
    3. if(event.getEntity() instanceof Player){
    4. event.setDamage(2x Whatever the damage of the arrow WOULD be);
    5. }
     
  5. Offline

    AoH_Ruthless

    TCO_007
    Here's a method that I use to check if a player is nearby

    Code:java
    1. public static boolean isClose(Player p, Player result, int distance) {
    2. // Loop through all nearby entities and check if the player we are looking for is in them.
    3. for (Entity e : p.getNearbyEntities(distance, distance, distance)) {
    4. if (e instanceof Player) {
    5. Player player = (Player) e;
    6. if (player.getName().equalsIgnoreCase(result.getName()))
    7. return true;
    8. continue;
    9. }
    10. }
    11. return false;
    12. }


    Now, you want to check if the player is not within 30 blocks away:
    Code:java
    1. if (!isClose(d, p, 30)) {
    2. e.setDamage(e.getDamage() * 2);
    3. }
     
  6. Offline

    TCO_007

    Where would I put that code though? I tried to branch if off of my code but it would work. Do I erase my code and input your code or..... tommyhoogstra

    Thank you AoH_Ruthless
    Ill see if yours works :D

    Let's see. I just changed something in it and there are no errors now with yours tommyhoogstra so is there any errors with this that you guys can see?
    Code:java
    1. public void ArcherShot(EntityDamageByEntityEvent e){
    2. Player p = (Player) e.getEntity();
    3. Player d = (Player) e.getDamager();
    4. if (plugin.Archer.contains(d.getName())){
    5. if (e.getDamager() instanceof Player && e.getEntity() instanceof Player){
    6. if(p.getLocation().getBlock().equals(d.getLocation().getBlockX() + 30));{
    7. if(e.getCause() == DamageCause.PROJECTILE){
    8. if (!isClose(d, p, 30)) {
    9. if(e.getDamager() instanceof Arrow){
    10. if(e.getEntity() instanceof Player){
    11. e.setDamage((e.getDamage() * 2));
    12. }
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }
    19. }
    20. public static boolean isClose(Player p, Player result, int distance) {
    21. // Loop through all nearby entities and check if the player we are looking for is in them.
    22. for (Entity e : p.getNearbyEntities(distance, distance, distance)) {
    23. if (e instanceof Player) {
    24. Player player = (Player) e;
    25. if (player.getName().equalsIgnoreCase(result.getName()))
    26. return true;
    27. continue;
    28. }
    29. }
    30. return false;
    31. }
    32. }


    It still doesnt work D:

    I dont know why though. Any help? My code is still the same as the one above.

    Whats happening is a shot right next to the player still does the same amount of damage as the player is 30 blocks away. I want the plugin to be able to tell that the player if the player is more than 30 blocks away and hits the enemy, it will deal double the damage. Nothings happening though.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 3, 2018
  7. Offline

    tommyhoogstra

    It should just go into your last if statement fine, whats it telling you?
     
  8. Offline

    Minesuchtiiii

    First get the instance then cast:

    Code:java
    1. Entity ent = e.getEntity();
    2. Entity dam = e.getDamager();
    3.  
    4. if(ent instanceof Player && dam instanceof Arrow) {
    5. Player p = (Player) e.getEntity();
    6. Entity a = (Arrow) e.getDamager();
    7.  
    8. }
     
  9. Offline

    TCO_007

    so like this?
    Code:java
    1. @EventHandler
    2. public void ArcherShot(EntityDamageByEntityEvent e){
    3. Player p = (Player) e.getEntity();
    4. Player d = (Player) e.getDamager();
    5. if (plugin.Archer.contains(d.getName())){
    6. Entity ent = e.getEntity();
    7. Entity dam = e.getDamager();
    8.  
    9. if(ent instanceof Player && dam instanceof Arrow) {
    10. Entity a = (Arrow) e.getDamager();
    11. if (!isClose(d, p, 30)) {
    12. e.setDamage((e.getDamage() * 2));
    13. }
    14. }
    15. }
    16. }
    17. public static boolean isClose(Player p, Player result, int distance) {
    18. // Loop through all nearby entities and check if the player we are looking for is in them.
    19. for (Entity e : p.getNearbyEntities(distance, distance, distance)) {
    20. if (e instanceof Player) {
    21. Player player = (Player) e;
    22. if (player.getName().equalsIgnoreCase(result.getName()))
    23. return true;
    24. continue;
    25. }
    26. }
    27. return false;
    28. }
    29.  
    30.  
    31. }


    Minesuchtiiii

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

    Minesuchtiiii

    I think yes @ TCO_007
     
Thread Status:
Not open for further replies.

Share This Page