[XP][VX][VXA] Timed User Input - Lite Version

Started by Heretic86, November 10, 2012, 09:40:14 am

Previous topic - Next topic

Heretic86

November 10, 2012, 09:40:14 am Last Edit: November 12, 2012, 08:54:55 pm by Heretic86
Timed User Input - Lite Version
Authors: Diagostimo, Heretic
Version: 1.0
Type: Simulated User Input
Key Term: Misc System



Introduction

This 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




Screenshots

No Screenshots.

It isnt possible to take a Screenshot of simulating User Input.


Demo

This Demo contains a FULL VERSION of the script with expandad functionality.

http://www.775.net/~heretic/downloads/rmxp/AnimatedTitleScreen/index.php


Script

This 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.
Spoiler: ShowHide

#===============================================================================
#
#           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




Instructions

How 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.


Compatibility

I 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 Notes

My 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.
--------------------------------------------------------------------------------
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

November 10, 2012, 10:31:09 pm #1 Last Edit: November 12, 2012, 09:23:37 pm by LiTTleDRAgo
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

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

LiTTleDRAgo


Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Heretic86

November 12, 2012, 04:44:11 am #5 Last Edit: November 12, 2012, 05:22:02 am by Heretic86
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!
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

November 12, 2012, 09:07:20 am #6 Last Edit: November 12, 2012, 09:23:16 pm by LiTTleDRAgo
you don't have to think too hard
Spoiler: ShowHide
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
(except the timer and the keyboard button)

Heretic86

November 12, 2012, 07:39:59 pm #7 Last Edit: November 12, 2012, 08:56:00 pm by Heretic86
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...

Spoiler: ShowHide
... 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.)
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

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
Spoiler: ShowHide
... 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

Spoiler: ShowHide
Window_ActorCommand                                       
XP = didn't exist
VX = exist
VXA = exist
Window_BattleActor
XP = didn't exist
VX = didn't exist
VXA = exist