|
So a little while ago i made this: http://www.rune-server.org/runescape...i-copy-pi.html
This is what you're adding:
Now that i have started my woodcutting base on my server i have made a better birds nests class. than my other class - First make a new class called BirdsNests.java and add all this in it You will need to change the impot of your client and the package location
Code:package org.rs2server.entity.players.skills.woodcutting; import java.util.Random; import org.rs2server.Server; import org.rs2server.entity.players.Client; /** * This will handle the opening of the birds nests and * it will handle dropping the birds nest * @author Zack/optimum * */ public class BirdsNests { /** * This will randomly generate a percentage */ private static Random rnd = new Random(); /** * This contains all of the nest item ids. */ private static final int[] NESTS = { 5070, 5071, 5072, 5073, 5074, 5075 }; /** * This holds all the ring data: ItemId, Percentage */ private static final int[][] RINGS = { {1635, 35}, {1637, 75}, {1639, 90}, {1641, 99}, {1643, 100} }; /** * This holds all the seeds data: ItemId, Percentage */ private static final int[][] SEEDS = { {5317, 1}, {5290, 3}, {5289, 5}, {5288, 9}, {5287, 13}, {5286, 19}, {5285, 28}, {5284, 38}, {5283, 54}, {5316, 55}, {5315, 58}, {5314, 64}, {5313, 79}, {5312, 100}, }; /** * This method will check if the item being clicked is * a nest. * @param itemId - Is the item being clicked * @return if the itemIf is a nest */ public static boolean isNest(int itemId) { for(int i : NESTS) { if(i == itemId) { return true; } } return false; } /** * This handles the opening of a birds nest * @param player * @param itemId - this is the item id thats being clicked */ public static void handleOpen(Client player, int itemId) { if(player.getItems().freeSlots() < 1){ player.sendMessage("You need atleast 1 free inventory space to open this!"); return; } switch(itemId) { case 5073: openSeedNest(player); player.getItems().deleteItem(itemId, 1); player.getItems().addItem(5075, 1); return; case 5074: openRingNest(player); player.getItems().deleteItem(itemId, 1); player.getItems().addItem(5075, 1); return; case 5070: case 5071: case 5072: player.getItems().deleteItem(itemId, 1); player.getItems().addItem(itemId + 6, 1); player.getItems().addItem(5075, 1); return; } } /** * This opens the Seed Nests and gives the player * a random seed item based on the seed percentage. * @param player */ private static void openSeedNest(Client player) { int random = 1 + rnd.nextInt(100); for(int i = 0; i < SEEDS.length; i++) { if(random <= SEEDS[i][1]) { player.getItems().addItem(SEEDS[i][0], 1); return; } } } /** * This opens the Ring Nests and gives the player * a random ring item based on the ring percentage. * @param player */ private static void openRingNest(Client player) { int random = 1 + rnd.nextInt(100); for(int i = 0; i < RINGS.length; i++) { if(random <= RINGS[i][1]) { player.getItems().addItem(RINGS[i][0], 1); return; } } } /** * This method drops a birds nest right at a players feet * at a chance of 500 */ public static void dropNest(Client player) { if(rnd.nextInt(500) == 0) { Server.itemHandler.createGroundItem( player, NESTS[rnd.nextInt(NESTS.length)], player.getX(), player.getY(), 1, player.playerId); } } }
open up the class ClickItem and go to this method - processPacket add this:
Thats you done. A thanks would be appretiated. Constructive critisism is welcome. Feel free to use the rep buttonCode:if(BirdsNests.isNest(itemId)){ BirdsNests.handleOpen(c, itemId); return; }
Also if i have missed anything please tell me
Nice, much more organized than I did it
All in all it's a decent release. If I was to be critical I would say that you could make some modifications for code reusability (though very minimal).
Also, by convention, a constant is static final.
Why are you instantiating the class?
My errors..
src\server\content\BirdsNests.java.java:12: error: class BirdsNests is public, s
hould be declared in a file named BirdsNests.java
public class BirdsNests {
^
src\server\content\BirdsNests.java.java:5: error: cannot find symbol
import org.rs2server.Server;
^
symbol: class Server
location: package org.rs2server
src\server\content\BirdsNests.java.java:6: error: cannot find symbol
import org.rs2server.entity.players.Client;
^
symbol: class Client
location: package org.rs2server.entity.players
src\server\content\BirdsNests.java.java:62: error: cannot find symbol
public void handleOpen(Client player, int itemId) {
^
symbol: class Client
location: class BirdsNests
src\server\content\BirdsNests.java.java:93: error: cannot find symbol
void openSeedNest(Client player) {
^
symbol: class Client
location: class BirdsNests
src\server\content\BirdsNests.java.java:108: error: cannot find symbol
void openRingNest(Client player) {
^
symbol: class Client
location: class BirdsNests
src\server\content\BirdsNests.java.java:122: error: cannot find symbol
public void dropNest(Client player) {
^
symbol: class Client
location: class BirdsNests
src\server\model\players\packets\ClickItem.java:58 : error: cannot find symbol
BirdsNests nest = new BirdsNests();
^
symbol: class BirdsNests
location: class ClickItem
src\server\model\players\packets\ClickItem.java:58 : error: cannot find symbol
BirdsNests nest = new BirdsNests();
^
symbol: class BirdsNests
location: class ClickItem
src\server\model\players\packets\Commands.java:104 1: error: cannot find symbol
for (Player client : PlayerHandler.players) {
^
symbol: class Player
location: class Commands
src\server\content\BirdsNests.java.java:124: error: package Server does not exis
t
Server.itemHandler.createGroundItem(
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors
Press any key to continue . . .
Dont hate, just tell what i did wrong. :L
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |