Thread: Converting Process() To Events

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 36
  1. #11  
    Ed
    Ed is offline
    AKA Edvinas
    Ed's Avatar
    Join Date
    Jun 2009
    Age
    28
    Posts
    4,504
    Thanks given
    523
    Thanks received
    512
    Rep Power
    2659
    So how do you need to do it? I have Eventmanager on my source but never used it

    Do I change ALL of those
    Code:
            if (npcDelay > 0) {
                npcDelay--;
            }
            if (teleDelay > 0) {
                teleDelay--;
            }
    (..) etc
    to this:
    Code:
    		public void statRestore(final Player p) {
            EventManager.getSingleton().addEvent(3000, new Event() { 
    	    public void execute(EventContainer c) {        
    		if (statRestoreDelay > 0) {
                statRestoreDelay--;
            } else {
    		    c.stop();
    		}
    	   }
    	});
        }
    but just changing the bolded stuff to the previous codes? like this:
    Code:
    public void isDead(final Player p) {
            EventManager.getSingleton().addEvent(3000, new Event() { 
    	    public void execute(EventContainer c) {        
            if (isDead) {
                deathDelay--;
                applyDead();
    } else {
                            c.stop();
    	   }
    	});
        }
    public void npc(final Player p) {
            EventManager.getSingleton().addEvent(3000, new Event() { 
    	    public void execute(EventContainer c) {        
            if (npcDelay > 0) {
                npcDelay--;
    } else {
                            c.stop();
    	   }
    	});
    }
    etc etc for all this if's? or what
    Reply With Quote  
     

  2. #12  
    Registered Member SilentZPrO's Avatar
    Join Date
    Dec 2008
    Posts
    727
    Thanks given
    3
    Thanks received
    4
    Rep Power
    12
    Lol no! You change the void to what that process is rofl!

    Reply With Quote  
     

  3. #13  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    kul, knew this, can you replace some of the code of your tut with this?:

    public void statRestore(final Player p) {
    EventManager.getSingleton().addEvent(2400, new Event() {
    public void execute(EventContainer c) {
    if (statRestoreDelay > 0)
    statRestoreDelay--;
    else
    c.stop();
    }
    });
    }

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

  4. #14  
    Annexation
    Guest
    Quote Originally Posted by Rowan View Post
    kul, knew this, can you replace some of the code of your tut with this?:

    public void statRestore(final Player p) {
    EventManager.getSingleton().addEvent(2400, new Event() {
    public void execute(EventContainer c) {
    if (statRestoreDelay > 0)
    statRestoreDelay--;
    else
    c.stop();
    }
    });
    }

    just conventions
    To bad you don't see spacing without tags, lol

    and yea your teaching it wrong, listen to william
    Reply With Quote  
     

  5. #15  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    just did conventions that i knew for that piece of code
    [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #16  
    XAFBX
    Guest
    Or, just make an event to call your process method process it every 500ms, then get rid of the process method being called through the Engine class and start the event on start up, oh my not multiple events pls.
    Reply With Quote  
     

  7. #17  
    Meh. I can't code.

    Soulevoker's Avatar
    Join Date
    Sep 2007
    Age
    26
    Posts
    1,198
    Thanks given
    5
    Thanks received
    6
    Rep Power
    137
    Quote Originally Posted by William.D View Post
    You're still doing it wrong, mate. Let's say you got this in your process:

    Code:
    if (timer > 0) {
    timer--;
    } if (timer == 0) {
    doJob();
    }
    Let's say you would set the timer to 6, which means 6x500MS that it would be executed after 3000 MS (3 seconds). Why does this suck? Because you are calling it 5 times to much, just execute an event after 3000 MS. Like this;

    Code:
    public void statRestore(final Player p) {
            EventManager.getSingleton().addEvent(3000, new Event() { 
            public void execute(EventContainer c) {        
            doJob();
                            c.stop();
           }
        });
        }
    I always thought it was like this:
    Code:
    public void statRestore(final Player p) {
    EventManager.getSingleton().addEvent( new Event() {
                        public void execute(EventContainer c) {
                           code here
                            c.stop();
                        }
                    }, 3000);
    }
    This works just the same right?

    Reply With Quote  
     

  8. #18  
    Registered Member pHametic's Avatar
    Join Date
    Nov 2006
    Posts
    637
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    Well after you create the method for the new event where do you call it? or does it automatically get called?
    Reply With Quote  
     

  9. #19  
    Hi.

    'Mystic Flow's Avatar
    Join Date
    Nov 2007
    Posts
    7,141
    Thanks given
    256
    Thanks received
    1,247
    Rep Power
    3636
    Quote Originally Posted by Goodoo Dolls View Post
    I always thought it was like this:
    Code:
    public void statRestore(final Player p) {
    EventManager.getSingleton().addEvent( new Event() {
                        public void execute(EventContainer c) {
                           code here
                            c.stop();
                        }
                    }, 3000);
    }
    This works just the same right?
    Goodoo replace your tick method in EventManager.java with this..


    Code:
    	public synchronized void addEvent(int tick, Event event) {
    		events.add(new EventContainer(event,tick));
    		notify();
    	}
    Thats how Simon is explaining it

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  10. #20  
    Meh. I can't code.

    Soulevoker's Avatar
    Join Date
    Sep 2007
    Age
    26
    Posts
    1,198
    Thanks given
    5
    Thanks received
    6
    Rep Power
    137
    Quote Originally Posted by Mystic Flow View Post
    Goodoo replace your tick method in EventManager.java with this..


    Code:
        public synchronized void addEvent(int tick, Event event) {
            events.add(new EventContainer(event,tick));
            notify();
        }
    Thats how Simon is explaining it
    I still don't understand the difference other than changing the place where you place the tick time in the event void

    Reply With Quote  
     

Page 2 of 4 FirstFirst 1234 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
  •