[Closed] Paint(Snow)Ball plugin!

Discussion in 'Plugin Development' started by billman555555, Sep 1, 2013.

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

    billman555555

    Hey i am developing a Paintball plugin using Snowballs as the Paintballs and need help.
    How do you make it so that when the snowball touches the player it teleports them to a place.
    Thanks!
    Assist
     
  2. billman555555
    If you're working with players in survival gamemode, listen for EntityDamageByEntityEvent, check if damaged entity is player, and damager is a snowball, if so, teleport.
    Code:
    @EventHandler
    public void onHit(EntityDamageByEntityEvent event) {
        if (event.getEntity() instanceof Player && event.getDamager() instanceof Snowball) {
            event.getEntity().teleport(new Location(world, x, y, z));
        }
    }
    If not, use ProjectileHitEvent, get the location, then get the closest player to that location, and teleport if location is <= 1.
     
  3. Offline

    billman555555

    Assist
    Thanks so much assist, now i need to make a GUI shop so that when PlayerInteractEvent it opens a GUI.

    EDIT: Also need a way to Set 1/2 of players (10 of 20) to Team Red and the other 1/2 to Team Blue and Check: if the player was in team Red or Blue.
     
  4. Offline

    Drkmaster83

    For the GUI, you'd do:
    Code:
    Inventory GUI = Bukkit.createInventory(null, "Title", sizeOfInventory);
    GUI.setItem(int slot#, ItemStack item); //Do for however many times you need
    player.openInventory(GUI);
    
    However, after doing that, you'd have to listen to InventoryClickEvent and InventoryDragEvent.

    For the two sets of teams, you'd create one ArrayList for Red and another for Blue. Then use Java's Random to decide things.
    Code:
    ArrayList<String> blueTeam = new ArrayList<String>();
    ArrayList<String> redTeam = new ArrayList<String>();
     
    Random r = new Random();
    int decidingFactor = r.nextInt() + 1;
    if(decidingFactor == 1)
    {
      if(blueTeam.size() > redTeam.size())
      {
        redTeam.add(player.getName());
        return;
      }
      blueTeam.add(player.getName());
      return;
    }
    else if(decidingFactor == 2)
    {
      if(redTeam.size() > blueTeam.size())
      {
        blueTeam.add(player.getName());
        return;
      }
      redTeam.add(player.getName());
      return;
    }
    
    I'm not quite sure if this is how you'd do it, but it seems like it should be. Should do a for-loop for every player using this, I think. However, you might want to check if the blueTeam or redTeam list is full.
     
  5. Offline

    billman555555

    Drkmaster83 Thanks for the GUI shop code and the base for Teams!

    Drkmaster83
    Assist
    How do i setup this so that slot 1 is DIAMOND:
    Code:
    GUI.setItem(int slot#, ItemStack item);
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    billman555555

    Assist
    Gives me mutiple errors, can i have the EXACT code?
     
  7. Offline

    billman555555

    Assist
    Oh sorry,
    i have an Inventory called Warp, i need the code to add a Bookshelf in slot 1.
    Code:
    Warp.setItem(1, ItemStack item);
    
    Wont work for me so i though i would ask.
     
  8. billman555555
    Code:
    Warp.setItem(1, new ItemStack(Material.BOOKSHELF, 1));
     
  9. Offline

    billman555555

    Assist
    Gives me errors in Eclipse
    Syntax errors and stuff
     
  10. Offline

    Henzz

    billman555555
    Sounds like to you need to read the Bukkit docs.
     
  11. Offline

    Drkmaster83

    Actually, the slots in an inventory are zero-based. So the first slot to the visual eye is:
    Code:
    Warp.setItem(0, new ItemStack(Material.BOOKSHELF, 1));
    
    Don't just stand there and tell him to read the JavaDocs, you have to link them too!
     
  12. Offline

    billman555555

    Hahahahahahhahaahhahahaaha!!^^

    Code:
        Inventory Warp = Bukkit.createInventory(null, 9, "Teleport");
        Warp.setItem(0, new ItemStack(Material.BOOKSHELF, 1));
    
    The first line is fine, the second (in eclipse) has an underline.

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

    Drkmaster83

    I'm pretty sure I'm about to humiliate you. Are you using net.minecraft.server.v1_6_2.ItemStack or org.bukkit.inventory.ItemStack?
    [​IMG]
     
  14. Offline

    billman555555

    Drkmaster83
    And thats were i fail.
    i didn't have it in onEnable().
    Thank you!
     
  15. Offline

    Waffletastic

    You'll want to learn how to make your own object structure for your plugins. Using Arrays and Sets will only get you so far.
     
  16. Offline

    Henzz

    Woah there mate, there's google for a reason, we can't be holding their hands.
     
  17. Offline

    Waffletastic

    Linking javadocs is considered hand holding? Shit, he didn't even ask for the javadocs but someone tried to help him out. Don't try and push your fear of appearing as a skid on other people.

    But yeah, to the OP, if you're new to Bukkit check this out as well: http://wiki.bukkit.org/Plugin_Tutorial
     
  18. Offline

    billman555555

    Assist
    How do i set it to send the hit player a message saying:
    [Paintball] Respawned!
    Code:
    event.getEntity().getPlayer().sendMessage("[Paintball] Respawned!");
    
    ^^ That is what i had in mind but it didn't work.
     
  19. Offline

    DrTURTLE2

    Like paintball plugins.
     
  20. Offline

    darkbro100



    Code:
     
    Player p = (Player) event.getEntity();
     
    p.sendMessage("[PaintBall] Respawned");
     
  21. Offline

    billman555555

    Last edited by a moderator: Jun 4, 2016
  22. Offline

    Waffletastic

    If you had read it you would know how to make send a message when a player is hit with a snowball.
     
  23. Offline

    billman555555

    Waffletastic
    I new how to send the player a message:
    Code:
    player.sendMessage(string);
    
    But not how to define player in that event>:D
     
Thread Status:
Not open for further replies.

Share This Page