Thread: Adding a Easy-To-Use Timer!

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 Adding a Easy-To-Use Timer 
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    ~Lester Knome's Easy-To-Use Tutorials~


    MAKE SURE YOU MAKE A BACKUP



    FIXED TIMER!!!



    Make a new file called: Timer.java and add:

    Code:
    
    /*~Lester Knome's Easy-To-Use Tutorials~*/
    
    public class Timer 
    {	
    
    	//Milliseconds
    	public static int globalMili;
    	public static int miliTimer = -1;
    	
    	//Seconds
    	public static int globalSeconds;
    	public static int secondsTimer = -1;
    	public static boolean secTick = false;
    	
    	//Minutes
    	public static int globalMinutes;
    	public static int minutesTimer = -1;
    	public static int minTick = 0;
    	
    
    	public void process() 
    	{
    
    		//Milliseconds
    		if(globalMili < miliTimer) globalMili++;
    		
    		//Resets after 1 hour
    		if(globalMili == 3600000) {
    		
    			resetMilli(false);
    		
    		}
    	
    		//Seconds	
    		if(globalSeconds < secondsTimer) {
    		
    			if(secTick)
    			{
    			
    				globalSeconds++;
    			
    			}
    			
    			if(secTick) secTick = false;
    			if(!secTick) secTick = true;
    			
    		}
    		
    		//Resets after 5 hours
    		if(globalSeconds == 18000) {
    			
    			resetSec(false);
    			
    		}	
    			
    		//Minutes
    		if(globalMinutes < minutesTimer) {
    			
    			minTick++;
    			
    			if(minTick == 120) 
    			{
    				globalMinutes++;
    				minTick = 0;
    			}
    			
    		}
    		
    		//Resets after 25 hours
    		if(globalMinutes == 1500) {
    		
    			resetMin(false);
    		
    		}
    		
    	
    	}
    	
    	//Milliseconds
    	public static void resetMilli(boolean timer) 
    	{
    	
    		globalMili = 0;
    		if (timer) miliTimer = -1;
    		
    	}
    	
    	//Seconds
    	public static void resetSec(boolean timer) 
    	{
    	
    		globalSeconds = 0;
    		secTick = false;
    		if (timer) secondsTimer = -1;
    		
    	}
    	
    	//Minutes
    	public static void resetMin(boolean timer) 
    	{
    	
    		globalMinutes = 0;
    		minTick = 0;
    		if (timer) minutesTimer = -1;
    		
    	}
    	
    	//Milliseconds
    	public static int Milliseconds(int milli, boolean reset) 
    	{
    		
    		if(reset) 
    		{
    			resetMilli(true);
    		}
    		
    		miliTimer = milli;
    		
    		return milli - globalSeconds;
    		
    	}
    	
    	//Seconds
    	public static int Seconds(int secs, boolean reset) 
    	{
    	
    		if(reset) 
    		{
    			resetSec(true);
    		}
    		
    		secondsTimer = secs;
    		
    		return secs - globalSeconds;
    		
    	}
    	
    	//Minutes
    	public static int Minutes(int mins, boolean reset) 
    	{
    	
    		if(reset) 
    		{
    			resetMin(true);
    		}
    		
    		minutesTimer = mins;
    		
    		return mins - globalSeconds;
    		
    	}
    	
    }
    In server.java under:

    Code:
    public static PlayerHandler playerHandler = null;
    add:

    Code:
    public static Timer	Timer = null;
    and under:

    Code:
    playerHandler = new PlayerHandler();
    add:

    Code:
    Timer = new Timer();

    Now to start the global Timer add:

    Code:
    server.Timer.process();
    to procces.java

    If you don't have it, just add it to client.java's process.

    Using it:

    To Start Timer:


    For milliseconds:
    Code:
    Milliseconds(Milliseconds till reaches 0?, true);
    For Seconds:
    Code:
    Seconds(Seconds till reaches 0?, true);
    For Minutes:
    Code:
    Minutes(Minutes till reaches 0?, true);
    To call timer:

    For milliseconds:
    Code:
    if(Milliseconds(Milliseconds till reaches 0?, false)){
    //Code
    }
    For Seconds:
    Code:
    if(Seconds(Seconds till reaches 0?, false)) {
    //Code
    }
    For Minutes:
    Code:
    if(Minutes(Minutes till reaches 0?, false)) {
    //Code
    }

    and to reset:

    Milliseconds:
    Code:
    resetMilli();
    Seconds:
    Code:
    resetSec();
    Minutes
    Code:
    resetMin();
    Previous Tutorial: None

    Next Tutorial: [Only registered and activated users can see links. ]
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  2. #2  
    Donator

    DrDiablo's Avatar
    Join Date
    Sep 2006
    Age
    37
    Posts
    3,279
    Thanks given
    344
    Thanks received
    1,381
    Rep Power
    5000
    Great suggestion. I'm sure it will help many
    Reply With Quote  
     

  3. #3  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Hope so
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  4. #4  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    very nice dude
    [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  
     

  5. #5  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    thanx
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  6. #6  
    Registered Member
    Homie Pimpson's Avatar
    Join Date
    Jul 2008
    Age
    26
    Posts
    982
    Thanks given
    280
    Thanks received
    124
    Rep Power
    175
    I don't understand a thing, will you explain how to use the timer?
    Doesn't work if i do something like this
    Seconds(5);
    Reply With Quote  
     

  7. #7  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Quote Originally Posted by thedeath View Post
    I don't understand a thing, will you explain how to use the timer?
    Doesn't work if i do something like this
    Seconds(5);
    Honestly idk either im just waiting for someone to come tell me how i can fix it or tell me how i can use it.

    I was thinking about a constructor but =/ dunno.
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

  8. #8  
    xAcid Tripx
    Guest
    Pretty cool this will work for anything?
    Reply With Quote  
     

  9. #9  
    Registered Member
    Sanity's Avatar
    Join Date
    Dec 2008
    Posts
    2,062
    Thanks given
    22
    Thanks received
    362
    Rep Power
    762
    if(!secTick)
    secTick = true;
    if(secTick)
    secTick = false;
    Huh? secTick will always be false (unless I'm missing something)....

    Another suggestion is that you could use the "tick" in the PlayerHandler class which runs every 500ms (I believe) and just ++ each time and call PlayerHandler.globalTick. Just another suggestion.
    Reply With Quote  
     

  10. #10  
    Registered Member LesterKnome's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    306
    Thanks given
    3
    Thanks received
    3
    Rep Power
    107
    Updated, fixed all
    I fighting for the crust of the little brown loaf
    Reply With Quote  
     

Page 1 of 2 12 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
  •