Hey guys,today i bring you my simple gun code:Features: the way it is coded allows you to make different weapons and let them do different amounts of damage Also it allows you to use any items with a few changes Also i have added a anti spam List so that you cant just keep left-clicking, to let them shoot faster just simply change the 30L Furture features: reloading system possibly scopes Hope you enjoy Code:java List<String> recentlyFired = new ArrayList<String>();public void onEnable(){this.server = getServer();PluginManager pm = getServer().getPluginManager();pm.registerEvents(this, this);getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {public void run(){recentlyFired.clear();} }, 0L, 30L);}@EventHandler(priority = EventPriority.HIGHEST)public void onDamage(EntityDamageByEntityEvent e){if(e.getCause().equals(DamageCause.PROJECTILE)){if(e.getDamager().hasMetadata("shotfrom")){String shotFrom = e.getDamager().getMetadata("shotfrom").get(0).asString();if(shotFrom.equalsIgnoreCase("pistol")){if(e.getEntity() instanceof Player){Player player = (Player) e.getEntity();// example of using 'bullet proof vests'if(player.getEquipment().getChestplate().getType() == Material.LEATHER_CHESTPLATE){e.setDamage(5);}else if(player.getEquipment().getChestplate().getType() == Material.IRON_CHESTPLATE){e.setDamage(3);}else if(player.getEquipment().getChestplate().getType() == Material.GOLD_CHESTPLATE){e.setDamage(2);}else{e.setDamage(6);}}else{e.setDamage(6);}}}} } //begin interact event@EventHandlerpublic void onInteract(final PlayerInteractEvent e){Player player = e.getPlayer();final PlayerInventory inventory = player.getInventory();if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK){ if(inventory.contains(Material.GLOWSTONE_DUST)){if(e.getPlayer().getItemInHand().getType() == Material.WOOD_HOE){if(!recentlyFired.contains(player.getName())){ItemStack item = new ItemStack(Material.GLOWSTONE_DUST, 1);ItemMeta reName = item.getItemMeta();reName.setDisplayName(ChatColor.RESET + "Ammo");List<String> lore = new ArrayList<String>();lore.add(ChatColor.RESET + "For use on:");lore.add(ChatColor.RESET + "- 9mm");reName.setLore(lore);item.setItemMeta(reName); Arrow arrow = (Arrow)player.launchProjectile(Arrow.class);arrow.setVelocity(arrow.getVelocity().multiply(3));arrow.setShooter(player);arrow.setMetadata("shotfrom", new FixedMetadataValue(this, "pistol"));recentlyFired.add(player.getName());inventory.removeItem(item);}}}
Im sorry, xD i was from iPhone and i couldn't undestand you. Thx. So i understand Arrows work, can you make one for snowballs too? i can't find out how to do those.
I really would like you to add Reloading system. Scopes would be simple, just add slowness when player left clicks with gun in hand.
Some people probably do not want to take the time to learn how to. Maybe they are just too lazy to do it and copy and paste everything. Which means, they should not be on the Bukkit Forums.
People who are currently learning Java (like me) can stay. You don't have to force them to leave just because they don't know something. I do agree he should start learning instead of copying and pasting, but sometimes there are things you wont find anywhere else. So he could just ask a friend or someone on the forums for SOME help (not all). Even I used to copy and paste code from people so I could read it and message them on what it means. People learn differently, so please respect them. -Don't tell me to give you an example lol
This is the huge flaw with Resources. Some people think that it is a free for all spoon feed session (which it is - I admittedly have done it myself), but I now realize that you need to show people the way to do it, not do it for them (yes, back to class everyone, we all know this rule regarding our parents ) Developerjohn
No, I'm just saying you should learn Java first before tackling Bukkit. If you try to learn Bukkit without knowing Java, you are going to have a very hard time learning it.
Deckerz I have two problems with your bit of code. 1. The formatting. 2. Code:java getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { recentlyFired.clear(); } } , 0L, 30L);} Repeating tasks are generally red flags unless done right. Having a repeating task like that isn't very efficient.