Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Super Simple No-Lag Timers
amaranth
post Dec 21 2008, 08:52 PM
Post #1


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Introduction
This script lets you create as many timers as you want without causing your game to lag. It's great if you want events to occur only after a specific amount of time has passed. For example, you go to a village, come back in 30 minutes, and a chicken has laid an egg.

This script contains two timers. You can always add more (I'll discuss below).

Update Game_System
In this section, we are going to add two timers.

1. Open your game and script editor.

2. In Game_System, add these methods at the bottom of the file, but above the last end tag:

CODE
  #--------------------------------------------------------------------------
  # ● set the current time to a variable (set timer)
  #--------------------------------------------------------------------------  
  def set_time(num)
    
      @total_sec = Graphics.frame_count / Graphics.frame_rate
      time = @total_sec/60 # minutes /60, hour /60 /60

      case num
        when 1 # Timer 1
            $game_variables[1] = time
        when 2 # Timer 2
            $game_variables[2] = time
        end
      
  end
  
  #--------------------------------------------------------------------------
  # ● compare two times
  #--------------------------------------------------------------------------  
  def get_time()
      @total_sec = Graphics.frame_count / Graphics.frame_rate
      time = @total_sec/60 # minutes
      $game_variables[10] = time  #Timer: in-game variable
  end


3. Save your script.

Create Timers Variables
Once your timers are added to your script, you can turn them on and off with variables.

Note: The number assigned to each data entry needs to match the number assigned to each switch. For example, @data[2] = "Get milk for Ma" | 0002: Help Ma.


1. Add a new event to one of your maps.

2. Open the Event Commands window.

3. Click Control Variables and add the following:
0001: Start Timer 1 (Blue Egg)
0002: Start Timer 2 (Brown Egg)
0010: Current Time

0011: Stop Timer 1 (Blue Egg)
0012: Stop Timer 2 (Brown Egg)
0020: Lay Blue Egg
0021: Lay Brown Egg

4. Save and delete event.

Create An Event that Starts Timer 1
Use this event to start Timer 1.

1. Add a new event to one of your maps.

2. Open the Event Commands window.

3. Click Script and enter: $game_system.set_time(1)

4. Save your work and close the Edit Event dialog box.

Repeat these steps for Timer 2. In step 3, replace 1 with 2.

Create An Event that Checks if Timer 1 has Finished
Use this event to stop Timer 1.

1. Add a new event to one of your maps.

2. Open the Event Command Window.

3. Command Window > Script. Enter: $game_system.get_time(). Save.

4. Command Window > Control Variables. To the right of Single, select 0011: Stop Timer 1. Select the = operator. To the right of Variable, select 0010: Current Time. Save.

7. Command Window > Control Variables. To the right of Single, select 0011: Stop Timer 1. Select the - operator. To the right of Variable, select 0001: Start Timer 1. Save.

9. Command Window > Click Control Branch > To the right of Variable, select 0011: Stop Timer 1. Select Greater than. To the right of Constant, enter the amount of minutes for the timer. For example, 60. Save.

10. Inside the conditional branch, put the commands that should happen when the timer has finished.



Repeat these steps for Timer 2, using timer 2 variables.

How do I add more Timers?
Adding new timers is easy! Open the script editor and go to Game_System. Add a new entry to def set_time(num) as follows:

def set_time(num)

@total_sec = Graphics.frame_count / Graphics.frame_rate
time = @total_sec/60 # minutes

case num
when 1 # Timer 1
$game_variables[1] = time
when 2 # Timer 2
$game_variables[2] = time
when 3 # Timer 3
$game_variables[3] = time

end

end


__________________________
Go to the top of the page
 
+Quote Post
   
Blizzard
post Dec 22 2008, 03:12 AM
Post #2


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




Uhm... Why does one need a script for a timer?


__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   
amaranth
post Dec 22 2008, 11:45 AM
Post #3


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




The default timers cause lag... especially if you have more than one running.


__________________________
Go to the top of the page
 
+Quote Post
   
Blizzard
post Dec 23 2008, 02:50 AM
Post #4


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




Oh no, you misunderstood what I meant. You really don't need a script for that.



__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   
woratana
post Dec 23 2008, 07:04 AM
Post #5


Looking for scripter to hire? PM me *O*
Group Icon

Group: +Gold Member
Posts: 1,038
Type: Scripter
RM Skill: Undisclosed




I didn't know timers cause lag, since I've never use multiple timers at a time. As in Blizzard's post, this can be done without script, unless you want to show timer on the screen (This part is also can be done with event, but script is easier). Anyway, thanks for sharing your script here. I'm sure someone will find this useful. ^^


__________________________
Check out my NEW blog!!!



MVP (Most Valuable Poster) Award 2008


Go to the top of the page
 
+Quote Post
   
Blizzard
post Dec 23 2008, 03:35 PM
Post #6


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




Generally sprites cause lag. Just storing the value of a variable and restoring it doesn't cause any lag at all.


__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 11:56 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker