Thread: [508+]Cooking(Palis)USING EVENTS

Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1 [508+]Cooking(Palis)USING EVENTS 
    Registered Member

    Join Date
    Jan 2009
    Posts
    1,318
    Thanks given
    71
    Thanks received
    105
    Discord
    View profile
    Rep Power
    334
    40% creds to me
    50% creds to mystic flow
    10% creds to zach for 2-1 method.

    Ok guys first you will need to make a new package called skills(lowercased) then you would need to make another folder called cooking, now make a new class called CookingManager.java and paste this into it
    Code:
    package palidino76.rs2.skills.cooking;
    
    import palidino76.rs2.players.Player;
    import palidino76.rs2.Engine;
    import palidino76.rs2.events.*;
    import palidino76.rs2.util.Misc;
    /** 
     * Info: This could be done a little better?
     * @aurthor Mystic Flow
     * @aurthor Tim
     */
     
    public class CookingManager {
            //TODO Interface :P
    	private static int counter , times;
    	/* {fishId, levelReq, cookedItem, burntId, XPGained} */
    	private final static int[][] cookingData = 
    	   {{317, 1, 315, 323, 70},	
    		{335, 15, 333, 343, 110}, 
    		{331, 25, 329, 343, 180},
    		{349, 20, 351, 349, 150},
    		{377, 40, 379, 381, 400},
    		{371, 45, 373, 375, 700},
    		{383, 80, 385, 387, 1000},
    		{389, 91, 391, 393, 1500},
    		{395, 82, 397, 399, 1200}};
    	private final static int[] firePlaces = {   };
    	private final static int[] stoves = {36973};
    	private static int getBurned(int item) {
    		for (int i = 0; cookingData.length > i; i++) {
    			if(cookingData[i][0] == item) {
    				return cookingData[i][3];
    			}
    		}
    		return -1;
    	}
    	private static int getCooked(int item) {
    		for (int i = 0; cookingData.length > i; i++) {
    			if(cookingData[i][0] == item) {
    				return cookingData[i][2];
    			}
    		}
    		return -1;
    	}
    	private static int getReq(int item) {
    		for (int i = 0; cookingData.length > i; i++) {
    			if(cookingData[i][0] == item) {
    				return cookingData[i][1];
    			}
    		}
    		return -1;
    	}
    	private static int getXP(int item) {
    		for (int i = 0; cookingData.length > i; i++) {
    			if(cookingData[i][0] == item) {
    				return cookingData[i][4];
    			}
    		}
    		return -1;
    	}
    	private static int getFish(final int item) {
    		for (int i = 0; cookingData.length > i; i++) {
    			if(cookingData[i][0] == item) {
    				return cookingData[i][0];
    			}
    		}
    		return -1;
    	}
    	private static int stove() {
    		for (int i = 0; stoves.length > i;) {
    			return stoves[i];
    		}
    		return -1;
    	}
    	private static int firePlace() {
    		for (int i = 0; firePlaces.length > i;) {
    			return firePlaces[i];
    		}
    		return -1;
    	}
    	public static void handleItemOnObject(Player p,int itemId, int objectId) {
    		if(objectId == stove()) {
    			if (stove() != -1 || objectId != -1) {
    				handleCooking(p, itemId, 1);
    			}
    		}
    		if(objectId == firePlace()) {
    			if (firePlace() != -1 || objectId != -1) {
    				handleCooking(p, itemId, 2);
    			}
    		}
    	}
    	private static void handleCooking(Player p, int itemId, int object) {
    		int emote = 883;
    		if (object == 1) {
    			emote = 883;
    		}
    		if(object == 2) {
    			emote = 899;
    		}
    		final int fishId = getFish(itemId);
    		p.isCooking = true;
    		if(p.skillLvl[7] >= getReq(fishId)) {
    			executeEvent(p, itemId, emote);
    		} else {
    			p.frames.sendMessage(p, "You need level " + getReq(fishId) + " Cooking to cook this.");
    		}
    	}
    	private static void executeEvent(final Player p, final int item, final int emote) {
    			final int fishId = getFish(item);
    			EventManager.getSingleton().addEvent(1000, new Event() { 
    				public void execute(EventContainer skill) {
    					if (p == null || p.disconnected) {
    						skill.stop();
    						return;
    					}
    					if (!p.isCooking && item != -1) {
    						skill.stop();
    						return;
    					}
    					if (!hasFish(p, item)) {
    						skill.stop();
    						p.resetSkills();
    						p.frames.sendMessage(p, "You ran out of fish to cook!");
    						return;
    					}
    					if (counter == 0) {
    					p.requestAnim(emote, 0);
    					p.frames.playSound(p, 2577);
    					Engine.playerItems.deleteItem(p, item, Engine.playerItems.getItemSlot(p, item), 1);
    					if(sucess(p, fishId)) {
    						p.addSkillXP(getXP(fishId), 7);
    						p.frames.sendMessage(p, "You sucessfully cook the "+ Engine.items.getItemName(item) +".");
    						Engine.playerItems.addItem(p, getCooked(fishId), 1);
    						counter = 3;
    					} else {
    						p.frames.sendMessage(p, "Opps! You accidently burnt the " + Engine.items.getItemName(item) +".");
    						Engine.playerItems.addItem(p, getBurned(fishId), 1);
    						counter = 3;
    					}
    				}
    				counter--;
    			}
    		});
    	}
    	private static boolean sucess(Player p, int fishId) {
    		if (p.skillLvl[7] > 98) {
    			return true;
    		}
    		int level = p.skillLvl[7];
    		int fishLevel = getReq(fishId);
    		int random = Misc.random(level*2);
    		if(random > fishLevel) {
    			return true;
    		}
    		return false;
    	}
    	private static boolean hasFish(Player p, int fishId) {
    		for(int i = 0; i < p.items.length; i++) {
    			if(p.items[i] == fishId) {
    				return true;
    			}
    		}
    		return false;
    	}
    }
    Now in Player.java add

    Code:
    public boolean isCooking;
    And now in ItemOnObject.java add

    Code:
    CookingManager.handleItemOnObject(p, itemId, objectId);
    make sure to import:

    Code:
    import palidino76.rs2.skills.cooking.CookingManager;
    Now to add new food all you would do is add

    {fishId, levelReq, cookedItem, burntId, XPGained}

    to the array Have fun!
    Reply With Quote  
     

  2. #2  
    :doge:

    Join Date
    Jan 2009
    Posts
    3,759
    Thanks given
    221
    Thanks received
    816
    Rep Power
    2113
    nice job tim.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Pedo_Bear's Avatar
    Join Date
    Sep 2009
    Age
    26
    Posts
    66
    Thanks given
    1
    Thanks received
    1
    Rep Power
    110
    Good job, Tim!
    Reply With Quote  
     

  4. #4  
    Sexy Donator
    Downfall's Avatar
    Join Date
    Oct 2008
    Age
    26
    Posts
    1,084
    Thanks given
    10
    Thanks received
    1
    Rep Power
    393
    nice Job mystic flow for 50% lol

    [Only registered and activated users can see links. ]
    Did you know?
    - JaGeX has enough money to buy 8,000,000 tons of SuperCrack.
    Reply With Quote  
     

  5. #5  
    Super Donator

    Janizary's Avatar
    Join Date
    Jul 2009
    Age
    19
    Posts
    2,132
    Thanks given
    109
    Thanks received
    137
    Rep Power
    1031
    Nice job rep+

    [Only registered and activated users can see links. ]
    Quote Originally Posted by Pirlo View Post
    I don't think the cold war existed during/before WWI
    Reply With Quote  
     

  6. #6  
    Aza
    Aza is offline
    Banned

    Join Date
    May 2008
    Posts
    2,583
    Thanks given
    99
    Thanks received
    22
    Rep Power
    0
    Great job
    Reply With Quote  
     

  7. #7  
    Registered Member Rayzer's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    26
    Thanks given
    1
    Thanks received
    2
    Rep Power
    18
    Nice Job.
    Reply With Quote  
     

  8. #8  
    Registered Member
    timetodothis's Avatar
    Join Date
    Jul 2009
    Posts
    532
    Thanks given
    24
    Thanks received
    55
    Rep Power
    123
    Sweet :] Never really thought about cooking
    Reply With Quote  
     

  9. #9  
    Registered Member
    Underoath's Avatar
    Join Date
    Sep 2008
    Posts
    2,943
    Thanks given
    826
    Thanks received
    582
    Rep Power
    853
    Sexy.


    Special thanks to Payton :trollface:
    Spoiler for People I respect:

    Definitely not you, faggot.

    Reply With Quote  
     

  10. #10  
    Registered Member
    harraj128's Avatar
    Join Date
    Nov 2008
    Posts
    1,154
    Thanks given
    1
    Thanks received
    10
    Rep Power
    382
    Look nice man. Good that its with events.
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

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