Thread: Event Manager Looping Help

Results 1 to 10 of 10
  1. #1 Event Manager Looping Help 
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    When I fletch arrow shafts from logs, I want it to loop through the event three times, adding 5 logs each time before finally giving the XP and message on the third time. However, I get the message saying "You carefully cut the wood into 15 arrow shafts." and then it loops once more, giving me a total of 20 shafts.

    Code:
    	static int stepcounter = 0;
    	
    	public static void fletch(int amount, Client client) {
    		final Client c = client;
    		if(c.fletchShafts == 1) {
    			if(amount == 1) {
    				if(c.GetXItemsInBag(1511) > 0) {
    					EventManager.getSingleton().addEvent(new Event() {
    		                public void execute(EventContainer ec) {
    		                	if(stepcounter == 2) {
    		                		c.addItem(52, 5);
    		                		c.sM("You carefully cut the wood into 15 arrow shafts.");
    			                	c.addSkillXP(5 * Server.EXP_MULTIPLIER, 9);
    			                	ec.stop();
    			                	stepcounter =  0;
    		                	}
    		                	if(stepcounter == 1) {
    		                		c.addItem(52, 5);
    		                		stepcounter++;
    		                	}
    		                	if(stepcounter == 0) {
    		                		c.deleteItem(1511, 1);
    		                		c.addItem(52, 5);
    		                		stepcounter++;
    		                	}
    		                }
    		            }, 600);
    				}
    			}
    		}
    	}
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    Code:
    switch(stepcounter){
        case 2:
            ec.stop();
            c.addItem(52, 5);
            c.sM("You carefully cut the wood into 15 arrow shafts.");
            c.addSkillXP(5 * Server.EXP_MULTIPLIER, 9);
            stepcounter =  0;
            break;
        case 1:
            c.addItem(52, 5);
            stepcounter++;
            break;
        case 0:
            c.deleteItem(1511, 1);
            c.addItem(52, 5);
            stepcounter++;
            break;
    }
    Stop the event container, before, not after you cut the logs.
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    Worked perfectly, thankyou.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    Quote Originally Posted by James_ View Post
    Worked perfectly, thankyou.
    Theres two different buttons to thank me for you
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    I've run into another error (not compilation error, this time)

    I am trying to make it so that if you use Make 5, it just loops the event 5 times. Here is my code:
    Code:
    static int counter = 0;
    	static int stepcounter = 0;
    	public static void fletch(final int amount, Client client) {
    		final Client c = client;
    		if (c.fletchShafts == 1) {
    			if (amount > 0) {
    				if (c.GetXItemsInBag(1511) > 0
    						&& c.GetXItemsInBag(1511) >= amount) {
    					fletchShafts(amount, c);
    				}
    			}
    		}
    	}
    	
    	public static void fletchShafts(final int amount, Client client) {
    		final Client c = client;
    		c.setAnimation(1248);
    		c.deleteItem(1511, 1);
    		EventManager.getSingleton().addEvent(new Event() {
    			public void execute(EventContainer ec) {
    				switch (stepcounter) {
    					case 3:
    						counter++;
    						ec.stop();
    						c.addItem(52, 15);
    						c.sM("You carefully cut the wood into 15 arrow shafts.");
    						c.addSkillXP(5 * Server.EXP_MULTIPLIER, 9);
    						stepcounter = 0;
    						if(amount > counter) fletchShafts(amount, c); 
    						break;
    					case 2:
    						stepcounter++;
    						break;
    					case 1:
    						stepcounter++;
    						break;
    					case 0:
    						stepcounter++;
    						break;
    				}
    			}
    		}, 930);
    	}
    But I get this error when it reaches the second log (the first log gets fletched perfectly):
    Code:
    Exception in thread "Thread-0" java.util.ConcurrentModificationException
    	at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
    	at java.util.AbstractList$Itr.next(Unknown Source)
    	at com.rs2.event.EventManager.run(EventManager.java:96)
    	at java.lang.Thread.run(Unknown Source)
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    CycleEventHandler uses a singleton to start an event, I'm not 100% sure why the error is being thrown, but my assumption would be that you've run into a thread and you're grabbing an instance of something which is blocked.
    Essentially you have a deadlock, what you can do for a temporary fix is try using the standard PI eventManager system. Otherwise i'd need to see it proper to debug it for you.
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    What do you mean by see it proper? I'll send you whatever you need
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    Sorry just read through your code.
    Code:
    fletchShafts(amount, c);
    you can't use recursion in this situation you've caused a deadlock because of the fact you can only have a single active instance with the event manager, infact there isn't even a need for you to do that as it will maintain the event by itself.

    So just to reiterate, if you want make a timed event to execute that event, you'll need to do it on a separate thread, AKA a new method and new anonymous inner method with the new CycleEvent crap.
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    Quote Originally Posted by Faris View Post
    Sorry just read through your code.
    Code:
    fletchShafts(amount, c);
    you can't use recursion in this situation you've caused a deadlock because of the fact you can only have a single active instance with the event manager, infact there isn't even a need for you to do that as it will maintain the event by itself.

    So just to reiterate, if you want make a timed event to execute that event, you'll need to do it on a separate thread, AKA a new method and new anonymous inner method with the new CycleEvent crap.
    I don't understand what you mean I need to run the event twice because I need to set the animation just before the event, because if I set the animation on the first cycle of the event then it runs the anim 930ms after the player begins fletching.
    Reply With Quote  
     

  10. #10  
    Registered Member

    Join Date
    Feb 2009
    Age
    27
    Posts
    2,861
    Thanks given
    127
    Thanks received
    226
    Rep Power
    700
    Nevermind, I fixed it
    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: 20
    Last Post: 02-06-2011, 12:52 AM
  2. Replies: 6
    Last Post: 01-18-2011, 09:56 PM
  3. event manager
    By storyscape in forum Help
    Replies: 11
    Last Post: 06-08-2010, 04:31 PM
  4. My Event Manager
    By Laxika in forum Snippets
    Replies: 5
    Last Post: 01-09-2010, 07:41 PM
  5. Replies: 6
    Last Post: 12-29-2009, 02:36 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
  •