Timed User Input - Lite Version
Authors: Diagostimo, Heretic
Version: 1.0
Type: Simulated User Input
Key Term: Misc System
IntroductionThis Script is intended to allow you to Simulate User Input in ANY Scene at ANY time by entering a series of simple script commands.
Features
- Simulate User Input at specific times
- Very easy to use
- Highly Compatible
- I like shiny things
ScreenshotsNo Screenshots.
It isnt possible to take a Screenshot of simulating User Input.
DemoThis Demo contains a FULL VERSION of the script with expandad functionality.
http://www.775.net/~heretic/downloads/rmxp/AnimatedTitleScreen/index.php (http://www.775.net/~heretic/downloads/rmxp/AnimatedTitleScreen/index.php)
ScriptThis is the LITE VERSION of the User Input Script. It does NOT contain the expanded functionality provided by the FULL VERSION, but will be more compatible.
Place above Main.
#===============================================================================
#
# Timed User Input
# Authors: Diagostimo, Heretic
# Version 1.0
# Saturday, November 9th, 2012
#
#===============================================================================
#
# This script is the work of Diagostimo and Heretic
#
# Keys can be entered either by saying B or C instead of Input::B or Input::C
# This works for directions also: DOWN or UP instead of Input::DOWN or Input::UP
#
# ALWAYS USE ALL CAPITAL LETTERS FOR YOUR KEYS!
#
# There are two ways to use this script.
#
# 1: Single Keypress
# In an Event, run a Script:
# Input.change_key(Key)
#
# * Most useful when used in Parallel or Autorun processes
#
#
# 2: Automated Keypress
# In an Event, run a Script:
# timed_input(wait, keys)
#
# - Examples -
#
# timed_input(20, C) Effect: Waits 20 frames, then simulates the C Key
# timed_input(14, DOWN, C) Effect: Waits 14 frames, and simulates DOWN and C
# timed_input(40) Effect: This just waits. May sometimes be useful.
#
# NOTE: Build your Input Sequences BEFORE bringing up any Menus
#
# NOTE: Use "Call Menu Screen" on Page 3 of Event Commands instead of trying
# to use "B" to bring up the Menu. It wont work because an Event is
# doing its thing.
#
# NOTE: You cant use this script to simulate Player Movement, the same way
# as you are unable to move (by default) while an Event is processing.
#
#
# This Script is a simlified version of Timed User Input, Scripts, and Windows.
#
# It lacks the expanded functionality of the other version of the script, but
# will be more compatible. It works a bit differently as well, but may be
# easier to use with Custom Battle System Menus due to the differences.
#
# --- TIMING DIFFERENCES in XP and VX / Ace ---
#
# The Timing in XP and VX / VX Ace is a bit different.
#
# In XP, 1 second is 20 Frames, and usually runs at 40 Frames Per Second so
# value is multiplied by two
#
# In VX and VX Ace, 1 second is 60 Frames Per Second and isnt multiplied
#
#
# --- LEGAL STUFF ---
#
# Legal: This script is not my property and is used with permission
# from diagostimo. It has been modified by Heretic to be easier to use.
module Input_Constants
DOWN = Input::DOWN
LEFT = Input::LEFT
RIGHT = Input::RIGHT
UP = Input::UP
A = Input::A
B = Input::B
C = Input::C
X = Input::X
Y = Input::Y
Z = Input::Z
L = Input::L
R = Input::R
end
module RPG
# Timing for XP and VX is different, 20 FPS is 1 second in XP 60 in VX and Ace
Input_Time_Multiplier = defined?(Game_Interpreter) ? 1 : 2
# Create New Class
class TimedInput
# Mixed Variable and Array types are easier as Objects
def initialize(wait, parameters = [])
# Time to wait before simulating keystrokes
@wait = wait * Input_Time_Multiplier
# The Input Keys to be Simulated - Handles Multiple Keys
@parameters = parameters
end
attr_accessor :wait
attr_accessor :parameters
end
end
# Interpreter is named differently in VX and XP
Intepreter_Name = defined?(Game_Interpreter) ? Game_Interpreter : Interpreter
class Intepreter_Name
include Input_Constants
def timed_input(wait, *keys)
Input.change_auto_keys(RPG::TimedInput.new(wait, keys))
end
def clear_auto
Input.init
end
end
class Game_Character
include Input_Constants
def timed_input(wait, *keys)
Input.change_auto_keys(RPG::TimedInput.new(wait, keys))
end
def clear_auto
Input.init
end
end
module Input
# If class is already defined - F12 Reset
if $input_class_defined
# Reset associated variables defined in def init
init
else
# Store Global Variable that modifications to input class have been defined
$input_class_defined = true
class << self
#alias listing
alias update_forced update
alias trigger_forced trigger?
alias press_forced press?
alias repeat_forced repeat?
alias dir4_forced dir4
alias dir8_forced dir8
#initialize
def init
@forced = nil
@auto_forced = []
@auto_index = 0
@auto_timer = 0
@auto_input_time = false
@input_forced = false
@input_disabled = false
end
def change_input_flag
@auto_input_time = true
end
#change forced value
def change_key(key)
@forced = key
end
#change auto forced keys
def change_auto_keys(object)
@auto_forced.push(object)
@auto_timer = @auto_forced[0].wait
@auto_input_time = true
@input_disabled = true
end
#modified Input.update method
def update
if @auto_input_time
if @auto_timer == 0
if @auto_index == @auto_forced.size - 1
@auto_index = 0
@auto_input_time = false
@input_disabled = false
@auto_forced = []
elsif @auto_forced.size > 0
@auto_index += 1
@auto_timer = @auto_forced[@auto_index].wait
return
end
end
@auto_timer -= 1 if @auto_timer > 0
end
@forced = nil
@input_forced = false
# Original Input.update method
update_forced
end
# called by press?, trigger? and repeat?
def auto_forced?(key)
if @auto_input_time && @auto_timer == 0 && @auto_forced.size > 0
# auto_group is an Array of Keys that when checked return true
auto_group = @auto_forced[@auto_index].parameters
(0...auto_group.size).each {|i|
if auto_group[i] == key
@input_forced = true
return true
end
}
end
return false
end
# these return true if input check is forced
def trigger?(key)
return true if auto_forced?(key) or @forced == key
return false if @input_disabled
trigger_forced(key)
end
def press?(key)
return true if auto_forced?(key) or @forced == key
return false if @input_disabled
press_forced(key)
end
def repeat?(key)
return true if auto_forced?(key) or @forced == key
return false if @input_disabled
repeat_forced(key)
end
def dir4
dir = dir4_forced
return dir if auto_forced?(dir) or @forced == dir
return 0 if @input_disabled
return dir
end
def dir8
dir = dir8_forced
return dir if auto_forced?(dir) or @forced == dir
return 0 if @input_disabled
return dir
end
def input_forced?
return true if @input_forced or @forced
end
end
end
end
#calling the initialize method
Input.init
InstructionsHow to use:
timed_input(wait=n, key)
Wait is Wait Time in Frames before simulating the key as the Button pressed.
Key is a CAPITAL LETTER of the corresponding Input Key or WORD. That means you dont need to put in Input::DOWN, you can just put in the word DOWN in all capital letters.
See Script and Demo for examples.
CompatibilityI believe this will be nearly 100% compatible with other Scripts, including other Input Scripts! If there are any compatability issues, please let me know and I'll do my best to correct them.
Credits and Thanks
- Diagostimo for providing the original code that was expanded on.
- I'd like to thank the Academy...
Author's NotesMy goal with this script is to reach as close to a 100% compatability rating as I can get.
NOTE: There are TWO VERSIONS of this Script. This is the LITE VERSION. Both versions are very similar, but for sake of compatability, a LITE VERSION was born. Some of the features in the Full Version may not be needed at all, but they may also lower the compatability.
The Lite Version is compatible with RMXP, RMVX, and RMVXA.
Update: Minor update to fix compatability with VX and Ace. Verified as compatible in all versions.
--------------------------------------------------------------------------------
NOT compatible with VX and VX-Ace
Quote
VX = defined?(Window_ActorCommand)
eval "
class Interpreter #{VX ? 'Game_Interpreter' : 'Interpreter'}
include Input_Constants
def timed_input(wait, *keys)
Input.change_auto_keys(RPG::TimedInput.new(wait, keys))
end
def clear_auto
Input.init
end
end#"
now you can call that compatible with VX and VX-Ace
There may be no need to use eval.
is it bad to use eval?
It really depends. eval can be a good way to make a program interactive with the user or if complex code can be generated on the fly, but these systematic approaches are usually very rarely needed. e.g. I have a Ruby prompt in RMX-OS on the server which is a fairly good use of eval. I also use eval for decoding of data, e.g. I get 1,2,3,4,5, then I add [ and ] and run eval on that. It may not be the safest way for the client/server to interpret data, but it makes things a lot easier. In other cases eval should be avoided, especially in code declaration such as methods and classes.
I was not aware that the classes had been renamed in later versions of RPG Maker. I do recall seeing something in a script somewhere that $DEBUG is also different in VX and Ace. Is there a better / safer (non eval) way to detect RPG Maker Version (IE: XP, VX, Ace) and process accordingly?
While Im at it, I just tested out the full version with BlizzABS in Sir Lags-A-Lot, and it seems to work just fine. How would I put in a command entry for a Keypress in Blizz? The Constants of UP and DOWN seem to work, just not sure how to do grab keys for BlizzABS. As far as I can tell, this could also be used as a BlizzABS Plugin as well!
you don't have to think too hard
QuoteVX = defined?(Window_ActorCommand)
Intr = VX ? Game_Interpreter : Interpreter
class Interpreter Intr
include Input_Constants
def timed_input(wait, *keys)
Input.change_auto_keys(RPG::TimedInput.new(wait, keys))
end
def clear_auto
Input.init
end
end
ah, by the way this is kinda off topic but this script does similar things with FTS - Key Simulator (http://forum.chaos-project.com/index.php/topic,2310.0.html)
(except the timer and the keyboard button)
What I meant to ask is are there any Global Variables or Methods or some other such thing that we can use to check for XP / VX and / or Versions?
For example RPG::Game_Version returning ["XP","1.07a"] or ["VX","1.13f"] or something to that effect?
Not that your method doesnt work, it works just fine, I'm just wondering if there was anything already built into the engine...
... or do it this way?
# Interpreter is named differently in VX and XP
Intepreter_Name = defined?(Game_Interpreter) ? Game_Interpreter : Interpreter
(Sorry for the delay, I've felt like crap for the last couple days.)
Quote from: Heretic86 on November 12, 2012, 07:39:59 pm
What I meant to ask is are there any Global Variables or Methods or some other such thing that we can use to check for XP / VX and / or Versions?
For example RPG::Game_Version returning ["XP","1.07a"] or ["VX","1.13f"] or something to that effect?
Not that your method doesnt work, it works just fine, I'm just wondering if there was anything already built into the engine...
さあ~ I didn't know about that but as far as I know there aren't
Quote from: Heretic86 on November 12, 2012, 07:39:59 pm
... or do it this way?
# Interpreter is named differently in VX and XP
Intepreter_Name = defined?(Game_Interpreter) ? Game_Interpreter : Interpreter
(Sorry for the delay, I've felt like crap for the last couple days.)
there are high possibility some scripter using
Game_Interpreter to make his script compatible with XP / VX
it's too risky if you use
defined?(Game_Interpreter) and much safer if you use something that most scripter don't aware of it
Window_ActorCommand XP = didn't exist VX = exist VXA = exist
| Window_BattleActor XP = didn't exist VX = didn't exist VXA = exist |