Thread: [SHARD] Eating food

Results 1 to 4 of 4
  1. #1 [SHARD] Eating food 
    Member
    Join Date
    Nov 2010
    Posts
    62
    Thanks given
    0
    Thanks received
    13
    Rep Power
    0
    Since people are begging to use shard revolutions again and I got a couple of requests on msn for help adding this to their base I figured that i would release it for them, and for you. If you like it, cool if you don't, then you can flame me all day and I still wont care and you will have waisted all of your time making yourself look like a fool.

    Difficulty: 1
    Assumed knowledge: Ability to create Java documents and copy and paste.
    What you are accomplishing: All fish food eating with correct healing amounts.

    Alright now make a file in the content package called FoodManager.java.

    Then paste this inside of it:
    Code:
    package com.rs.worldserver.content;
    
    import com.rs.worldserver.events.Event;
    import com.rs.worldserver.events.EventContainer;
    import com.rs.worldserver.events.EventManager;
    import com.rs.worldserver.model.player.Client;
    
    /**
     * This class manages eating food
     * 
     * Latest update:  Naira (Arian of Rune-Server) had a talk with me about object
     * orientation and why not to use static methods, so I took his advise and completely
     * redid the code at the cost of a few more lines of code in client.java and this class.
     * 
     * @author Scott
     */
    public class FoodManager {
    
    	/**
    	 * The time that the player last ate a piece of food.
    	 */
    	private long lastEatTime;
    	
    	/**
    	 * Animation played when one takes a bite of a peace of food.
    	 */
    	private int eatingAnimation;
    	
    	/**
    	 * Gets the eating animation variable.
    	 * @return the eating animation variable.
    	 */
    	private int getEatingAnimation() {
    		return eatingAnimation;
    	}
    	
    	/**
    	 * Sets the animation that will play when a player eats a peace of food.
    	 * @param eatingAnimation the animation that is going to be executed.
    	 */
    	private void setEatingAnimation(int eatingAnimation) {
    		// 829 = Eating food animation
    		this.eatingAnimation = eatingAnimation;
    	}
    	
    	/**
    	 * How long after the item is clicked that the event will be executed.
    	 */
    	private int eatingDelay;
    	
    	/**
    	 * Gets how long after the item is clicked that the event will be executed.
    	 * @return eathingDelay variable
    	 */
    	private int getEatingDelay() {
    		return eatingDelay;
    	}
    	
    	/**
    	 * Sets how long after the item is clicked that the event will be executed.
    	 * @param eatingDelay
    	 */
    	private void setEatingDelay(int eatingDelay) {
    		this.eatingDelay = eatingDelay;
    	}
    
    	/**
    	 * Click item hook
    	 */
    	public final boolean eatFood(final Client client, final int itemSlot) {
    		final int itemID = client.playerItems[itemSlot] - 1;
    		
    		final int[][] FOOD_DATA = {
    				{319, 1}, {315, 3}, {325, 4}, {329, 9}, {333, 7}, {339, 7}, {347, 5}, {351, 8},
    				{355, 6}, {361, 10}, {365, 13}, {379, 12}, {373, 14}, {385, 20}, {391, 22}, {397, 21}
    		};
    
    		setEatingAnimation(829);
    		client.getActionAssistant().startAnimation(getEatingAnimation());
    
    		/**
    		 * The eating food event.
    		 */
    		EventManager.getSingleton().addEvent(client, new Event() {
    			/**
    			 * Executes the eating food event
    			 */
    			public void execute(EventContainer container) {
    				if (client.getActionAssistant().getItemSlot((itemID)) == -1) {
    					container.stop();
    					return;
    				}
    				if (System.currentTimeMillis() - lastEatTime >= 1500) {
    					if(!client.isDead()) {
    						for (int i = 0; i < FOOD_DATA.length; i++) {
    							if(itemID == FOOD_DATA[i][0]) {
    								addHP(client, FOOD_DATA[i][1]);
    								client.getActionAssistant().deleteItem(itemID, client.getActionAssistant().getItemSlot(itemID), 1);
    							}
    						}
    					}
    					lastEatTime = System.currentTimeMillis();
    					setEatingDelay(1000);
    					container.stop();
    				}
    			}
    			/**
    			 * Stops the eating food event
    			 */
    			public void stop() {
    				client.getActionAssistant().startAnimation(-1);
    			}
    		}, getEatingDelay());
    
    		return true;
    	}
    	
    	/**
    	 * Adds hitpoints to the player.
    	 * @param amount - The amount of hitpoints that are depleted or added.
    	 */
    	private void addHP(Client client, int amount) {
    		if (! client.isDead()) {
    			client.playerLevel[3] += amount;
    			if (client.playerLevel[3] > client.getActionAssistant().getLevelForXP(client.playerXP[3])) {
    				client.playerLevel[3] = client.getActionAssistant().getLevelForXP(client.playerXP[3]);
    			}
    			client.getActionAssistant().setSkillLevel(3, client.playerLevel[3], client.playerXP[3]);
    		}
    	}
    
    }
    Then go into com.rs.worldserver.model.player.Client and add this import:
    Code:
    import com.rs.worldserver.content.FoodManager;
    Then find this:
    Code:
    private FriendsAssistant friendsAssistant = new FriendsAssistant(this);
    Then under it add this:
    Code:
    private FoodManager foodManager = new FoodManager();
    Then add this method in Client.java as well:
    Code:
    	/**
    	 * Gets the FoodManager Object.
    	 */
    	public FoodManager getFoodManager() {
    		return foodManager;
    	}
    Now go into com.rs.worldserver.model.player.packet.BuryBones and under this:
    Code:
    		if (Prayer.buryBones(client, burySlot)) {
    		}
    Add the following:
    Code:
    		if(client.getFoodManager().eatFood(client, burySlot)) {
    		}
    Now you are done.

    If there are any errors or anything that i missed please let me know.

    Don't flame, Thanks Deimos
    Quote Originally Posted by The MisJudged View Post
    I am god so i can answer both of ur fucking questions....... revision is scratch and base is 317.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Nov 2010
    Posts
    339
    Thanks given
    84
    Thanks received
    122
    Rep Power
    182
    Good job, but I believe the correct delay is 1200ms. (2 cycles)
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Aug 2010
    Age
    26
    Posts
    315
    Thanks given
    46
    Thanks received
    21
    Rep Power
    0
    Cool good job
    Reply With Quote  
     

  4. #4  
    Member
    Join Date
    Nov 2010
    Posts
    62
    Thanks given
    0
    Thanks received
    13
    Rep Power
    0
    BUMP; Arian had a talk with me about why not to use static methods so i redid the tutorial.

    And thanks for the comments.
    Quote Originally Posted by The MisJudged View Post
    I am god so i can answer both of ur fucking questions....... revision is scratch and base is 317.
    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. [562]More food eating[RS2HD]
    By Derranged in forum Configuration
    Replies: 5
    Last Post: 06-20-2010, 09:53 AM
  2. Food Eating #508
    By Zena in forum Tutorials
    Replies: 6
    Last Post: 06-13-2010, 02:14 PM
  3. [100%!!] NPC EATING [max food in autospawn]
    By Robin Spud in forum Show-off
    Replies: 30
    Last Post: 07-16-2009, 06:48 PM
  4. [508]Eating Food
    By Light Moger in forum Tutorials
    Replies: 6
    Last Post: 01-20-2009, 01:04 AM
  5. food problem (eating)
    By dalebra in forum RS2 Client
    Replies: 5
    Last Post: 08-17-2008, 02:27 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •