Thread: Fishing(Event) Issue

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 Fishing(Event) Issue 
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    I finished my fishing skill, fixed all issues with it, except for one.

    If you mass click the fishing spot, it "mass fishes". In other words, click it twice, it fishes two times as fast, basically starting a second event. But, I have this when you click a spot:
    Code:
    				if(!c.isFishing) {
    					//Fishing.fishingEvent.stop();
    					Fishing.doFishingEvent(c, npcType, 2);
    				} else {
    					Fishing.fishingEvent.stop();
    				}
    This is the event itself:
    Code:
    	public static Event fishingEvent = new Event(){
    		@Override
    		public void execute(EventContainer cont) {
    			if(client.isFishing) {
    				if(!runFishingCheck(client, fishingSpot, clickedSpot)) {
    					cont.stop();
    					return;
    				}
    				int checkedFish = checkFish(client, getFish(fishingSpot, clickedSpot));
    				client.startAnimation(getAnim(fishingSpot, clickedSpot));
    				client.getItems().addItem(checkedFish, 1);
    				client.sendMessage("You catch " + getString(client.getItems().getItemName(checkedFish).toLowerCase()) + ".");
    				if(getSpotBait(fishingSpot, clickedSpot) > 0)
    					client.getItems().deleteItem(getSpotBait(fishingSpot, clickedSpot), 1);
    				client.getPA().addSkillXP(getXP(checkedFish) * Config.XP_RATE, 10);
    				client.getPA().refreshSkill(10);
    				cont.setTick(20 * (300 - reducedTime(client, checkedFish)));
    			}
    		}
    		@Override
    		public void stop() {
    			client.isFishing = false;
    		}
    	};
    And where the event is initialized:
    Code:
    			if(!c.isFishing) {
    				c.isFishing = true;
    				EventManager.getSingleton().addEvent(fishingEvent, 20 * 200);
    			}
    I honestly can't figure it out. I've tried everything.

    EDIT: Here is the event related stuff in Fishing.java
    Spoiler for Fishing.java:
    Code:
    package server.model.players.skills;
    
    import server.event.*;
    import server.model.players.Client;
    import server.Constants;
    
    public class Fishing {
    
    	public static int fishingSpot;
    	public static int clickedSpot;
    	public static Client client;
    
    	public static void doFishingEvent(final Client c, final int spot, final int click) {
    		try {
    			fishingSpot = spot;
    			clickedSpot = click;
    			client = c;
    			if(c.isFishing) {
    				c.isFishing = false;
    				return;
    			}
    			if(!runFishingCheck(c, spot, click)) {
    				return;
    			}
    			c.startAnimation(getAnim(spot, click));
    			if(!c.isFishing) {
    				c.isFishing = true;
    				EventManager.getSingleton().addEvent(fishingEvent, 4000);
    			}
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static Event fishingEvent = new Event() {
    		@Override
    		public void execute(EventContainer cont) {
    			if(client.isFishing) {
    				if(!runFishingCheck(client, fishingSpot, clickedSpot)) {
    					cont.stop();
    					return;
    				}
    				int checkedFish = checkFish(client, getFish(fishingSpot, clickedSpot));
    				client.startAnimation(getAnim(fishingSpot, clickedSpot));
    				client.getItems().addItem(checkedFish, 1);
    				client.sendMessage("You catch " + getString(client.getItems().getItemName(checkedFish).toLowerCase()) + ".");
    				if(getSpotBait(fishingSpot, clickedSpot) > 0)
    					client.getItems().deleteItem(getSpotBait(fishingSpot, clickedSpot), 1);
    				client.getPA().addSkillXP(getXP(checkedFish) * Constants.XP_RATE, 10);
    				client.getPA().refreshSkill(10);
    				cont.setTick(20 * (300 - reducedTime(client, checkedFish)));
    			}
    		}
    		@Override
    		public void stop() {
    			client.isFishing = false;
    		}
    	};
    
    	public static boolean runFishingCheck(Client c, int spot, int click) {
    		if(c.playerLevel[c.playerFishing] < getSpotLevel(spot, click)) {
    			c.sendMessage("You need a fishing level of " + getSpotLevel(spot, click) + " to fish here.");
    			return false;
    		}
    		if(!c.getItems().playerHasItem(getSpotItem(spot, click), 1) && getSpotItem(spot, click) != -1) {
    			c.sendMessage("You need a " + c.getItems().getItemName(getSpotItem(spot, click)).toLowerCase() + " to fish here.");
    			return false;
    		}
    		if(getSpotBait(spot, click) != -1 && !c.getItems().playerHasItem(getSpotBait(spot, click), 1)){
    			c.sendMessage("You need some bait to fish here.");
    			return false;
    		}
    		if(c.getItems().freeSlots() <= 0){
    			c.sendMessage("You can't carry anymore fish.");
    			return false;
    		}
    		return true;
    	}
    
    }
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member hybrent's Avatar
    Join Date
    Nov 2007
    Posts
    566
    Thanks given
    73
    Thanks received
    90
    Rep Power
    28
    Can't tell very well without looking at the whole thing, but why do you do:

    Fishing.doFishingEvent(c, npcType, 2);

    AND

    EventManager.getSingleton().addEvent(fishingEvent, 20 * 200);


    Wouldn't that be starting 2 events? (Unless that's not what doFishingEvent does)


    Again, kinda hard to tell much from just lookin at snippets.

    EDIT: One more question:
    Does this glitch happen everytime you use events, or just with fishing?
    Amused as I am not, I must continue to try. -Keith Charles
    Quote Originally Posted by Ayton View Post
    I'm sorry, but I have to agree with Hybrent.
    Reply With Quote  
     

  3. #3  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by hybrent View Post
    Can't tell very well without looking at the whole thing, but why do you do:

    Fishing.doFishingEvent(c, npcType, 2);

    AND

    EventManager.getSingleton().addEvent(fishingEvent, 20 * 200);


    Wouldn't that be starting 2 events? (Unless that's not what doFishingEvent does)


    Again, kinda hard to tell much from just lookin at snippets.

    EDIT: One more question:
    Does this glitch happen everytime you use events, or just with fishing?
    I've only ever really used Events for my Fishing skill. I have it for cooking as well, but cooking has no problems whatsoever.

    And;
    Code:
    Fishing.doFishingEvent(c, npcType, 2);
    contains
    Code:
    EventManager.getSingleton().addEvent(fishingEvent, 20 * 200);
    in it.

    Nothing is being initialized twice unless you click twice. But it shouldn't.

    EDIT: I added the main methods of Fishing.java to the first post(in the spoiler).
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    Donator


    Join Date
    Mar 2008
    Posts
    1,945
    Thanks given
    118
    Thanks received
    201
    Rep Power
    2104
    check if the event is even working at the right times...

    then check if its making new events....
    Reply With Quote  
     

  5. #5  
    Registered Member hybrent's Avatar
    Join Date
    Nov 2007
    Posts
    566
    Thanks given
    73
    Thanks received
    90
    Rep Power
    28
    Ah mmk...


    In the doFishingEvent method, try putting the c.isFishing = true after the event starts.
    That way it doesn't think it's fishing before it actually is?


    Probably won't change anything, but
    MEH.
    Amused as I am not, I must continue to try. -Keith Charles
    Quote Originally Posted by Ayton View Post
    I'm sorry, but I have to agree with Hybrent.
    Reply With Quote  
     

  6. #6  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Lmctruck30 View Post
    check if the event is even working at the right times...

    then check if its making new events....
    The event works at the right time...? You click the spot, it waits a bit before you can catch a fish(starts animation), then it starts catching fish with a timer between each fish based on your level and the fish you're fishing.

    What do you mean check if it's making new events? How. Rofl.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    I'm Back

    Stewie's Avatar
    Join Date
    Jul 2008
    Age
    26
    Posts
    7,989
    Thanks given
    1,877
    Thanks received
    1,491
    Rep Power
    5000
    I think he means once the event starts, check to see if its trying to start another fishing event, and if it is, stop the extra event.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Bing View Post
    I think he means once the event starts, check to see if its trying to start another fishing event, and if it is, stop the extra event.
    But how
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  9. #9  
    I'm Back

    Stewie's Avatar
    Join Date
    Jul 2008
    Age
    26
    Posts
    7,989
    Thanks given
    1,877
    Thanks received
    1,491
    Rep Power
    5000
    I guess create a boolean

    Code:
    	
    public static boolean alreadyRunning = false;
    public static Event fishingEvent = new Event(){
    		@Override
    		public void execute(EventContainer cont) {
    			if(alreadyRunning){
    			      cont.stop();
    			      return;
    			}
    			if(client.isFishing) {
    				alreadyRunning = true;
    				if(!runFishingCheck(client, fishingSpot, clickedSpot)) {
    					cont.stop();
    					alreadyRunning = false;
    					return;
    				}
    				int checkedFish = checkFish(client, getFish(fishingSpot, clickedSpot));
    				client.startAnimation(getAnim(fishingSpot, clickedSpot));
    				client.getItems().addItem(checkedFish, 1);
    				client.sendMessage("You catch " + getString(client.getItems().getItemName(checkedFish).toLowerCase()) + ".");
    				if(getSpotBait(fishingSpot, clickedSpot) > 0)
    					client.getItems().deleteItem(getSpotBait(fishingSpot, clickedSpot), 1);
    				client.getPA().addSkillXP(getXP(checkedFish) * Config.XP_RATE, 10);
    				client.getPA().refreshSkill(10);
    				cont.setTick(20 * (300 - reducedTime(client, checkedFish)));
    			}
    		}
    		@Override
    		public void stop() {
    			client.isFishing = false;
    			alreadyRunning = false;
    		}
    	};
    I guess that's worth a shot.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #10  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Bing View Post
    I guess create a boolean

    Code:
    	
    public static boolean alreadyRunning = false;
    public static Event fishingEvent = new Event(){
    		@Override
    		public void execute(EventContainer cont) {
    			if(alreadyRunning){
    			      cont.stop();
    			      return;
    			}
    			if(client.isFishing) {
    				alreadyRunning = true;
    				if(!runFishingCheck(client, fishingSpot, clickedSpot)) {
    					cont.stop();
    					alreadyRunning = false;
    					return;
    				}
    				int checkedFish = checkFish(client, getFish(fishingSpot, clickedSpot));
    				client.startAnimation(getAnim(fishingSpot, clickedSpot));
    				client.getItems().addItem(checkedFish, 1);
    				client.sendMessage("You catch " + getString(client.getItems().getItemName(checkedFish).toLowerCase()) + ".");
    				if(getSpotBait(fishingSpot, clickedSpot) > 0)
    					client.getItems().deleteItem(getSpotBait(fishingSpot, clickedSpot), 1);
    				client.getPA().addSkillXP(getXP(checkedFish) * Config.XP_RATE, 10);
    				client.getPA().refreshSkill(10);
    				cont.setTick(20 * (300 - reducedTime(client, checkedFish)));
    			}
    		}
    		@Override
    		public void stop() {
    			client.isFishing = false;
    			alreadyRunning = false;
    		}
    	};
    I guess that's worth a shot.
    It works in a sense, but the event can't continue after it's set to alreadyRunning = true;, it just ends the event lol. So you fish one fish, and stop.
    [Only registered and activated users can see links. ]
    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
  •