A few questions

Discussion in 'Plugin Development' started by ShadowLAX, Aug 28, 2013.

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

    ShadowLAX

    Hello bukkit, I have a few questions/problems I need help with, If you can answer any of them please help! ^.^

    1) I am trying to make a game that cycles through all the payers. So when the game starts 2 players fight, and then when 1 of the players dies it starts again with 2 other players, and keeps going through all the players until the arraylist is down to 1 player/element.

    2) When my game starts, i have a horse spawned at a specific location. Sometimes however, instead of spawning just one, it spawns 2 or 3 horses and I have no idea why.

    Thank you! ^.^

    EDIT: Question one was a little screwed up, fixed now.
     
  2. ShadowLAX
    for the second question, maybe post your code?
     
  3. Offline

    ShadowLAX

    Datdenkikniet here is the code that involves the horse spawning:
    Code:
    Random rand = new Random();
                int r1;
                int r2;
                r1 = rand.nextInt(Main.alive.size());
                Main.alive.remove(r1);
                r2 = rand.nextInt(Main.alive.size());
                String r1n = Main.alive.get(r1);
                Main.alive.add(r1n);
                String r2n = Main.alive.get(r2);
                Player p1 = Bukkit.getServer().getPlayerExact(r1n);
                Player p2 = Bukkit.getServer().getPlayerExact(r2n);
                String p1n = p1.getName();
                String p2n = p2.getName();
                Main.ingame.add(p1n);
                Main.ingame.add(p2n);
                Horse horse1 = (Horse) p1.getWorld().spawnEntity(this.getHorse1Spawn(), EntityType.HORSE);
                Horse horse2 = (Horse) p2.getWorld().spawnEntity(this.getHorse2Spawn(), EntityType.HORSE);
                horse1.setAdult();
                horse2.setAdult();
                horse1.setColor(Color.BLACK);
                horse2.setColor(Color.WHITE);
    the methods getHorsespawn1 and 2 are getting a location from my config file for where the horses spawn
     
  4. Offline

    flaaghara

    For number 1: Get all the players in the game into a HashMap with a key whose index starts from 0 to however many people are in your game, and value of player name. Create an empty HashSet into which you can add players' names after the round is over. Use random integers to grab the key of the HashMap. If that key's value isn't already in the HashSet, then add the name to the HashSet. Do this until the HashSet's size is equal to that of the HashMap.
     
  5. hmmm, don't see what is wrong with that, maybe you have a loop somewhere you didn't close?
     
  6. Offline

    ShadowLAX

    flaaghara would using an arraylist work the same way, or must it be a HashMap?
     
  7. Offline

    flaaghara

    That's actually a better option. Good thinking. I assume ArrayList has a better benchmark too so yes.
     
  8. Offline

    ShadowLAX

    flaaghara thanks :p I was originally using an arraylist for it. the thing is though, I made the method game() which holds the picking of the players and I have it set so it is called when a player dies, but it doesn't work.

    How I get the player:
    Code:java
    1. Random rand = new Random();
    2. int r1;
    3. int r2;
    4. r1 = rand.nextInt(Main.alive.size());
    5. Main.alive.remove(r1);
    6. r2 = rand.nextInt(Main.alive.size());
    7. String r1n = Main.alive.get(r1);
    8. Main.alive.add(r1n);
    9. String r2n = Main.alive.get(r2);
    10. Player p1 = Bukkit.getServer().getPlayerExact(r1n);
    11. Player p2 = Bukkit.getServer().getPlayerExact(r2n);


    The death listener:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e) {
    3. Entity entity = e.getEntity();
    4. if (entity instanceof Player) {
    5. Player player = (Player) entity;
    6. String playern = player.getName();
    7. if (Main.ingame.contains(playern)) {
    8. e.setDeathMessage(ChatColor.RED + "Player " + playern + " has been slain!");
    9. Main.ingame.remove(player.getName());
    10. plugin.game();
    11. }
    12. }
    13. }


    the ArrayList is called ingame

    bump, help plz D:

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

    IceBurgers

    I would be interested in seeing this resolved!
     
  10. Offline

    xTrollxDudex

    IceBurgers
    No need to bump after OP has bumped himself, just watch the thread.
    ShadowLAX
    I'm confused. What's the current question?
     
  11. Offline

    IceBurgers

    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page