Thread: [PI] woodcutting help

Results 1 to 6 of 6
  1. #1 [PI] woodcutting help 
    Registered Member
    Join Date
    Nov 2011
    Posts
    276
    Thanks given
    60
    Thanks received
    5
    Rep Power
    22
    when woodcutting everything works, cut down tree, stump appears etc except for when 2+ people are cutting the same tree.
    when 2+ are cutting the tree someone cuts it down and stops woodcutting, while the rest will continue to cut at the stump.

    here is what i have, and i have marked where the check would go in larger red font to see if the tree still exists, but i have had no luck using any of the "objectExists" methods to check if it is still there.

    any help on stopping the player from woodcutting if the id at the x and y coords of where the tree was at would be much appreciated, thanks

    also tips/help improving any other parts would also be appreciated

    Code:
    package AbyssalScape.rs2.content.skills;
    
    import AbyssalScape.Server;
    import AbyssalScape.core.event.CycleEvent;
    import AbyssalScape.core.event.CycleEventContainer;
    import AbyssalScape.core.event.CycleEventHandler;
    import AbyssalScape.rs2.objects.Objects;
    import AbyssalScape.rs2.players.Player;
    import AbyssalScape.rs2.players.PlayerAssistant;
    import AbyssalScape.util.Misc;
    
    public class Woodcutting {
    
    	//variables
    	private Player p;
    	
    	//axe id, level req, anim, strength
    	private static final int[][] AXES = {
    		{1351, 1, 879, 1}, //bronze axe
    		{1349, 1, 877, 2}, //iron axe
    		{1353, 6, 875, 3}, //steel axe
    		{1361, 6, 873, 4}, //black axe
    		{1355, 21, 871, 5}, //mithril axe
    		{1357, 31, 869, 6}, //adamant axe
    		{1359, 41, 867, 7}, //rune axe
    	    {6739, 61, 2846, 10} //dragon axe
    	}; //end of axes
    	
    	//tree id, stump id, level req, xp given, log id, respawn time, tree strength, max amount of logs
    	private static final int[][] TREES = {
    		{1276, 1342, 1, 25, 1511, 30, 4, 1}, //Tree
    		{1278, 1342, 1, 25, 1511, 30, 4, 1}, //Tree
    		{1286, 1342, 1, 25, 1511, 30, 4, 1}, //Dead Tree
    		{1383, 1342, 1, 25, 1511, 30, 4, 1}, //Dead Tree
    		{1281, 1356, 15, 38, 1521, 45, 15, 5}, //Oak
    		{1308, 7399, 30, 68, 1519, 50, 35, 15}, //Willow
    		{5552, 7399, 30, 68, 1519, 50, 35, 15}, //Willow
    		{5551, 7399, 30, 68, 1519, 50, 35, 15}, //Willow
    		{5553, 7399, 30, 68, 1519, 50, 35, 15}, //Willow
    		{1307, 1343, 45, 100, 1517, 65, 50, 20}, //Maple
    		{1309, 7402, 60, 175, 1515, 100, 70, 28}, //Yew
    		{1306, 7401, 75, 250, 1513, 200, 85, 28} //Magic
    	}; //end of trees
    			
    	//constructors
    	public Woodcutting(Player p) {
    		this.p = p;
    	}
    	
    	
    	
    	//getters and setters
    	
    	//methods	
    	public void startWoodcutting(final int treeId, final int treeX, final int treeY) {
    		p.turnPlayerTo(treeX, treeY); //turn the player so they are facing the tree
    		if (p.ed.getBoolean("isSkilling") == true) {
    			return;
    		}
    		short treeIndex = 0; //the index in which the tree we are cutting sits
    		for (short i = 0; i < TREES.length; i++) {
    			if (treeId == TREES[i][0]) {
    				treeIndex = i;
    				break;
    			}
    		} //end of for loop
    		if (!(p.playerLevel[8] >= TREES[treeIndex][2])) { //check if they have the proper level
    			p.sendMessage("You need atleast a woodcutting level of " + TREES[treeIndex][2] + "to cut this tree.");
    			return;
    		} //end of level check
    		boolean canCutTree = false;
    		short axeIndex = 0;
    		for (short i = 0; i < AXES.length; i++) {
    			if (p.getItems().playerHasItem(AXES[i][0]) || p.playerEquipment[p.playerWeapon] == AXES[i][0] && p.playerLevel[8] >= AXES[i][1]) {
    				axeIndex = i;
    				canCutTree = true;
    			} //end of if statement
    		} //end of for loop
    		if (!canCutTree) {
    			p.sendMessage("You need a Woodcutting axe which you need a Woodcutting level to use.");
    			return;
    		} //end of checking if they have an axe they can use
    		if (p.getItems().freeSlots() < 1) {
    			p.sendMessage("You do not have enough inventory slots to do that.");
    			return;
    		} //end of checking if the player has an inventory slot open
    		p.startAnimation(AXES[axeIndex][2]);
    		final short treeSpot = treeIndex;
    		final short axeSpot = axeIndex;
    		p.sendMessage("You swing your axe at the tree.");
    		p.ed.put("isSkilling", true); //add the boolean isSkilling to the extra data
    		CycleEventHandler.getSingleton().addEvent(1, p, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer container) {
    				if (p.ed.getBoolean("isSkilling") == true) { //need to check here if the tree is still avaible
    					p.startAnimation(AXES[axeSpot][2]);
    					int logsToGive = (TREES[treeSpot][7] == 1 ? 1 : Misc.random(TREES[treeSpot][7]));
    					int xp = TREES[treeSpot][3];
    					if (p.playerEquipment[p.playerHat] == 10941) {
    						xp = (int)(xp * 1.004);
    					}
    					if (p.playerEquipment[p.playerFeet] == 10933) {
    						xp = (int)(xp * 1.002);
    					}
    					if (p.playerEquipment[p.playerChest] == 10939) {
    						xp = (int)(xp * 1.008);
    					}
    					if (p.playerEquipment[p.playerLegs] == 10940) {
    						xp = (int)(xp * 1.006);
    					}
    					if (p.getItems().freeSlots() < 1) {
    						p.sendMessage("You have ran out of inventory slots.");
    						container.stop();
    					} //end of checking if the player has an inventory slot open
    					if (Misc.random(100) == 25 && p.membership) 
    						giveBirdsNest();
    					p.getItems().addItem(TREES[treeSpot][4], 1);
    					p.sendMessage("You cut some logs.");
    					PlayerAssistant.addSkillXP(p, xp, 8);
    					logsToGive--;
    					if (logsToGive == 0) {
    						createStump(p, TREES[treeSpot][1], TREES[treeSpot][0], treeX, treeY, Misc.random(TREES[treeSpot][5] + 3));
    						container.stop();
    					}
    				} else {
    					container.stop();
    				}
    			}
    			@Override
    			public void stop() {
    				p.startAnimation(65535);
    				PlayerAssistant.removeAllWindows(p);
    				p.ed.remove("isSkilling");
    			}
    		}, getTimer(treeIndex, axeIndex, p.playerLevel[8]));
    		
    	} //end of startWoodcutting
    	
    	private static void createStump(final Player p, final int stumpId, final int objId, final int objX, final int objY, int ticks) {
    		Server.objectHandler.createAnObject(p, stumpId, objX, objY);
    		CycleEventHandler.getSingleton().addEvent(p, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer container) {
    				Server.objectHandler.createAnObject(p, objId, objX, objY);
    				container.stop();
    			}
    			@Override
    			public void stop() {
    				// Whatever you want it to do when the event stops
    			}
    		}, ticks);
    	}
    	
    	private int getTimer(int tree, int axe, int level) {
    		double timer = (int)((TREES[tree][6]  * 2) + 20 + Misc.random(20))-((AXES[axe][3] * (AXES[axe][3] * 0.75)) + level);
    		if (timer < 3.0) {
    			return 3;
    		} else {
    			return (int)timer;
    		}
    	}
    	
    	private void giveBirdsNest() { //need to finish this method
    		p.sendMessage("@red@A bird's nest falls from the tree!");		
    		//when a player receives a birds nest
    	}
    	
    } //end of class
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Nov 2011
    Posts
    276
    Thanks given
    60
    Thanks received
    5
    Rep Power
    22
    bump. i've been stuck on this for awhile :/
    Reply With Quote  
     

  3. #3  
    Registered Member
    Karma_K's Avatar
    Join Date
    Nov 2012
    Posts
    4,283
    Thanks given
    152
    Thanks received
    610
    Rep Power
    108
    Could try calling the stopSkilling or whatever boolean when the tree is replaced with the stump.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Nov 2011
    Posts
    276
    Thanks given
    60
    Thanks received
    5
    Rep Power
    22
    Quote Originally Posted by Karma_K View Post
    Could try calling the stopSkilling or whatever boolean when the tree is replaced with the stump.
    that would stop it for the person who gets the last log, which it already does, it wouldn't stop the rest of the players cutting that specific tree
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2011
    Posts
    276
    Thanks given
    60
    Thanks received
    5
    Rep Power
    22
    bump - need help checking if the object still exists :/
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Nov 2011
    Posts
    276
    Thanks given
    60
    Thanks received
    5
    Rep Power
    22
    bump
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Woodcutting Help Again
    By Ired in forum Help
    Replies: 8
    Last Post: 06-08-2013, 08:16 PM
  2. [PI] Woodcutting Help
    By Ired in forum Help
    Replies: 7
    Last Post: 06-06-2013, 08:27 PM
  3. [PI] Woodcutting help
    By mc wobbla in forum Help
    Replies: 2
    Last Post: 12-06-2012, 02:47 AM
  4. [PI] Woodcutting help
    By mc wobbla in forum Help
    Replies: 0
    Last Post: 12-06-2012, 01:34 AM
  5. PI woodcutting help
    By corndogs in forum Help
    Replies: 1
    Last Post: 07-01-2012, 01:24 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •