Thread: Help me with my cycle event please?

Results 1 to 9 of 9
  1. #1 Help me with my cycle event please? 
    Registered Member BryceTheCoder's Avatar
    Join Date
    Aug 2008
    Posts
    740
    Thanks given
    21
    Thanks received
    24
    Rep Power
    27
    I am tottally flipping sh1t right now.. I'm getting super mad. I just cannot find why its doing this.

    My code:
    Code:
    	public void startMining(int oreType, int levelReq, int exp) {
    		if (c.isMining)
    			return;
    		c.turnPlayerTo(c.objectX, c.objectY);
    		iOre = oreType;
    		if (!hasPick()) {
    			c.sendMessage("You need a pickaxe to mine this ore.");
    			resetMining();
    			return;
    		}
    		c.isMining = true;
    		c.sendMessage("You swing your pickaxe at the rock..");
    		c.startAnimation(mineEmote());
    		CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer container) {
    				if (!c.isMining)
    					container.stop();
    				if (c.getItems().freeSlots() != 0 && c.isMining) {
    					c.startAnimation(mineEmote());
    					c.getItems().addItem(iOre, 1);
    					c.sendMessage("You mine an ore.");
    				}
    				if (c.getItems().freeSlots() == 0) {
    					c.sendMessage("You have no more free space in your inventory.");
    					container.stop();
    				}
    			}
    			@Override
    			public void stop() {
    				resetMining();
    				c.sendMessage("@red@EVENT STOPPED!");
    			}
    		}, 5 + Misc.random(getMiningTimer(oreType)));
    	}


    So when I click on a rock object, it will do the startMining void.
    And if I click that rock like 15 times, it will create 15 cycle events for adding the ores to your inventory. So of course, I'm trying to prevent that.
    I added a boolean "isMining" so I could fix this little bug.
    Once you start mining the rock I clearly state to make it true.
    c.isMining = true;
    c.sendMessage("You swing your pickaxe at the rock..");

    Now in the begging so if they try to click it again and call startMining void again I put:
    if (c.isMining)
    return;

    So it would NOT create another cycle event for it.
    But for some ODD reason, it will not return and it will do the whole void. it will say again "You swing your pickaxe at the rock.." and it will create another cycle event.

    Please help me

    Advertise your RSPS cheap on my website: www.BryceBux.com

    ^ PM me and I will give you a few dollars for FREE on my website for advertisements ^
    Reply With Quote  
     

  2. #2  
    Registered Member BryceTheCoder's Avatar
    Join Date
    Aug 2008
    Posts
    740
    Thanks given
    21
    Thanks received
    24
    Rep Power
    27
    BUMP.
    Someone please help meh :/

    Advertise your RSPS cheap on my website: www.BryceBux.com

    ^ PM me and I will give you a few dollars for FREE on my website for advertisements ^
    Reply With Quote  
     

  3. #3  
    Spread Love

    Dhruv's Avatar
    Join Date
    Feb 2012
    Age
    28
    Posts
    1,011
    Thanks given
    157
    Thanks received
    167
    Rep Power
    215
    Try adding
    Code:
    c.isMining = false;
    in your void stop
    Reply With Quote  
     

  4. #4  
    Registered Member BryceTheCoder's Avatar
    Join Date
    Aug 2008
    Posts
    740
    Thanks given
    21
    Thanks received
    24
    Rep Power
    27
    Quote Originally Posted by Physco View Post
    Try adding
    Code:
    c.isMining = false;
    in your void stop
    No thats not the problem. I do not believe you understand completely:/ Please re-read it again.
    My resetMining() void is making the boolean isMining = false.

    Advertise your RSPS cheap on my website: www.BryceBux.com

    ^ PM me and I will give you a few dollars for FREE on my website for advertisements ^
    Reply With Quote  
     

  5. #5  
    Registered Member 06scape Developers's Avatar
    Join Date
    Aug 2013
    Age
    25
    Posts
    26
    Thanks given
    1
    Thanks received
    0
    Rep Power
    11
    public void startMining(int oreType, int levelReq, int exp) { if (c.isMining) return; } c.turnPlayerTo(c.objectX, c.objectY); iOre = oreType; if (!hasPick()) { c.sendMessage("You need a pickaxe to mine this ore."); resetMining(); return; } c.isMining = true; c.sendMessage("You swing your pickaxe at the rock.."); c.startAnimation(mineEmote()); CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() { @Override public void execute(CycleEventContainer container) { if (!c.isMining) container.stop(); return; } if (c.getItems().freeSlots() != 0 && c.isMining) { c.startAnimation(mineEmote()); c.getItems().addItem(iOre, 1); c.sendMessage("You mine an ore."); } if (c.getItems().freeSlots() == 0) { c.sendMessage("You have no more free space in your inventory."); return; container.stop(); } } @Override public void stop() { resetMining(); c.sendMessage("@red@EVENT STOPPED!"); } }, 5 + Misc.random(getMiningTimer(oreType))); }
    [ Mod Mark] [ Mod Jason ] [ Mod Driman ]
    [ Client Developer ] [ Co of 06scape ] [ Head of 06scape ]



    1 registry is under review.
    Reply With Quote  
     

  6. #6  
    Registered Member BryceTheCoder's Avatar
    Join Date
    Aug 2008
    Posts
    740
    Thanks given
    21
    Thanks received
    24
    Rep Power
    27
    Quote Originally Posted by 06scape Developers View Post
    public void startMining(int oreType, int levelReq, int exp) { if (c.isMining) return; } c.turnPlayerTo(c.objectX, c.objectY); iOre = oreType; if (!hasPick()) { c.sendMessage("You need a pickaxe to mine this ore."); resetMining(); return; } c.isMining = true; c.sendMessage("You swing your pickaxe at the rock.."); c.startAnimation(mineEmote()); CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() { @Override public void execute(CycleEventContainer container) { if (!c.isMining) container.stop(); return; } if (c.getItems().freeSlots() != 0 && c.isMining) { c.startAnimation(mineEmote()); c.getItems().addItem(iOre, 1); c.sendMessage("You mine an ore."); } if (c.getItems().freeSlots() == 0) { c.sendMessage("You have no more free space in your inventory."); return; container.stop(); } } @Override public void stop() { resetMining(); c.sendMessage("@red@EVENT STOPPED!"); } }, 5 + Misc.random(getMiningTimer(oreType))); }
    That is terrible...
    I can't even read that. Can you please put it in code brackets?

    Advertise your RSPS cheap on my website: www.BryceBux.com

    ^ PM me and I will give you a few dollars for FREE on my website for advertisements ^
    Reply With Quote  
     

  7. #7  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Ripped this from Project Perfection, you dont have to replace your whole mining file with it but I suggest u do. If not just read over it
    Code:
    package server.model.players.skills;
    
    import server.model.players.Client;
    import server.event.*;
    import server.Server;
    import server.Config;
    
    public class Mining extends SkillHandler {
    
    	public static void attemptData(final Client c, final int object, final int obX, final int obY) {
    		if(!noInventorySpace(c, "mining")) {
    			resetMining(c);
    			return;
    		}
    		if(!hasRequiredLevel(c, 14, getLevelReq(c, object), "mining", "mine here")) {
    			return;
    		}
    		if(!hasPickaxe(c)) {
    			c.sendMessage("You need a pickaxe to mine this rock.");
    			return;
    		}
    		c.sendMessage("You swing your pick at the rock.");
    		if(c.playerSkilling[14]) {
    			return;
    		}
    		c.playerSkilling[14] = true;
    		c.stopPlayerSkill = true;
    		c.startAnimation(getAnimation(c));
    		c.turnPlayerTo(c.objectX, c.objectY);
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				c.playerSkillProp[14][0] = data[i][1];
    				c.playerSkillProp[14][1] = data[i][3];
    				c.startAnimation(getAnimation(c));
    				CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    					@Override
    					public void execute(CycleEventContainer container) {
    					c.turnPlayerTo(c.objectX, c.objectY);
    						if(c.playerSkillProp[14][0] > 0) {
    							c.getItems().addItem(c.playerSkillProp[14][0], 1);
    							c.sendMessage("You manage to mine some "+ c.getItems().getItemName(c.playerSkillProp[14][0]).toLowerCase()+".");
    						}
    						if(c.playerSkillProp[14][1] > 0) {
    							c.getPA().addSkillXP(c.playerSkillProp[14][1] * MINING_XP, c.playerMining);
    							Server.objectHandler.createAnObject(c, 451, obX, obY);
    						}
    						if(!hasPickaxe(c)) {
    							c.sendMessage("You need a pickaxe to mine this rock.");
    							resetMining(c);
    							container.stop();
    						}
    						if(!c.stopPlayerSkill) {
    							resetMining(c);
    							container.stop();
    						}
    						if(!noInventorySpace(c, "mining")) {
    							resetMining(c);
    							container.stop();
    						}
    
    						resetMining(c);
    						container.stop();
    					}
    					@Override
    					public void stop() {
    					}
    				}, getTimer(c, object));
    				CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    					@Override
    					public void execute(CycleEventContainer container) {
    						Server.objectHandler.createAnObject(c, object, obX, obY);
    						container.stop();
    					}
    					@Override
    					public void stop() {
    					}
    				}, getTimer(c, object) + getRespawnTime(c, object));
    				CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    					@Override
    					public void execute(CycleEventContainer container) {
    						if(c.playerSkilling[14]) {
    							c.startAnimation(getAnimation(c));
    						}
    						if(!c.stopPlayerSkill || !c.playerSkilling[14]) {
    							resetMining(c);
    							container.stop();
    						}
    					}
    					@Override
    					public void stop() {
    					}
    				}, 15);
    			}
    		}
    	}
    
    	private static int getTimer(Client c, int i) {
    		return (getMineTime(c, i) + getTime(c) + playerMiningLevel(c));
    	}
    
    	private static int getMineTime(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				return data[i][4];
    			}
    		}
    		return -1;
    	}
    
    	private static int playerMiningLevel(Client c) {
    		return (10 - (int)Math.floor(c.playerLevel[14] / 10));
    	}
    
    	private static int getTime(Client c) {
    		for(int i = 0; i < pickaxe.length; i++) {
    			if(c.getItems().playerHasItem(pickaxe[i][0]) || c.playerEquipment[3] == pickaxe[i][0]) {
    				if(c.playerLevel[c.playerMining] >= pickaxe[i][1]) {
    					return pickaxe[i][2];
    				}
    			}
    		}
    		return 10;
    	}
    
    	public static void resetMining(Client c) {
    		c.playerSkilling[14] = false;
    		c.stopPlayerSkill = false;
    		for(int i = 0; i < 2; i++) {
    			c.playerSkillProp[14][i] = -1;
    		}
    		c.startAnimation(65535);
    	}
    
    	public static boolean miningRocks(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    	private static int getRespawnTime(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				return data[i][5];
    			}
    		}
    		return -1;
    	}
    
    	private static int getLevelReq(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				return data[i][2];
    			}
    		}
    		return -1;
    	}
    
    	private static boolean hasPickaxe(Client c) {
    		for(int i = 0; i < animation.length; i++) {
    			if(c.getItems().playerHasItem(animation[i][0]) || c.playerEquipment[3] == animation[i][0]) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    	private static int getAnimation(Client c) {
    		for(int i = 0; i < animation.length; i++) {
    			if(c.getItems().playerHasItem(animation[i][0]) || c.playerEquipment[3] == animation[i][0]) {
    				return animation[i][1];
    			}
    		}
    		return -1;
    	}
    
    	private static int[][] animation = {
    		{15259, 12188},{1275, 6746}, {1271, 6750}, {1273, 6751}, {1269, 6749},
    		{1267, 6748}, {1265, 6747}, {13661, 10249}
    	};
    
    	private static int[][] pickaxe = {
    		{15259, 61, 0}, 		//Dragon
    		{1275, 41, 0}, 		//RUNE
    		{13661, 41, 0},		//Inferno Adze
    		{1271, 31, 1},		//ADDY
    		{1273, 21, 2},		//MITH
    		{1269, 6, 3},		//STEEL
    		{1267, 1, 3},		//IRON
    		{1265, 1, 4},		//BRONZE
    	};
    
    	private static int[][] data = {
    		{2091, 436, 1, 18, 1, 5},	//COPPER
    		{2090, 436, 1, 18, 1, 5},	//COPPER
    		{2094, 438, 1, 18, 1, 5},	//TIN
    		{2095, 438, 1, 18, 1, 5},	//TIN
    		{2093, 440, 15, 35, 2, 5},	//IRON
    		{2092, 440, 15, 35, 2, 5},	//IRON
    		{2097, 453, 30, 50, 3, 8},	//COAL
    		{2096, 453, 30, 50, 3, 8},	//COAL
    		{2098, 444, 40, 65, 3, 10},	//GOLD
    		{2099, 444, 40, 65, 3, 10},	//GOLD
    		{2103, 447, 55, 80, 5, 20},	//MITH
    		{2102, 447, 55, 80, 5, 20},	//MITH
    		{2104, 449, 70, 95, 7, 50},	//ADDY
    		{2105, 449, 70, 95, 7, 50},	//ADDY
    		{2100, 442, 20, 40, 5, 5},	//SILVER
    		{2101, 442, 20, 40, 5, 5},	//SILVER
    		{14859, 451, 85, 125, 40, 100},//RUNE
    		{14860, 451, 85, 125, 40, 100},//RUNE
    	};
    
    	public static void prospectRock(final Client c, final String itemName) {
    		c.sendMessage("You examine the rock for ores...");
    		EventManager.getSingleton().addEvent(new Event() {
    
    			@Override
    			public void execute(EventContainer container) {
    				c.sendMessage("This rock contains "+itemName+".");
    				container.stop();
    			}
    
    		}, 2500);
    	}
    	public static void prospectNothing(final Client c) {
    		c.sendMessage("You examine the rock for ores...");
    		EventManager.getSingleton().addEvent(new Event() {
    
    			@Override
    			public void execute(EventContainer container) {
    				c.sendMessage("There is no ore left in this rock.");
    				container.stop();
    			}
    
    		}, 1000);
    	}
    }
    Also if you want you can add in ActionHandlein the mining case or w/e that if the person is mining they cant click again
    OR add this above under your "isMining" c.stopPlayerSkill = true;
    Attached image
    Reply With Quote  
     

  8. #8  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    The only thing I can come up with, is that the isMining variable is set to false elsewhere.
    Try and find setters of that variable (most notably in process, which could be a remnant of old mining code).
    Reply With Quote  
     

  9. #9  
    Respected Member


    George's Avatar
    Join Date
    Mar 2009
    Posts
    7,099
    Thanks given
    2,226
    Thanks received
    3,146
    Rep Power
    5000
    You need to make a check that ensures that a player cannot run an event more than once at a time.
    Attached image

    Spoiler for Spoilers!:
    Attached image
    Attached image
    Attached image
    Attached image
    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: 2
    Last Post: 02-14-2013, 01:37 AM
  2. Help me with my rsps compiler please! :(
    By johnyopolo in forum Help
    Replies: 0
    Last Post: 12-01-2012, 11:26 PM
  3. Please help me with my webby! :(
    By softwaretavlonia in forum Help
    Replies: 0
    Last Post: 10-10-2012, 03:30 PM
  4. Please help me with my VPS
    By gl til i die in forum Help
    Replies: 10
    Last Post: 06-10-2012, 03:31 PM
  5. Replies: 0
    Last Post: 04-12-2011, 09:28 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
  •