[MiniGame] I need help making a game.

Discussion in 'Plugin Development' started by historio, Jul 24, 2013.

?

How much of this thread makes sense?

  1. 100%

    42.9%
  2. 50%

    42.9%
  3. 0%

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

    historio

    I need help with making this game so far I have made this

    (My main idea for this plugin is just a simple PvP minigame)

    Code:java
    1. package me.historio13.AkpGame;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.GameMode;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.enchantments.Enchantment;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class AkpGame extends JavaPlugin {
    17.  
    18. Location loc = new Location(Bukkit.getWorld("World"), 188.53028, 79.000,
    19. 268.41069);
    20. int timer = 60;
    21.  
    22. public boolean onCommand(CommandSender sender, Command cmd,
    23. String commandLabel, String[] args) {
    24. final Player player = (Player) sender;
    25.  
    26. if (player.hasPermission("AkpGame.Start") || player.isOp())
    27. ;
    28. if (cmd.getName().equalsIgnoreCase("start")) {
    29. new Location(player.getWorld(), 188.53028, 79.000, 268.41069);
    30.  
    31. }
    32. final ItemStack Sword = new ItemStack(Material.STONE_SWORD);
    33. ItemMeta SwordMeta = Sword.getItemMeta();
    34. SwordMeta.setDisplayName(ChatColor.AQUA + "Sword");
    35. Sword.setItemMeta(SwordMeta);
    36. Sword.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
    37. Sword.addUnsafeEnchantment(Enchantment.KNOCKBACK, 2);
    38. Bukkit.broadcastMessage(ChatColor.GOLD + "{" + ChatColor.DARK_GREEN
    39. + "Advanced" + ChatColor.GRAY + "Kit" + ChatColor.DARK_RED
    40. + "PvP" + ChatColor.BLUE + "Game" + ChatColor.GOLD + "} "
    41. + "Game starting in 1 minute");
    42. Bukkit.broadcastMessage(ChatColor.GOLD + "{" + ChatColor.DARK_GREEN
    43. + "Advanced" + ChatColor.GRAY + "Kit" + ChatColor.DARK_RED
    44. + "PvP" + ChatColor.BLUE + "Game" + ChatColor.GOLD + "} "
    45. + "Look at you exp bar!");
    46. this.getServer().getScheduler()
    47. .scheduleSyncRepeatingTask(this, new Runnable() {
    48.  
    49. public void run() {
    50. if (timer != -1) {
    51. if (timer != 0) {
    52. for (Player players : Bukkit.getOnlinePlayers()) {
    53. players.setLevel(timer);
    54. }
    55. timer--;
    56. } else {
    57. Bukkit.broadcastMessage(ChatColor.GOLD + "{"
    58. + ChatColor.DARK_GREEN + "Advanced"
    59. + ChatColor.GRAY + "Kit"
    60. + ChatColor.DARK_RED + "PvP"
    61. + ChatColor.BLUE + "Game"
    62. + ChatColor.GOLD + "} "
    63. + "Game starting!");
    64. for (Player players : Bukkit.getOnlinePlayers()) {
    65. players.setLevel(0);
    66. }
    67. for (Player players : Bukkit.getOnlinePlayers()) {
    68. players.teleport(loc);
    69. players.setGameMode(GameMode.SURVIVAL);
    70. System.out.println(player.getName()
    71. + " Has joined the game");
    72. players.getInventory().clear();
    73. players.getInventory().addItem(Sword);
    74. }
    75. timer--;
    76. }
    77. }
    78. }
    79. }, 0L, 20L);
    80. return false;
    81. }
    82. }

    Q1: How would I add something like if all the players die in one game the last player alive wins and then game resets ?
    Q2: How would I get the server to check if there are any players in the game.
    Q3: If anyone would like to help me improve my code generally that would help me a lot.

    Note: I'm still learning java and i'm sorry if this post doesn't make any sense.

    No one wants to help me? :'(

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

    chasechocolate

    It's been 5 minutes -_-
     
  3. Offline

    historio

    chasechocolate I know :D

    chasechocolate How bad does this thread look to you?

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

    chasechocolate

    historio
    1. Make an List<String> of players in the game, when they die, remove them from the list and check if the size is 1 which means that there is 1 player left in the game.

    2. See #1 (use a List).

    EDIT: Quit bumping your thread ._.
     
  5. Offline

    artish1

    You can try and create a /join command where the player will be teleported to the arena and then add the players name into a list, you can create an automatic start by checking if the list = numberofPlayerstoStart and then after that give the players the items, then go into a listener on PlayerDeathEvent and if the player is in that list, Remove, and set their respawn location back to the lobby. Also in PlayerDeathEvent, check if the list.size() == 1, and if so then get the player object with Bukkit.getPlayer(list.get(0)); then tell that player they've won and tp them back to lobby and do whatever else you want with them, you can also try creating a manual start command (/start) instead of automatic, just incase if anything goes wrong.

    To get all the players that have joined, you can create a method that returns a list of strings.
    so something like public List<String> getPlayersinArena(){ }, and in there create a for loop, looping through the list that you've obtained from people who have been added using the /join command, and then add them to a list in the method that hopefully you've declared before, then return that list, or you can make it List<Player>

    Also for the game reset, just do list.clear() and tp all players to the lobby and clear anything else that needs to be cleared that was involved into the game, or put them back to default if needed
     
    LegoPal92 likes this.
  6. Offline

    historio

    chasechocolate Like this?

    Code:java
    1. List<String> list = new ArrayList<String>();
    2. @EventHandler
    3. public void PlayerDeathEvent(PlayerDeathEvent e) {
    4. //Player Player = e.getPlayer(); <-- Doesn't work ?
    5. //list.add(player?)
    6. }
     
  7. Offline

    Chiller

    People, stop posting your WHOLE class and just post the snippet of code which is giving you troubles!
     
  8. Offline

    historio

    artish1 Thanks I will try and do some of that :D
     
  9. Offline

    chasechocolate

    historio use e.getEntity() (despite the name, it returns a Player object). And use list.remove(player.getName()) after checking if the player is in the list.
     
  10. Offline

    historio

    Chiller That is a snippet of my code?

    chasechocolate Ok I will try that now.

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

    Chiller

    This is not a snippet... This is a whole class.

     
  12. Offline

    historio

    Chiller Sorry :oops:

    chasechocolate Like this?

    Code:java
    1. @EventHandler
    2. public void PlayerDeathEvent(PlayerDeathEvent e) {
    3. Player player = e.getEntity();
    4. if(list.contains(player.getName()));
    5. //Check if the player is alive or something like that right?
    6. } else {
    7. list.remove(player.getName());


    Error : "} else {" gives me this error "Syntax error on token "else", delete this token"

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

    xTrollxDudex

    historio
    Instead of starting a real if statemet you happen to put a ; at the end of it
     
  14. Offline

    Mycrowut

    Code:java
    1. @EventHandler
    2. public void PlayerDeathEvent(PlayerDeathEvent e) {
    3. Player player = e.getEntity();
    4. if(list.contains(player.getName())){
    5. //Check if the player is alive or something like that right?
    6. } else {
    7. list.remove(player.getName());
     
  15. Offline

    historio

  16. Offline

    xTrollxDudex

  17. Offline

    historio

    xTrollxDudex Can you help me finish this thing ?

    P.s If you don't want to help me I don't mined :'(

    Can anyone help me finish this?

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

    Mycrowut

    historio
    We can't help you with anything unless you ask a question.
    Sorry to put this so harsh but - we're here to answer your questions, not code a plugin for you.

    If you don't know how to code plugins correctly you need to watch every video by
    http://youtube.com/thebcbroz
     
  19. Offline

    historio

    chasechocolate What do I do now ?

    Code:java
    1. List<String> list = new ArrayList<String>();
    2.  
    3. @EventHandler
    4. public void PlayerDeathEvent(PlayerDeathEvent e) {
    5. Player player = e.getEntity();
    6. if (list.contains(player.getName())) {
    7. } else {
    8. list.remove(player.getName());
    9. }
    10. }
     

  20. you remove the player from the list if he is NOT in the list

    Code:java
    1.  
    2. if (list.contains(player.getName())) {
    3. list.remove(player.getName());
    4. }
     
  21. Offline

    historio

    bluegru How do i get the plugin to tell how many people are in the game ?

    Bump.

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

    WhatAaCow

  23. Offline

    historio

  24. historio I can tell you when I'm at home, in a few hours,
     
  25. Offline

    LightcraftLP

    historio .... so ... if you are german this channel is great! you can learn many about it: http://youtube.com/PostCrafter ... but i think you are american! But I'm a little bit intresting.... In the next weeks i can help you a little bit. I like Kit PvP and this theme is for me very cool. Have you got a Youtube Channel? My channel is ColdyEyeFX =)
     
  26. Offline

    historio

    bluegru Okay :D

    LightcraftLP I'm english!

    LightcraftLP I haven't got a youtube channel sorry I'll make one

    LightcraftLP I have already made a kit pvp Plugin (Its private)

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

  27. Write every player who joins the game in a list, then you can use list.size();
     
  28. Offline

    historio

    bluegru I will try and do that but i'm not sure if i know how tho Oh well :p
     
  29. Offline

    Scr3am

    Learn Java.
     
  30. Offline

    historio

    Scr3am Did you not see this on my first post? "Note: I'm still learning java"

    I came here so people could help me learn java.
     
Thread Status:
Not open for further replies.

Share This Page