+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: Wednesday's Timer: The Centisecond Alternative (/thread-7277.html)
Wednesday's Timer: The Centisecond Alternative - DerVVulfman - 06-07-2018
Wednesday's Timer:
The Centisecond Alternative
Version: 1.0
Introduction
This script permits you to use your PC's actual time in order to create a more accurate pause system instead of using the RGSS scripted counter method. It does this by way of Ruby's built-in Time class to acquire the current time.
Script
"Look Under Here (CLICK)"
Code:
#==============================================================================
# ** Wednesday's Timer:
# The Centisecond Alternative
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 06-06-2018 (MM-DD-YYYY)
# RGSS / RPGMaker XP
#
#==============================================================================
#
# INTRODUCTION:
#
# This script permits you to use your PC's actual time in order to create
# a more accurate pause system instead of using the RGSS scripted counter
# method. It does this by way of Ruby's built-in Time class to acquire
# the current time.
#
#
#------------------------------------------------------------------------------
#
# INSTALLATION:
#
# Paste this script below Scene_Debug and above Main for it to work. As
# it rewrites some code, it may be best to be high in your script order.
# It overwrites the 'update' and 'move_type_custom' methods in Game_Char-
# acter, and overwrites the 'update' method in the 'Interpreter' class.
#
#
#------------------------------------------------------------------------------
#
# INSTRUCTIONS:
#
# Instead of using the traditional [Wait] command option in your event
# list, you use a script command instead. The script command is simply:
#
# Syntax: centi_wait( time_value )
# Properties: time_value (integer value)
# Returns: no return value
# Example: centi_second(250)
#
# The time_value is the length of time in centiseconds in which the event
# is to be delayed. For example, a time_value setting of 250 would cause
# a 2 1/2 second delay.
#
#
#------------------------------------------------------------------------------
#
# IMPORTANT:
#
# There are a few issues to note:
#
# 1) The timer is based on the PC clock, and exiting from the game screen
# does not pause the wait timer. So if you run an event with this de-
# lay system, exiting from your game and returning to it may force all
# your delayed events no longer be delayed.
#
# 2) Save Games do not work so well with this timer system for the same
# reason just described. This script's timer is based on the PC clock,
# so saving a game and later loading it would have the same effect as
# going from the game screen to another window and back.
#
# 3) The script requires rewrites in three major sections of code, two in
# the Game_Character class to handle 'move route' controlled event mo-
# vements, and one in the Interpreter class which handles basic all of
# the other basic wait commands throughout the software.
#
#
#------------------------------------------------------------------------------
#
# COMPATIBILITY:
#
# Designed for RPGMaker XP.
#
# This script overwrites three methods within, so it may conflict with
# other scripts that handle the Game_Character and the Interpreter class.
# For the experienced scripter, the code added into these three methods
# are listed below:
#
# Within The Game_Character class:
#
# This block of code exists within the 'update' method and can be found
# in this script starting on line 205.
#
# # If waiting with centisecond timer
# if @mswait_count > 0
# # Current Time Now
# time = Time.now
# # Set to Centiseconds
# temp = ((time.to_f) * 100).to_i
# # Exit on insufficient wait
# return if temp < @mswait_count
# # Reset mswait if matched or exceeded
# @mswait_count = 0
# end
#
# * * * *
#
# This block of code exists within the 'move_type_custom' method and can
# be found in this script starting on line 322.
#
# # If waiting with Centisecond timer
# if command.code = 42
# if ((command.parameters.to_s)[0,10]).upcase == "CENTI_WAIT"
# time = Time.now
# # Current time in Centiseconds
# temp = ((time.to_f) * 100).to_i
# # Set wait count
# @mswait_count = temp + eval(command.parameters[0])
# @move_route_index += 1
# return
# end
# end
#
# * * * *
#
# And within the Interpreter class:
#
# This block of code exists within the 'update' method and can be found
# in this script starting on line 521.
#
# # If waiting with centisecond timer
# if @mswait_count > 0
# time = Time.now
# # Current time in Centiseconds
# temp = ((time.to_f) * 100).to_i
# # Exit on insufficient wait
# return if temp < @mswait_count
# # Reset mswait if matched or exceeded
# @mswait_count = 0
# end
#
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Free for use, even in commercial games.
#
#==============================================================================
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias mud initialize
alias sweat force_move_route
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
mud
@mswait_count = 0
end
#--------------------------------------------------------------------------
# * Force Move Route
# move_route : new move route
#--------------------------------------------------------------------------
def force_move_route(move_route)
sweat(move_route)
@mswait_count = 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % 4
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If waiting with centisecond timer
if @mswait_count > 0
# Current Time Now
time = Time.now
# Set to Centiseconds
temp = ((time.to_f) * 100).to_i
# Exit on insufficient wait
return if temp < @mswait_count
# Reset mswait if matched or exceeded
@mswait_count = 0
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
#--------------------------------------------------------------------------
# * Move Type : Custom
#--------------------------------------------------------------------------
def move_type_custom
# Interrupt if not stopping
if jumping? or moving?
return
end
# Loop until finally arriving at move command list
while @move_route_index < @move_route.list.size
# Acquiring move command
command = @move_route.list[@move_route_index]
# If command code is 0 (last part of list)
if command.code == 0
# If [repeat action] option is ON
if @move_route.repeat
# First return to the move route index
@move_route_index = 0
end
# If [repeat action] option is OFF
unless @move_route.repeat
# If move route is forcing
if @move_route_forcing and not @move_route.repeat
# Release forced move route
@move_route_forcing = false
# Restore original move route
@move_route = @original_move_route
@move_route_index = @original_move_route_index
@original_move_route = nil
end
# Clear stop count
@stop_count = 0
end
return
end
# During move command (from move down to jump)
if command.code <= 14
# Branch by command code
case command.code
when 1 # Move down
move_down
when 2 # Move left
move_left
when 3 # Move right
move_right
when 4 # Move up
move_up
when 5 # Move lower left
move_lower_left
when 6 # Move lower right
move_lower_right
when 7 # Move upper left
move_upper_left
when 8 # Move upper right
move_upper_right
when 9 # Move at random
move_random
when 10 # Move toward player
move_toward_player
when 11 # Move away from player
move_away_from_player
when 12 # 1 step forward
move_forward
when 13 # 1 step backward
move_backward
when 14 # Jump
jump(command.parameters[0], command.parameters[1])
end
# If movement failure occurs when [Ignore if can't move] option is OFF
if not @move_route.skippable and not moving? and not jumping?
return
end
@move_route_index += 1
return
end
# If waiting
if command.code == 15
# Set wait count
@wait_count = command.parameters[0] * 2 - 1
@move_route_index += 1
return
end
# If waiting with Centisecond timer
if command.code = 42
if ((command.parameters.to_s)[0,10]).upcase == "CENTI_WAIT"
time = Time.now
# Current time in Centiseconds
temp = ((time.to_f) * 100).to_i
# Set wait count
@mswait_count = temp + eval(command.parameters[0])
@move_route_index += 1
return
end
end
# If direction change command
if command.code >= 16 and command.code <= 26
# Branch by command code
case command.code
when 16 # Turn down
turn_down
when 17 # Turn left
turn_left
when 18 # Turn right
turn_right
when 19 # Turn up
turn_up
when 20 # Turn 90° right
turn_right_90
when 21 # Turn 90° left
turn_left_90
when 22 # Turn 180°
turn_180
when 23 # Turn 90° right or left
turn_right_or_left_90
when 24 # Turn at Random
turn_random
when 25 # Turn toward player
turn_toward_player
when 26 # Turn away from player
turn_away_from_player
end
@move_route_index += 1
return
end
# If other command
if command.code >= 27
# Branch by command code
case command.code
when 27 # Switch ON
$game_switches[command.parameters[0]] = true
$game_map.need_refresh = true
when 28 # Switch OFF
$game_switches[command.parameters[0]] = false
$game_map.need_refresh = true
when 29 # Change speed
@move_speed = command.parameters[0]
when 30 # Change freq
@move_frequency = command.parameters[0]
when 31 # Move animation ON
@walk_anime = true
when 32 # Move animation OFF
@walk_anime = false
when 33 # Stop animation ON
@step_anime = true
when 34 # Stop animation OFF
@step_anime = false
when 35 # Direction fix ON
@direction_fix = true
when 36 # Direction fix OFF
@direction_fix = false
when 37 # Through ON
@through = true
when 38 # Through OFF
@through = false
when 39 # Always on top ON
@always_on_top = true
when 40 # Always on top OFF
@always_on_top = false
when 41 # Change Graphic
@tile_id = 0
@character_name = command.parameters[0]
@character_hue = command.parameters[1]
if @original_direction != command.parameters[2]
@direction = command.parameters[2]
@original_direction = @direction
@prelock_direction = 0
end
if @original_pattern != command.parameters[3]
@pattern = command.parameters[3]
@original_pattern = @pattern
end
when 42 # Change Opacity
@opacity = command.parameters[0]
when 43 # Change Blending
@blend_type = command.parameters[0]
when 44 # Play SE
$game_system.se_play(command.parameters[0])
when 45 # Script
result = eval(command.parameters[0])
end
@move_route_index += 1
end
end
end
#--------------------------------------------------------------------------
# * Centisecond Wait
# count : count in centiseconds (1/100th of a second)
#--------------------------------------------------------------------------
def centi_wait(count)
@wait_set = count
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias grime clear
#--------------------------------------------------------------------------
# * Clear
#--------------------------------------------------------------------------
def clear
grime
@mswait_count = 0 # wait count
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Initialize loop count
@loop_count = 0
# Loop
loop do
# Add 1 to loop count
@loop_count += 1
# If 100 event commands ran
if @loop_count > 100
# Call Graphics.update for freeze prevention
Graphics.update
@loop_count = 0
end
# If map is different than event startup time
if $game_map.map_id != @map_id
# Change event ID to 0
@event_id = 0
end
# If a child interpreter exists
if @child_interpreter != nil
# Update child interpreter
@child_interpreter.update
# If child interpreter is finished running
unless @child_interpreter.running?
# Delete child interpreter
@child_interpreter = nil
end
# If child interpreter still exists
if @child_interpreter != nil
return
end
end
# If waiting for message to end
if @message_waiting
return
end
# If waiting for move to end
if @move_route_waiting
# If player is forcing move route
if $game_player.move_route_forcing
return
end
# Loop (map events)
for event in $game_map.events.values
# If this event is forcing move route
if event.move_route_forcing
return
end
end
# Clear move end waiting flag
@move_route_waiting = false
end
# If waiting for button input
if @button_input_variable_id > 0
# Run button input processing
input_button
return
end
# If waiting
if @wait_count > 0
# Decrease wait count
@wait_count -= 1
return
end
# If waiting with centisecond timer
if @mswait_count > 0
time = Time.now
# Current time in Centiseconds
temp = ((time.to_f) * 100).to_i
# Exit on insufficient wait
return if temp < @mswait_count
# Reset mswait if matched or exceeded
@mswait_count = 0
end
# If an action forcing battler exists
if $game_temp.forcing_battler != nil
return
end
# If a call flag is set for each type of screen
if $game_temp.battle_calling or
$game_temp.shop_calling or
$game_temp.name_calling or
$game_temp.menu_calling or
$game_temp.save_calling or
$game_temp.gameover
return
end
# If list of event commands is empty
if @list == nil
# If main map event
if @main
# Set up starting event
setup_starting_event
end
# If nothing was set up
if @list == nil
return
end
end
# If return value is false when trying to execute event command
if execute_command == false
return
end
# Advance index
@index += 1
end
end
#--------------------------------------------------------------------------
# * Centisecond Wait
# count : count in centiseconds (1/100th of a second)
#--------------------------------------------------------------------------
def centi_wait(count)
time = Time.now
# Current time in Centiseconds
temp = ((time.to_f) * 100).to_i
# Set wait count
@mswait_count = temp + count
# Continue
return true
end
end
Instructions
In a nutshell, paste this into your script library below Scene_Debug. And use the script call 'centi_wait(time)" where time is a numeric value. A value of 100 in this call will make a 1-second delay, and a value of 2350 will make a 23 1/2 second delay.
Compatibility
Designed solely for RPGMaker XP right now. And it rewrites three methods, two in Game_Character and one in the Interpreter class. Notes have been added in the script for any would-be scripter.