[Tutorial] Simple Guns

Discussion in 'Resources' started by negative_codezZ, Oct 25, 2013.

?

Was this helpful?

  1. Yes

    16 vote(s)
    47.1%
  2. No

    10 vote(s)
    29.4%
  3. Kind of

    8 vote(s)
    23.5%
Thread Status:
Not open for further replies.
  1. Offline

    beaudigi

    With the second one I added sounds and made the snowball become "t"
    However it did nto shoot mak the smoke effect or the sound
     
  2. Offline

    negative_codezZ

    You are doing such at the player's location and not where the snowball hits.
     
  3. Offline

    PieMan456

  4. Offline

    negative_codezZ

    I don't know what you mean by "metadata"
     
  5. Offline

    PieMan456

    negative_codezZ
    Metadata like this:
    egg.setMetadata("grenade", new FixedMetadataValue(this, true));
     
  6. Offline

    negative_codezZ

    I recommend reading this.
     
  7. Offline

    beaudigi

    Yeah thats what I want
    Why dosent the gun example you have shown (2nd spoiler) not work ? Its really bugging me
     
  8. Offline

    w84u2cy

    I'm not sure why people care if it's helpful or not.
    It's not hurting anyone, in fact, it's helping some.
    Great Job ;)
     
  9. Offline

    negative_codezZ

    Thank you very much.
     
  10. Offline

    sunny.zhang

    negative_codezZ My bazooka is causing the same damage as the Nuke_Launcher. Here is my code, I tried as i hard as i could and could not fix it! Thnaks!
    Main:
    Code:java
    1. package thebawsgamer.projectiles;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.inventory.ShapedRecipe;
    9. import org.bukkit.inventory.meta.ItemMeta;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin{
    13. public void onEnable(){
    14. Bukkit.getServer().getPluginManager().registerEvents(new Events(), this);
    15. ItemStack stick = new ItemStack(Material.STICK, 1);
    16. ItemMeta meta = stick.getItemMeta();
    17. meta.setDisplayName("Bazooka");
    18. ArrayList<String> lore = new ArrayList<String>();
    19. lore.add("This is a bazooka!");
    20. lore.add("BLOW 'EM UP!");
    21. meta.setLore(lore);
    22. stick.setItemMeta(meta);
    23. ShapedRecipe Bazooka = new ShapedRecipe(stick);
    24. Bazooka.shape(new String[] {"c","i","i"}).setIngredient('i', Material.IRON_INGOT).setIngredient('c', Material.COBBLESTONE);
    25. Bukkit.getServer().addRecipe(Bazooka);
    26.  
    27. ItemStack hopper = new ItemStack(Material.HOPPER, 1);
    28. ItemMeta meta1 = hopper.getItemMeta();
    29. meta1.setDisplayName("Grenade_Launcher");
    30. ArrayList<String> lore1 = new ArrayList<String>();
    31. lore1.add("This is a grenade launcher");
    32. lore1.add("FIRE IN THE HOLE!");
    33. meta1.setLore(lore1);
    34. hopper.setItemMeta(meta1);
    35. ShapedRecipe GrenadeLauncher = new ShapedRecipe(hopper);
    36. GrenadeLauncher.shape(new String[] {"c","b","s"}).setIngredient('s', Material.STICK).setIngredient('c', Material.COBBLESTONE).setIngredient('b', Material.BUCKET);
    37. Bukkit.getServer().addRecipe(GrenadeLauncher);
    38.  
    39. ItemStack dispenser = new ItemStack(Material.DISPENSER, 1);
    40. ItemMeta meta2 = dispenser.getItemMeta();
    41. meta2.setDisplayName("Nuke_Launcher");
    42. ArrayList<String> lore2 = new ArrayList<String>();
    43. lore2.add("This is a nuke launcher");
    44. lore2.add("HEAVEY DAMAGE! MAY CRASH SERVER");
    45. meta2.setLore(lore2);
    46. hopper.setItemMeta(meta2);
    47. ShapedRecipe NukeLauncher = new ShapedRecipe(dispenser);
    48. NukeLauncher.shape(new String[] {"c","g","c"}).setIngredient('g', Material.CACTUS).setIngredient('c', Material.COBBLESTONE);
    49. Bukkit.getServer().addRecipe(NukeLauncher);
    50.  
    51. ItemStack iron_ingot = new ItemStack(Material.IRON_INGOT);
    52. ItemMeta meta3 = iron_ingot.getItemMeta();
    53. meta3.setDisplayName("Rocket_Shell");
    54. ArrayList<String> lore3 = new ArrayList<String>();
    55. lore3.add("Important material!");
    56. meta3.setLore(lore3);
    57. iron_ingot.setItemMeta(meta3);
    58. ShapedRecipe RocketMetal = new ShapedRecipe(iron_ingot);
    59. RocketMetal.shape(new String[] { "i,g,i","i,s,i","i,g,i"}).setIngredient('i', Material.IRON_INGOT).setIngredient('g', Material.GOLD_INGOT).setIngredient('s', Material.STONE);
    60. Bukkit.getServer().addRecipe(RocketMetal);
    61. }
    62.  
    63. }
    64.  

    Listener:
    Code:java
    1. package thebawsgamer.projectiles;
    2.  
    3. import org.bukkit.Effect;
    4. import org.bukkit.entity.Egg;
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.Fireball;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.entity.Projectile;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.entity.ProjectileHitEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.potion.PotionEffect;
    15. import org.bukkit.potion.PotionEffectType;
    16.  
    17. public class Events implements Listener {
    18. @EventHandler
    19. public void onPlayerInteract(final PlayerInteractEvent a) {
    20. if(!(a.getAction() == Action.RIGHT_CLICK_AIR)) return;
    21. if(a.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Bazooka")){
    22. Fireball a1 = a.getPlayer().launchProjectile(Fireball.class);
    23. a1.getWorld().playEffect(a.getPlayer().getLocation(), Effect.SMOKE,10);
    24. }
    25. }
    26. @SuppressWarnings("deprecation")
    27. @EventHandler
    28. public void onProjectileHit(ProjectileHitEvent a) {
    29. Projectile p = a.getEntity();
    30. if(!(p instanceof Fireball)) return;
    31. Fireball a1 = (Fireball) p;
    32. a1.getWorld().createExplosion(a1.getLocation(), 5.0F);
    33. for(Entity en : a1.getNearbyEntities(5, 30, 5)) {
    34. if(en instanceof Player) {
    35. Player pl = (Player) en;
    36. if(!(pl == a.getEntity().getShooter())) pl.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 0));
    37. }
    38. }
    39. }
    40. @EventHandler
    41. public void onPlayerInteract1(final PlayerInteractEvent b) {
    42. if(!(b.getAction() == Action.RIGHT_CLICK_AIR)) return;
    43. if(b.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Grenade_Launcher")){
    44. Egg b1 = b.getPlayer().launchProjectile(Egg.class);
    45. b1.getWorld().playEffect(b.getPlayer().getLocation(), Effect.SMOKE,10);
    46. }
    47. }
    48. @SuppressWarnings("deprecation")
    49. @EventHandler
    50. public void onProjectileHit1(ProjectileHitEvent b) {
    51. Projectile p = b.getEntity();
    52. if(!(p instanceof Egg)) return;
    53. Egg b1 = (Egg) p;
    54. b1.getWorld().createExplosion(b1.getLocation(), 5.0F);
    55. for(Entity en : b1.getNearbyEntities(5, 30, 5)) {
    56. if(en instanceof Player) {
    57. Player pl = (Player) en;
    58. if(!(pl == b.getEntity().getShooter())) pl.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 0));
    59. }
    60. }
    61. }
    62.  
    63. @EventHandler
    64. public void onPlayerInteract2(final PlayerInteractEvent c) {
    65. if(c.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Nuke_Launcher")){
    66. if(!(c.getAction() == Action.RIGHT_CLICK_AIR)) return;
    67. Fireball c1 = c.getPlayer().launchProjectile(Fireball.class);
    68. c1.getWorld().playEffect(c.getPlayer().getLocation(), Effect.SMOKE,10);
    69. }
    70. }
    71. @SuppressWarnings("deprecation")
    72. @EventHandler
    73. public void onProjectileHit2(ProjectileHitEvent c) {
    74. Projectile p = c.getEntity();
    75. if(!(p instanceof Fireball)) return;
    76. Fireball c1 = (Fireball) p;
    77. c1.getWorld().createExplosion(c1.getLocation(), 100.0F);
    78. for(Entity en : c1.getNearbyEntities(5, 30, 5)) {
    79. if(en instanceof Player) {
    80. Player pl = (Player) en;
    81. if(!(pl == c.getEntity().getShooter())) pl.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 0));
    82. }
    83. }
    84. }
    85. }
     
  11. Offline

    hankered

    No its not. use Integer.MAX_INTEGER
     
  12. Offline

    MrDplugins

    @negative_codezZ True this is a simple tutorial, why don't you add a reloading system and ammo consumption
    and maybe attachments!
     
  13. Offline

    gabe4356

    How would you remove the explosion block damage?
     
Thread Status:
Not open for further replies.

Share This Page