Team Games Proggraming

Discussion in 'WIP and Development Status' started by Insanehero, Jan 23, 2011.

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

    Insanehero

    Ok so I have a few plugin games I've been thinking of that would be setup by teams( blue and a red team) But, Im a bit lost at the moment with my Proggraming for this and I'm looking for a few pointers. I would to have it setup where an Adimn does something like /start teambattle and then it allows people to be able to say like /join blue team ( or red team) Or if Adimn just does a command for them like /add (playername) red team. Looking for a few tips on how exactly how I would do this.
     
  2. Offline

    MadMichi

    I think after reading this and this you might have a clue where to start. If you have questions on your code then you are very welcome to ask here again.
    An idea i had instantly when reading your post was: try to get in contact with the developer of this plugin and ask him if you may use his work to point out who is in wich team. (i.e. tnt heads vs. dirt heads *lol* just an idea ;) ) Maybe he even likes to help you with that.
     
  3. Offline

    Snowl

    Here's a brief way to do it:

    Under your main .class

    Code:
    public class Teams extends JavaPlugin {
        private final TeamsPlayerListener playerListener = new TeamsPlayerListener(this);
        private final TeamsBlockListener blockListener = new TeamsBlockListener(this);
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
        private ArrayList<Player> TeamRedList = new ArrayList<Player>();
        private ArrayList<Player> TeamBlueList = new ArrayList<Player>();
    After onEnable() (still in your main class):
    Code:
        public void TeamRemove (Player player) {
            while (TeamBlueList.remove(player));
            while (TeamRedList.remove(player));
        }
    
       public void TeamBlueAdd (Player player) {
            if (!TeamBlueList.contains(player)) {
                TeamBlueList.add(player);
            }
        }
    
        public boolean TeamBlueStatus (Player player) {
            if (TeamBlueList.contains(player)) {
                return true;
            }
            return false;
        }
      public void TeamRedAdd (Player player) {
            if (!TeamRedList.contains(player)) {
                TeamRedList.add(player);
            }
        }
        public boolean TeamRedStatus (Player player) {
            if (TeamRedList.contains(player)) {
                return true;
            }
            return false;
        }
    You can then call
    Code:
    plugin.TeamBlueAdd(event.getPlayer());
    
    to add a person to the blue team, or
    Code:
    plugin.TeamRedAdd(event.getPlayer());
    
    to add a person to the red team.

    To check if a person is on a team,
    Code:
                	if (plugin.TeamBlueStatus(event.getPlayer())) {
                          //blueTeam stuff
                    }
                   else if (plugin.TeamRedStatus(event.getPlayer())) {
                          //redTeam stuff
                    }
                    else {
                         //Player doesnt belong to a team :(
                     }
    
    To remove a player from a team:
    Code:
    plugin.TeamRemove(event.getPlayer());
    
    Is that easy or what :D

    EDIT: Fixed a typo in the code :S
     
  4. Offline

    Lycake

    I thinks it's not a problem to set up the teams. The "games" will be more difficult. What kind of games are you thinking of?
    Anyway. If we should help you it would be great to know how familiar you are with java. Post #2 is for those who have never seen java before. Post #3 for those who programmed java a few hours already.

    Cake
     
  5. Offline

    kazimir

    I hacked Davids code into eclipse, customized it a bit and compiled it.
    Works great...a small team management.

    Uploaded Source and Jar to googlecode.
    http://code.google.com/p/bukkit-teamgames/

    If you're interested in, we can work on this together.
    If you are going to do it on your own, i will delete the project, because this plugin was your idea.
     
  6. Offline

    Snowl

    -ignore me-
     
  7. Offline

    kazimir

    Sorry David,
    i meant it is Insanes idea. He started this thread asking for help.
    And i don't want to steal his idea. :D
     
  8. Offline

    Snowl

    oh LMAO sorry it too early in the morning -.-
     
  9. Offline

    Zand

    As long as the project is open-source I don't mined if you use code from my plugin.

    Here is a copy of the core function in my BlockHead plugin.
    It will place the item on the players head into there inventory or drop it on the ground if there is no room. Then it will put 1 item with the same ID as item stack onto there head and subtract 1 from the stack.
    Code:
    placeOnHead(player, new ItemStack(itemId));
    Code:
    private boolean placeOnHead(Player player, ItemStack item) {
        	PlayerInventory inv = player.getInventory();
    		if (item.getAmount() < 1) {
    			player.sendMessage(ChatColor.RED + "You have no item in your hand");
    			return false;
    		}
    
    		int id = item.getTypeId();
    		if (id < 1 || id > 255) {
    			player.sendMessage(ChatColor.RED + "You can't put that item on your head");
    			return false;
    		}
    
    		ItemStack helmet = inv.getHelmet();
    ItemStack helmet = inv.getHelmet();
    ItemStack hat = new ItemStack(item.getType());
    hat.setData(item.getData()); // For colored cloth
    hat.setDamage(item.getDamage());
            
    inv.setHelmet(hat);
    		inv.setHelmet(new ItemStack(id, 1));
    		if (item.getAmount() > 1) item.setAmount(item.getAmount()-1);
    		else inv.remove(item);
    
    		// put what was in the helmet spot back
    		if (helmet.getAmount() > 0) {
    			HashMap<Integer, ItemStack> leftover = inv.addItem(helmet);
    			if (!leftover.isEmpty()) {
    				player.sendMessage("Was unble to put the old headhear away, droping it at your feet");
    
    				// Drop the stacks
    				for (Map.Entry<Integer, ItemStack> e : leftover.entrySet())
    					player.getWorld().dropItem(player.getLocation(), e.getValue());
    			}
    		}
    
    		player.sendMessage("Enjoy your new Headgear");
    		return true;
        }
    
    I will be updating this function when I have time so it would be best to keep an eye on my GitHub account.
     
  10. Offline

    kazimir

    Ah, thats nice to color the team members with red and blue wool :D

    PS: Trying to implement the first game :D
     
  11. Offline

    Zand

    Well the planed update for that function was too add support for complex blocks witch is what colored wool is. So until then the color will default to white. Working I'm on fixing that now.

    *edit Fixed, I also updated the code in my post to support colored cloth. You can set a cloths color by setting its damage 1-15.
     
Thread Status:
Not open for further replies.

Share This Page