[SOLVED]Player die in radius of location

Discussion in 'Plugin Development' started by ceoepts, Jul 11, 2012.

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

    ceoepts

    Hi guys, i have been trying to make that if a player is standing in a 5block radius from a location i have in my config file.
    config.yml
    And i want the code to repeat every 1 secound.
    I have tryed but i cant get work.
    Please help me :D

    anyone? :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  2. Could you rephrase what you are attempting to do?
    Also, what do you have so far?
     
  3. Offline

    ceoepts

    I had a code but nothing was working in that code. So i have nothing i cant figur it out
    and i a player to die when they are entring bluespawn/redspawn heres the config with the locations and the world
    Understand now?

    Please help?

    Bump?

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

    stelar7

    so, you want a player that comes within 5 blocks of a location to die?

    if so, use a scheduler and check if a player is near that location
     
  5. Offline

    ceoepts

    I know that but i have some problems i am using the config could you help me making it that if the player is near the positions in the config he dies :p

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. i would also like to know how this is done
     
  7. Offline

    ceoepts

    Only hope someone that know it is replaying :oops:
     
  8. you want something whit the schedular and location.distance?
     
  9. Offline

    ceoepts

    Yes but i have problem with getting the location from the config to :p Please help me.
     
  10. Offline

    Father Of Time

    As stated above, use a sheduler, and each time the runnable is executed do the following:

    1) get the players location and store it in a variable
    2) get the location from your config file and store it in a variable
    3) do a distance check from player location to "death location"
    4) if the distance is greater than 5 continue, if the distance is fewer then five... Axe the dude!

    something like this:

    Code:
     Location playerloc = player.getLocation();
     Location deathloc = // how ever you are loading your location from your config
     if( playerloc.distance( deathloc ) <= 5 )
     {
      // kill the player
     }
    
    Remember, cut and paste is bad... I only provide code to individuals who will evaluate and understand the snippets, so please read it carefully and understand what is happening, and if you have any questions simply let us know.

    Good luck, I hope this helps. :D

    Sorry, I am no use on this one... I don't ever use Bukkits config files. If I remember correctly from what I have read, I believe that locations can't actually be stored, but rather 3 integers and a String representing their X, Y, Z and worldname; but I could be completely wrong on this.

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

    ceoepts

    Thanks again! But could you help me with getting the Location from the config:p
    Config:
    Code:
    # Deafault configuration!
    BLUESPAWN:
      Loc: -548.0,72.0,1270.0
      World: world
    REDSPAWN:
      Loc: -548.0,72.0,1263.0
      World: world
    
    Ok but could you help me with getting the player?:)

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

    Father Of Time

    As I stated above, I simply don't have experience with config.yml; I would advise clicking search, limiting the board being searched to plug-in development and then type in "config.yml location" to see what pops up, this has been discussed dozen upon dozens of times, the answer is surely out there.
     
  13. Offline

    ceoepts

    As i said can you help me with getting the player?
     
  14. Offline

    Father Of Time

    You need to provide us your code, and if you don't have code you need to attempt it to the best of your ability and post the broken code.

    Sorry, but I am very against providing people code, I require they atleast try on their own first for learning purposes.

    I'm assuming this is a game of some sort, so you likely have a collection that stores players; during the sync event you would grab that collection and iterate it to evaluate their locations. If you don't have a collection then you could simple use the getOnlinePlayers() function to get everyone online, but that isn't optimal.

    I means this as politely as possible, but I feel you are attempting to bite off far more than you can chew. You are attempting to make a system that absolutely requires the usage of classes, collections and delayed task; do you fully understand any of those three items? If not I would definately recommend reading about and fully understanding those three objects before moving forward.

    Trial and error is great, but sometimes you need to read to subsidize the knowledge gained from experimentation.
     
    ferrybig and Bone008 like this.
  15. Offline

    ase34

    In the config, you could save the coordinates of the blocks separate so it's easier to get the coordinates:
    Code:
    BLUESPAWN:
        x: -548
        y: 72
        z: 1270
        world: world
    REDSPAWN:
        x: -548
        y: 72
        z: 1263
        world: world
    Then in the plugin you cang get the coordinates by:
    Code:java
    1. BlockVector redspawn = new BlockVector(
    2. config.getInt("REDSPAWN.x"),
    3. config.getInt("REDSPAWN.y"),
    4. config.getInt("REDSPAWN.z"));
     
  16. Offline

    ceoepts

    Thx i have done it like that now. :)
     
  17. Ok so i've done it like this now:
    But i get error on the if line with the distance.

    the goal is to poison players on the location from the config.

    Code:java
    1.  
    2. public void onLocation(PlayerMoveEvent event) {
    3. BlockVector poisonloc = new BlockVector(
    4. plugin.getConfig().getInt("POISONLOC.x"),
    5. plugin.getConfig().getInt("POISONLOC.y"),
    6. plugin.getConfig().getInt("POISONLOC.z"));
    7.  
    8. Player player = event.getPlayer();
    9. Location playerloc = player.getLocation();
    10. if( playerloc.distance( poisonloc ) <= 5 )
    11. {
    12. // kill the player
    13. }
    14. }
     
  18. Offline

    ceoepts

    Thanks guys! I got is working heres my final code.
    Sorry i did'nt see your comment :p Thanks for trying to help me :)

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

    Father Of Time

    I'm happy to hear you accomplished your goal, that was a fairly complicated concept for a beginning to wrap their head around.

    I am impressed with how quckly you learn, well done ceoepts. :D
     
    ceoepts likes this.
  20. Offline

    ceoepts

    Thx :D
     
  21. i want to do the same but his code doesn't work for me. should i open a new thread or continue here?
     
  22. Offline

    ceoepts

    No. whats the problem first i can try to fix it :)
     
  23. well this is what i got now, but fails on the getConfig:

    Code:java
    1.  
    2. public void onLocation(PlayerMoveEvent event) {
    3.  
    4. Player player = event.getPlayer();
    5. Location PlayerLocation = player.getLocation();
    6.  
    7. double x = getConfig().getDouble("PL.X");
    8. double y = getConfig().getDouble("PL.Y");
    9. double z = getConfig().getDouble("PL.Z");
    10. String world = getConfig().getString("PL.world");
    11. Location PoisonLoc = new Location(getWorld(world), x, y, z);
    12.  
    13. if( PlayerLocation.distance( PoisonLoc ) <= 5 ) {
    14. // do delayed schedule here
    15. }
    16. }
    17.  
     
  24. Offline

    ceoepts

    I think i know the error
    1. go to the main class file.
    2. place this code in onEnable
    Code:
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
               public void run() {
                    //The code here
               }
            }, 60L, 20L);
    Its a schedule and its making the code repeat every 1 secound.
    }, 60L, 20L);
    READ!
    The 20L means that its 20/20 and its that the code is repeating every 1 secound. If you want to change it to 2 secounds change the 20L to 40L that means 40/20 and thats 2 secound and this is 3 secounds 60L (60/20).
    read more about schedule here http://wiki.bukkit.org/Scheduler_Programming :)
    Hope it helps :D
     
  25. helps a lot man, i'm getting there!
    still get an error though.
    this is inside my onEnable now:

    Code:
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
                  public void run() {
                   
                      for (Player player : getServer().getOnlinePlayers()){
                          int duration = (plugin.getSettings().getInt("abilitytime")*1200);
                       
                              double x = plugin.getConfig().getDouble("PL.X");
                                double y = plugin.getConfig().getDouble("PL.Y");
                                double z = plugin.getConfig().getDouble("PL.Z");
                                String world = plugin.getConfig().getString("PL.world");
                                Location PoisonLoc = new Location(getWorld(world), x, y, z);
                             
                                if( PlayerLocation.distance( PoisonLoc ) <= 5 )
                          {
                              PotionEffect effect = new PotionEffect(PotionEffectType.POISON,duration,1);
                              effect.apply(event.getEntity());
                          }
                          return ;
                      }
                  }
                }, 60L, 20L);
            }
    the errors i'm getting are:
    - The method getWorld(string) is undefined for the type new runnable(){}

    - PlayerLocation cannot be resolved. i know why i get this, but not where to set the playerlocation, this is the code i use for it though: Location PlayerLocation = player.getLocation();

    - event cannot be resolved. this is on the effect.apply line
     
  26. Offline

    EnvisionRed

    When you create the new Runnable() you are actually creating a new class. So inside your class you have to declare the plugin or it won't work.
     
  27. i have decleared the plugin above what you see here, but not inside the onEnable. is that wrong?
     
  28. Offline

    gjossep

    Is this in your main class or a other one? Also on you onEnable try getting the config values and print it to the console, so that you can see if it's a problem with your config!
     
  29. that code is old, see my more recent post for the right code.
     
  30. Offline

    ceoepts

    I found one thing if you hav'nt fixed it add this
    Location PlayerLocation = player.getLocation();
    And
    Replace plugin. with this.
     
Thread Status:
Not open for further replies.

Share This Page