Thread: I would really appreciate some help with Evil Trees please

Results 1 to 5 of 5
  1. #1 I would really appreciate some help with Evil Trees please 
    Registered Member
    Join Date
    Jun 2017
    Posts
    27
    Thanks given
    1
    Thanks received
    2
    Rep Power
    11
    Hello guys

    I'm a bit of a newbie when it comes to coding on RSPS.

    I was wondering if someone could help me out with a problem i'm facing.

    Basically, I have an EvilTree.java file. Everything works fine in game. It spawns every 40 minutes as it should, however you can't actually cut the tree.

    The model it's using is 11434. I tried with the other 2 models and it does the same thing and doesn't cut.

    Please find the code i'm using below:

    Code:
    package com.ruseps.world.content;
    
    import com.ruseps.model.Animation;
    import com.ruseps.model.GameObject;
    import com.ruseps.model.Position;
    import com.ruseps.util.Misc;
    import com.ruseps.util.Stopwatch;
    import com.ruseps.world.World;
    import com.ruseps.world.entity.impl.player.Player;
    
    	/** Evil Tree's Spawning every 40 minutes **/
    	/*@author Falador
    	 */
    
    	/*
    	 * Evil Trees
    	 * Object id: 11434
    	 */
    
    public class EvilTrees {
    	
    
    	private static final int TIME = 30; //40 minutes? not sure lol
    	public static final int MAX_CUT_AMOUNT = 500;//Amount of logs the tree will give before
    											//despawning
    
    	public static Stopwatch timer = new Stopwatch().reset();
    	public static EvilTree SPAWNED_TREE = null;
    	public static LocationData LAST_LOCATION = null;
    
    	public static class EvilTree {
    
    		public EvilTree(GameObject treeObject, LocationData treeLocation) {
    			this.treeObject = treeObject;
    			this.treeLocation = treeLocation;
    		}
    
    		private GameObject treeObject;
    		private LocationData treeLocation;
    
    		public GameObject getTreeObject() {
    			return treeObject;
    		}
    
    		public LocationData getTreeLocation() {
    			return treeLocation;
    		}
    	}
    
    	/**
    	 * Holds the location data in an enum for where the treee's will spawn
    	 */
    	public static enum LocationData {
    
    		LOCATION_1(new Position(3052, 3516), "Outside of the monastery", "Monastery"),
    		LOCATION_2(new Position(3093, 3535), "In the wilderness (Level 2)", "Wilderness"),
    		LOCATION_3(new Position(2470, 5166), "Somewhere in the Tzhaar-Dungeon", "TzHaar dungeon"), 
    		LOCATION_4(new Position(3321, 3238), "In the Duel Arena", "Duel Arena"), 
    		LOCATION_5(new Position(2928, 3453), "In the taverley entrance", "Taverley"),
    		LOCATION_6(new Position(2782, 3483), "East of Camelot castle", "Camelot"),
    		LOCATION_7(new Position(2994, 3376), "In the Falador Garden", "Falador"), 
    		LOCATION_8(new Position(3212, 3423), "Varrock square", "Varrock");
    
    		private LocationData(Position spawnPos, String clue, String playerPanelFrame) {
    			this.spawnPos = spawnPos;
    			this.clue = clue;
    			this.playerPanelFrame = playerPanelFrame;
    		}
    
    		private Position spawnPos;
    		private String clue;
    		public String playerPanelFrame;
    	}
    
    	public static LocationData getRandom() {
    		LocationData tree = LocationData.values()[Misc.getRandom(LocationData.values().length - 1)];
    		return tree;
    	}
    /*
     * Sequences the spawning so you don't have the same location back to back
     * 
     */
    	public static void sequence() {
    		if (SPAWNED_TREE == null) {
    			if (timer.elapsed(TIME)) {
    				LocationData locationData = getRandom();
    				if (LAST_LOCATION != null) {
    					if (locationData == LAST_LOCATION) {
    						locationData = getRandom();
    					}
    				}
    				LAST_LOCATION = locationData;
    				SPAWNED_TREE = new EvilTree(new GameObject(11434, locationData.spawnPos), locationData);
    				CustomObjects.spawnGlobalObject(SPAWNED_TREE.treeObject);
    				World.sendMessage("<img=10> @blu@[Evil Tree]@bla@ The Evil Tree has sprouted " + locationData.clue + "!");
    				timer.reset();
    			}
    		} else {
    			if (SPAWNED_TREE.treeObject.getCutAmount() >= MAX_CUT_AMOUNT) {
    				despawn(false);
    				timer.reset();
    			}
    		}
    	}
    
    	/**
    	 * Handles the despawning of the tree and resets the timer
    	 */
    	public static void despawn(boolean respawn) {
    		if (respawn) {
    			timer.reset(0);
    		} else {
    			timer.reset();
    		}
    		if (SPAWNED_TREE != null) {
    			for (Player p : World.getPlayers()) {
    				if (p == null) {
    					continue;
    				}
    				if (p.getInteractingObject() != null && p.getInteractingObject().getId() == SPAWNED_TREE.treeObject.getId()) {
    					p.performAnimation(new Animation(65535));
    					p.getPacketSender().sendClientRightClickRemoval();
    					p.getSkillManager().stopSkilling();
    					p.getPacketSender().sendMessage("@blu@[EVIL TREES]@bla@The Evil Tree has been chopped down");
    				}
    			}
    			CustomObjects.deleteGlobalObject(SPAWNED_TREE.treeObject);
    			SPAWNED_TREE = null;
    		}
    	}
    	
    	public static LocationData getLocation() {
    		return LAST_LOCATION;
    	}
    }
    Again, it'll most probably be dead obvious to some legends on here, but for a newbie, it's a bit of a mystery!

    If you need me to provide anything else, please let me know.

    Thank you in advance!
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    theres no code here for actually cutting the tree
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2017
    Posts
    27
    Thanks given
    1
    Thanks received
    2
    Rep Power
    11
    Quote Originally Posted by Stuart View Post
    theres no code here for actually cutting the tree
    Please find the woodcutting code below:

    Woodcutting.java

    Code:
    package com.ruseps.world.content.skill.impl.woodcutting;
    
    import com.ruseps.engine.task.Task;
    import com.ruseps.engine.task.TaskManager;
    import com.ruseps.model.Animation;
    import com.ruseps.model.GameObject;
    import com.ruseps.model.Skill;
    import com.ruseps.model.container.impl.Equipment;
    import com.ruseps.util.Misc;
    import com.ruseps.world.content.Achievements;
    import com.ruseps.world.content.CustomObjects;
    import com.ruseps.world.content.EvilTrees;
    import com.ruseps.world.content.Sounds;
    import com.ruseps.world.content.Achievements.AchievementData;
    import com.ruseps.world.content.Sounds.Sound;
    import com.ruseps.world.content.skill.impl.firemaking.Logdata;
    import com.ruseps.world.content.skill.impl.firemaking.Logdata.logData;
    import com.ruseps.world.content.skill.impl.woodcutting.WoodcuttingData.Hatchet;
    import com.ruseps.world.content.skill.impl.woodcutting.WoodcuttingData.Trees;
    import com.ruseps.world.entity.impl.player.Player;
    
    public class Woodcutting {
    
    	public static void cutWood(final Player player, final GameObject object, boolean restarting) {
    		if(!restarting)
    			player.getSkillManager().stopSkilling();
    		if(player.getInventory().getFreeSlots() == 0) {
    			player.getPacketSender().sendMessage("You don't have enough free inventory space.");
    			return;
    		}
    		player.setPositionToFace(object.getPosition());
    		final int objId = object.getId();
    		final Hatchet h = Hatchet.forId(WoodcuttingData.getHatchet(player));
    		if (h != null) {
    			if (player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= h.getRequiredLevel()) {
    				final WoodcuttingData.Trees t = WoodcuttingData.Trees.forId(objId);
    				if (t != null) {
    					player.setEntityInteraction(object);
    					if (player.getSkillManager().getCurrentLevel(Skill.WOODCUTTING) >= t.getReq()) {
    						player.performAnimation(new Animation(h.getAnim()));
    						int delay = Misc.getRandom(t.getTicks() - WoodcuttingData.getChopTimer(player, h)) +1;
    						player.setCurrentTask(new Task(1, player, false) {
    							int cycle = 0, reqCycle = delay >= 2 ? delay : Misc.getRandom(1) + 1;
    							@Override
    							public void execute() {
    								if(player.getInventory().getFreeSlots() == 0) {
    									player.performAnimation(new Animation(65535));
    									player.getPacketSender().sendMessage("You don't have enough free inventory space.");
    									this.stop();
    									return;
    								}
    								if (cycle != reqCycle) {
    									cycle++;
    									player.performAnimation(new Animation(h.getAnim()));
    								} else if (cycle >= reqCycle) {
    									int xp = t.getXp();
    									if(lumberJack(player))
    										xp *= 1.5;
    									player.getSkillManager().addExperience(Skill.WOODCUTTING, xp);
    									cycle = 0;
    									BirdNests.dropNest(player);
    									this.stop();
    									if (object.getId() == 11434) {
    										if (EvilTrees.SPAWNED_TREE == null || EvilTrees.SPAWNED_TREE.getTreeObject().getCutAmount() >= EvilTrees.MAX_CUT_AMOUNT) {
    											player.getPacketSender().sendClientRightClickRemoval();
    											player.getSkillManager().stopSkilling();
    											return;
    										} else {
    											EvilTrees.SPAWNED_TREE.getTreeObject().incrementCutAmount();
    										}
    									//} else {
    										//player.performAnimation(new Animation(65535));
    									}
    									if (!t.isMulti() || Misc.getRandom(10) == 2) {
    										treeRespawn(player, object);
    										player.getPacketSender().sendMessage("You've chopped the tree down.");
    										player.performAnimation(new Animation(65535));
    										player.setSkillPoints(player.getSkillPoints() + 1);
    										player.sendMessage("<img=10>You now have @red@" + player.getSkillPoints() + " Skilling Points!");
    									} else {
    										cutWood(player, object, true);
    										player.getPacketSender().sendMessage("You get some logs..");
    										player.setSkillPoints(player.getSkillPoints() + 1);
    										player.sendMessage("<img=10>You now have @red@" + player.getSkillPoints() + " Skilling Points!");
    									}
    									Sounds.sendSound(player, Sound.WOODCUT);
    									if(!(infernoAdze(player) && Misc.getRandom(5) <= 2)) {
    										player.getInventory().add(t.getReward(), 1);
    									} else if(Misc.getRandom(5) <= 2) {
    										logData fmLog = Logdata.getLogData(player, t.getReward());
    										if(fmLog != null) {
    											player.getSkillManager().addExperience(Skill.FIREMAKING, fmLog.getXp());
    											player.getPacketSender().sendMessage("Your Inferno Adze burns the log, granting you Firemaking experience.");
    											if(fmLog == Logdata.logData.OAK) {
    												Achievements.finishAchievement(player, AchievementData.BURN_AN_OAK_LOG);
    											} else if(fmLog == Logdata.logData.MAGIC) {
    												Achievements.doProgress(player, AchievementData.BURN_100_MAGIC_LOGS);
    												Achievements.doProgress(player, AchievementData.BURN_2500_MAGIC_LOGS);
    											}
    										}
    									}
    									if(t == Trees.OAK) {
    										Achievements.finishAchievement(player, AchievementData.CUT_AN_OAK_TREE);
    									} else if(t == Trees.MAGIC) {
    										Achievements.doProgress(player, AchievementData.CUT_100_MAGIC_LOGS);
    										Achievements.doProgress(player, AchievementData.CUT_5000_MAGIC_LOGS);
    									}
    								}
    							}
    						});
    						TaskManager.submit(player.getCurrentTask());
    					} else {
    						player.getPacketSender().sendMessage("You need a Woodcutting level of at least "+t.getReq()+" to cut this tree.");
    					}
    				}
    			} else {
    				player.getPacketSender().sendMessage("You do not have a hatchet which you have the required Woodcutting level to use.");
    			}
    		} else {
    			player.getPacketSender().sendMessage("You do not have a hatchet that you can use.");
    		}
    	}
    	
    	public static boolean lumberJack(Player player) {
    		return player.getEquipment().get(Equipment.HEAD_SLOT).getId() == 10941 && player.getEquipment().get(Equipment.BODY_SLOT).getId() == 10939 && player.getEquipment().get(Equipment.LEG_SLOT).getId() == 10940 && player.getEquipment().get(Equipment.FEET_SLOT).getId() == 10933; 
    	}
    	
    	public static boolean infernoAdze(Player player) {
    		return player.getEquipment().get(Equipment.WEAPON_SLOT).getId() == 13661;
    	}
    
    	public static void treeRespawn(final Player player, final GameObject oldTree) {
    		if(oldTree == null || oldTree.getPickAmount() >= 1)
    			return;
    		oldTree.setPickAmount(1);
    		for(Player players : player.getLocalPlayers()) {
    			if(players == null)
    				continue;
    			if(players.getInteractingObject() != null && players.getInteractingObject().getPosition().equals(player.getInteractingObject().getPosition().copy())) {
    				players.getSkillManager().stopSkilling();
    				players.getPacketSender().sendClientRightClickRemoval();
    			}
    		}
    		player.getPacketSender().sendClientRightClickRemoval();
    		player.getSkillManager().stopSkilling();
    		CustomObjects.globalObjectRespawnTask(new GameObject(1343, oldTree.getPosition().copy(), 10, 0), oldTree, 20 + Misc.getRandom(10));
    	}
    
    }


    WoodcuttingData.java

    Code:
    package com.ruseps.world.content.skill.impl.woodcutting;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.ruseps.model.Skill;
    import com.ruseps.model.container.impl.Equipment;
    import com.ruseps.world.entity.impl.player.Player;
    
    public class WoodcuttingData {
    	
    	public static enum Hatchet {
    		BRONZE(1351, 1, 879, 1.0),
    		IRON(1349, 1, 877, 1.3),
    		STEEL(1353, 6, 875, 1.5),
    		BLACK(1361, 6, 873, 1.7),
    		MITHRIL(1355, 21, 871, 1.9),
    		ADAMANT(1357, 31, 869, 2),
    		RUNE(1359, 41, 867, 2.2),
    		DRAGON(6739, 61, 2846, 2.28),
    		ADZE(13661, 80, 10227, 2.5);
    
    		private int id, req, anim;
    		private double speed;
    
    		private Hatchet(int id, int level, int animation, double speed) {
    			this.id = id;
    			this.req = level;
    			this.anim = animation;
    			this.speed = speed;
    		}
    
    		public static Map<Integer, Hatchet> hatchets = new HashMap<Integer, Hatchet>();
    
    
    		public static Hatchet forId(int id) {
    			return hatchets.get(id);
    		}
    
    		static {
    			for(Hatchet hatchet : Hatchet.values()) {
    				hatchets.put(hatchet.getId(), hatchet);
    			}
    		}
    
    		public int getId() {
    			return id;
    		}
    
    		public int getRequiredLevel() {
    			return req;
    		}
    
    		public int getAnim() {
    			return anim;
    		}
    		
    		public double getSpeed() {
    			return speed;
    		}
    	}
    
    	public static enum Trees {
    		NORMAL(1, 3655, 1511, new int[] { 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319, 1330, 1331, 1332, 1365, 1383, 1384, 3033, 3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 4, false),
    		ACHEY(1, 3655, 2862, new int[] { 2023 }, 4, false),
    		OAK(15, 4684, 1521, new int[] { 1281, 3037 }, 5, true),
    		WILLOW(30, 6346, 1519, new int[] { 1308, 5551, 5552, 5553 }, 6, true),
    		TEAK(35, 6544, 6333, new int[] { 9036 }, 7, true),
    		DRAMEN(36, 6581, 771, new int[] { 1292 }, 7, true),
    		MAPLE(45, 7935, 1517, new int[] { 1307, 4677 }, 7, true),
    		MAHOGANY(50, 8112, 6332, new int[] { 9034 }, 7, true),
    		YEW(60, 8417, 1515, new int[] { 1309 }, 8, true),
    		MAGIC(75, 9127, 1513, new int[] { 1306 }, 9, true);
    
    		private int[] objects;
    		private int req, xp, log, ticks;
    		private boolean multi;
    
    		private Trees(int req, int xp, int log, int[] obj, int ticks, boolean multi) {
    			this.req = req;
    			this.xp = xp;
    			this.log = log;
    			this.objects = obj;
    			this.ticks = ticks;
    			this.multi = multi;
    		}
    		
    		public boolean isMulti() {
    			return multi;
    		}
    		
    		public int getTicks() {
    			return ticks;
    		}
    
    		public int getReward() {
    			return log;
    		}
    
    		public int getXp() {
    			return xp;
    		}
    
    		public int getReq() {
    			return req;
    		}
    
    		private static final Map<Integer, Trees> tree = new HashMap<Integer, Trees>();
    
    		public static Trees forId(int id) {
    			return tree.get(id);
    		}
    
    		static {
    			for (Trees t : Trees.values()) {
    				for (int obj : t.objects) {
    					tree.put(obj, t);
    				}
    			}
    		}
    	}
    
    	public static int getHatchet(Player p) {
    		for (Hatchet h : Hatchet.values()) {
    			if (p.getEquipment().getItems()[Equipment.WEAPON_SLOT].getId() == h.getId()) {
    				return h.getId();
    			} else if (p.getInventory().contains(h.getId())) {
    				return h.getId();
    			}
    		}
    		return -1;
    	}
    
    	public static int getChopTimer(Player player, Hatchet h) {
    		int skillReducement = (int) (player.getSkillManager().getMaxLevel(Skill.WOODCUTTING) * 0.05);
    		int axeReducement = (int) h.getSpeed();
    		return skillReducement + axeReducement;
    	}
    }
    Reply With Quote  
     

  4. #4  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Why not make a new class containing the tree cut and reward for it instead?


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  5. #5  
    Registered Member Farage's Avatar
    Join Date
    Jan 2017
    Posts
    252
    Thanks given
    24
    Thanks received
    22
    Rep Power
    0
    In trees enum in woodcuttingdata replace this
    Code:
    NORMAL(1, 3655, 1511, new int[] { 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319, 1330, 1331, 1332, 1365, 1383, 1384, 3033, 3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 4, false),
    		ACHEY(1, 3655, 2862, new int[] { 2023 }, 4, false),
    		OAK(15, 4684, 1521, new int[] { 1281, 3037 }, 5, true),
    		WILLOW(30, 6346, 1519, new int[] { 1308, 5551, 5552, 5553 }, 6, true),
    		TEAK(35, 6544, 6333, new int[] { 9036 }, 7, true),
    		DRAMEN(36, 6581, 771, new int[] { 1292 }, 7, true),
    		MAPLE(45, 7935, 1517, new int[] { 1307, 4677 }, 7, true),
    		MAHOGANY(50, 8112, 6332, new int[] { 9034 }, 7, true),
    		YEW(60, 8417, 1515, new int[] { 1309 }, 8, true),
    		MAGIC(75, 9127, 1513, new int[] { 1306 }, 9, true);
    with this
    Code:
    NORMAL(1, 3655, 1511, new int[] { 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1319, 1330, 1331, 1332, 1365, 1383, 1384, 3033, 3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 4, false),
    		ACHEY(1, 3655, 2862, new int[] { 2023 }, 4, false),
    		OAK(15, 4684, 1521, new int[] { 1281, 3037 }, 5, true),
    		WILLOW(30, 6346, 1519, new int[] { 1308, 5551, 5552, 5553 }, 6, true),
    		TEAK(35, 6544, 6333, new int[] { 9036 }, 7, true),
    		DRAMEN(36, 6581, 771, new int[] { 1292 }, 7, true),
    		MAPLE(45, 7935, 1517, new int[] { 1307, 4677 }, 7, true),
    		MAHOGANY(50, 8112, 6332, new int[] { 9034 }, 7, true),
    		YEW(60, 8417, 1515, new int[] { 1309 }, 8, true),
    		MAGIC(75, 9127, 1513, new int[] { 1306 }, 9, true);
    		EVIL(85, 10000,-1,new int[] { 11434},15,true);
    Change what you need such as xp, reward and other tree ids and ticks
    Have a nice day!
    Иди в пизду!
    Bonne journée!
    Einen schönen Tag noch!
    Hezký den!
    祝你今天愉快!
    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. Replies: 0
    Last Post: 11-19-2016, 11:35 PM
  2. Some help with this error please
    By supernova123 in forum Help
    Replies: 0
    Last Post: 02-19-2014, 11:37 PM
  3. Some help with my App please
    By plats in forum Application Development
    Replies: 4
    Last Post: 10-20-2013, 01:08 AM
  4. Replies: 0
    Last Post: 07-20-2010, 09:48 PM
  5. Replies: 3
    Last Post: 07-20-2010, 09:46 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •