Solved Survival Games Podium Spawning

Discussion in 'Plugin Development' started by LordVakar, Jun 18, 2014.

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

    LordVakar

    I'm having trouble writing the spawning system on podiums for my survival games plugin.
    I'm using OOP with game (arena) objects. I'm trying to make a command where you can add a spawn for an arena and it will save it in the config file.
    So it'd be something like this in the config:
    Code:
                            Arena:
                                Arena1:
                                    Podium1:
                                        CoordsHere
                                    Podium2:
                                        CoordsHere
                                Arena2:
                                    Podium1:
                                        CoordsHere
                                    Podium2:
                                        CoordsHere
    How would I save the location of each podium to it's correct int and then when the game starts teleport each player to a different podium (24 podiums) and no people are on the same podium?
    I've been trying everything from Location lists to Location arrays but I can't figure how to do it ._.
     
  2. You could use for saving and loading.
    First. You have this list with locations.
    Second. In your save method, you make an ArrayList<String>.
    Third. You make a for loop, for(Location loc: spawnlocations).
    Fourth. You make a string with the world and the x y z of the location separated by a :, and add it to the string list.
    Fifth. You save the stringlist in the config.

    If you want to load it, you just do this backwards.

    For the spawning.
    First. Make a hashmap, HashMap<Integer,Boolean>. This will say if the location is occupied.
    Second. I. The spawn method make a for loop, for(int I = 0; I < maxplayers; I++).
    Third. Then get the boolean that's in the hashmap with I as argument.
    Fourth. Check if it's null, if it's null you add in the hashmap that it's occupied. hashmap.put(I,true), then you let the player spawn on the right location and break the for loop. If it's not null you check if the boolean is = false, if so you just do the same as if it's null. If it's true, you do nothing.

    That should help you.
     
  3. Offline

    LordVakar

    Bram0101
    Thanks, I'll try it.
    I already got the saving to work 2 hours previous your post but not the spawning.

    EDIT:
    How would you teleport the player to the right one?

    EDIT 2:
    This is my code so far:
    Code:java
    1. for(int I = 0; I < a.getArenaLimit(); I++) {
    2. Boolean derp = spawns.get(I);
    3. if(derp == null) {
    4. spawns.put(I,true);
    5. break;
    6. }
    7. else if(derp = false) {
    8. spawns.put(I,true);
    9. //Teleport players?
    10. break;
    11. }
    12. else if(derp = true) {
    13. //Do Nothing
    14. }
    15. }


    Bram0101
    I figured out how to teleport the players (I think) but now I don't know how to get all the players that haven't been put on a podium yet.
    Code:java
    1. String world = arenaPodiumsConfig.getString(arenaName + ".world");
    2. String pathx = arenaName + ".spawn" + I + ".x";
    3. String pathy = arenaName + ".spawn" + I + ".y";
    4. String pathz = arenaName + ".spawn" + I + ".z";
    5. Location loc = new Location(Bukkit.getWorld(world), arenaPodiumsConfig.getInt(pathx), arenaPodiumsConfig.getInt(pathy), arenaPodiumsConfig.getInt(pathz));
    6. Bukkit.getPlayer(PlayersThatHaventBeenPutOnPodiumYet).teleport(loc);


    Is the I the podium number like I'm using it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Yes. And for your previous post,
    Code:java
    1. for(int I = 0; I < a.getArenaLimit(); I++) {
    2. Boolean derp = spawns.get(I);
    3. if(derp == null) {
    4. spawns.put(I,true);
    5. //you must also add it to here, the teleport code!!!
    6. break;
    7. }
    8. else if(derp = false) {
    9. spawns.put(I,true);
    10. //Teleport players? Yes!
    11. //use the code you had earlier.
    12. break;
    13. }
    14. else if(derp = true) {
    15. //Do Nothing
    16. }
    17. }
     
  5. Offline

    LordVakar

    Bram0101
    But how would I get the PlayersThatHaventBeenPutOnPodiumYet to teleport like in my teleport code?
     
  6. You can have an arraylist that has the players name that has teleported, or you use a hashmap that also has the players name but also has the podium(I think you mean stage, because podium is dutch for stage) there on.
     
  7. Offline

    LordVakar

    Bram0101
    The thing is, I'm not sure where to add the player to an arraylist in my code or how to get the player because my method doesn't have a player parameter.
     
  8. If you post the full class, I will add the things to it, to make it (hopefully) work.
     
  9. Offline

    LordVakar

    Bram0101
    I think I got it all to work, I can't test it since I'm not done with my plugin. Can you read over the code and see if it looks good?
    I added the player to a list when they join the arena and I teleported them by getting their name from that list. If they left the arena, I would remove their name and if the game ended I would remove their name.
    This is my startArena method which teleports the players.
    Code:java
    1. public void startArena(String arenaName) {
    2. Game a = getArena(arenaName);
    3. if (a != null) {
    4. a.messageAllPlayers(prefix + ChatColor.AQUA
    5. + "The arena has started!");
    6. GameState.getManager().setState(State.ARENA);
    7. for (int I = 0; I < a.getArenaLimit(); I++) {
    8. Boolean derp = spawns.get(I);
    9. if (derp == null) {
    10. spawns.put(I, true);
    11. for (String allP : a.getPlayersNotOnPodium()) {
    12. String world = arenaPodiumsConfig.getString(arenaName
    13. + ".world");
    14. String pathx = arenaName + ".spawn" + I + ".x";
    15. String pathy = arenaName + ".spawn" + I + ".y";
    16. String pathz = arenaName + ".spawn" + I + ".z";
    17. Location loc = new Location(Bukkit.getWorld(world),
    18. arenaPodiumsConfig.getInt(pathx),
    19. arenaPodiumsConfig.getInt(pathy),
    20. arenaPodiumsConfig.getInt(pathz));
    21. Bukkit.getPlayer(allP).teleport(loc);
    22. }
    23. break;
    24. } else if (derp = false) {
    25. spawns.put(I, true);
    26. for (String allP : a.getPlayersNotOnPodium()) {
    27. String world = arenaPodiumsConfig.getString(arenaName
    28. + ".world");
    29. String pathx = arenaName + ".spawn" + I + ".x";
    30. String pathy = arenaName + ".spawn" + I + ".y";
    31. String pathz = arenaName + ".spawn" + I + ".z";
    32. Location loc = new Location(Bukkit.getWorld(world),
    33. arenaPodiumsConfig.getInt(pathx),
    34. arenaPodiumsConfig.getInt(pathy),
    35. arenaPodiumsConfig.getInt(pathz));
    36. Bukkit.getPlayer(allP).teleport(loc);
    37. }
    38. break;
    39. } else if (derp = true) {
    40. // Do Nothing
    41. }
    42. }
    43.  
    44. }
    45. }
     
  10. LordVakar
    The only thing I think is wrong is the for loop where you get the players that aren't on the podium.
    So instead of
    for (String allP : a.getPlayersNotOnPodium()) {

    String allP = a.getPlayersNotOnPodium().get(I);
     
  11. Offline

    LordVakar

    Bram0101
    Thanks for your help!
    I think my code will work now, when I finish the entire plugin I'll know.
    Marking as solved.
     
Thread Status:
Not open for further replies.

Share This Page