Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: nathmatt on August 07, 2010, 10:00:07 am

Title: [XP] Control Config
Post by: nathmatt on August 07, 2010, 10:00:07 am
Control Config
Authors: Nathmatt
Version: 1.01
Type: control config
Key Term: Misc Add-on



Introduction
A controls config scene


Features




Screenshots

maybe later



Demo

no demo needed


Script


Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Control_Config by Nathmatt
# Version: 1.01
# Type: control config
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Control_Config
 
 def main
   @controls = Window_Controls.new
   @help_window = Window_Help.new
   @info = Window_Help.new
   @info.set_text('Control Config')
   @help_window.y = 416
   Graphics.transition
   while $scene == self
     Graphics.update
     Input.update
     update
   end
   Graphics.freeze
   @controls.dispose
   @help_window.dispose
   @info.dispose
 end
 
 def update
   @controls.update
   if @controls.index >= 0 && Input.trigger?(Input::C) && !@get_keys
     $game_system.se_play($data_system.decision_se)
     @controls.active = false
     @help_window.set_text('Press A Key')
     @wait = 6
     @get_keys = true
   end
   if Input.trigger?(Input::B) && !@get_keys
     $game_system.se_play($data_system.decision_se)
     $scene = Scene_Map.new
   end
   if @get_keys
     @wait -= 1
     return if @wait > 0
     (0..256).each{|i|
     if Input.trigger?(i)
       $game_system.se_play($data_system.decision_se)
       key = @controls.item
       Input.change(key,i)
       eval("$game_system.con_#{key.downcase} = [#{i}]")
       $game_system.contols_set = true
       @get_keys = false
       @controls.active = true
       @help_window.set_text('')
       @controls.refresh
     end}
   end
 end
 
end

class Window_Controls < Window_Selectable
 
 def initialize
   super(0,64,640,352)
   get_keys
   self.contents = Bitmap.new(width - 32, @keys.size * 32)
   @key_input = Input::Key.clone
   self.active = true
   self.index = 0
   refresh
 end
 
 def item
   return @keys[self.index][0]
 end
 
 def refresh
   get_keys
   @item_max = @keys.size
   self.contents.clear
   @keys.each_index{|i|
   self.contents.draw_text(4,i*32,120,32,@keys[i][0])
   self.contents.draw_text(200,i*32,120,32,'>>')
   self.contents.draw_text(400,i*32,200,32,@keys[i][1])}
 end
 
 def get_keys
   @key_input = Input::Key.clone
   ['NumberPad 0','NumberPad 1','NumberPad 2','NumberPad 3',
   'NumberPad 4','NumberPad 5','NumberPad 6', 'NumberPad 7','NumberPad 8',
   'NumberPad 9'].each{|key|@key_input.delete(key)}
   @keys = []
   $game_system.keys.each{|key|
   @keys.push(eval("['#{key}',@key_input.index(Input::#{key}[0])]"))}
 end
   
 
end
 
     

module Input
 
 def self.change(key,value)
   eval("#{key}[0] = #{value}")
 end
 
end

class Scene_Load < Scene_File
 
 alias set_controls_read_save_data read_save_data
 def read_save_data(file)
   set_controls_read_save_data(file)
   $game_system.set_controls
 end
 
end

class Game_System
 
 attr_accessor :contols_set,:con_up,:con_down,:con_left,:con_right,
 :con_b,:con_c,:con_l,:con_r,:con_attack,:con_defend,:con_skill,:con_item,
 :con_select,:con_hud,:con_hotkey,:con_minimap,:con_run,:con_sneak,:con_jump,
 :con_turn,:con_escape,:keys
 
 alias set_controls_initialize initialize
 def initialize
   set_controls_initialize
   @keys = ['UP','LEFT','DOWN','RIGHT','B','C','L','R']
   if $BlizzABS != nil
     @keys.push('Attack','Defend','Skill','Item','Select','Hud','Hotkey',
     'Minimap','Run','Sneak','Jump')
   end
   if $Battle_Dome != nil
     @keys.push('Escape')
   end
   @keys.each{|key|
   eval("@con_#{key.downcase} = Input::#{key}[0]")}
 end
   
 def set_controls
   return if !@contols_set
   @keys.each{|key|
   eval("Input.change('#{key}',@con_#{key.downcase})")}
 end
 
end



Instructions

Requires Blizz-ABS, RMXOS, or Tons custom controls
place below the one you use



Compatibility

No compatibility issues known



Credits and Thanks




Author's Notes

if you have any issues / suggestions post here
Title: Re: [XP] Control Config
Post by: element on August 07, 2010, 04:16:47 pm
This looks Incredeably usefull.
I'd test it if there was a demo but don't have teh time to ploace it in a project now.
Maybe i'll test it tomorrow though  :)
Title: Re: [XP] Control Config
Post by: legacyblade on August 08, 2010, 02:24:49 am
Why isn't this in the database yet?
Title: Re: [XP] Control Config
Post by: G_G on August 08, 2010, 02:28:10 am
Psh what you talkin bout
Title: Re: [XP] Control Config
Post by: Hellfire Dragon on August 09, 2010, 10:36:52 am
Seems very useful :D

I was testing it with Blizz ABS, how do you call the scene? I tried $scene = Control_Config.new the config screen shows but I can't do anything except cancel it.
Title: Re: [XP] Control Config
Post by: nathmatt on August 09, 2010, 01:14:20 pm
i bet i 4got to set the index to 0 i was using mouse controller when i made it

update: 1.01 fixed index bug
Title: Re: [XP] Control Config
Post by: element on August 09, 2010, 01:27:03 pm
I tested it today, I love it  :) *Lvls up*
Title: Re: [XP] Control Config
Post by: Hellfire Dragon on August 09, 2010, 04:38:14 pm
Working perfectly now :) Just a little suggestion, how about a way to change what the buttons are called. For example, there's 'B' option, so say I wanted it to say 'Menu' instead. I tried just changing it, which I thought wouldn't work anyway, and it didn't,
Quote
NameError  occurred while running script.

unintialized constant Input:Menu

:P
Title: Re: [XP] Control Config
Post by: nathmatt on August 09, 2010, 06:04:04 pm
i would but im using eval on the name of the command to shorten the code which means i set the input key with the name of the command
Title: Re: [XP] Control Config
Post by: Hellfire Dragon on August 10, 2010, 07:20:24 am
Oh well, still an awesome script that should included in every Blizz ABS game :roll:
Title: Re: [XP] Control Config
Post by: Blizzard on August 12, 2010, 08:13:52 am
Nathmatt, you messed up the header of the template again. -_- *fixes* You had "Authors:Nathmatt " instead of "Authors: Nathmatt"
Title: Re: [XP] Control Config
Post by: nathmatt on August 12, 2010, 12:04:26 pm
didn't know i was doing that will pay more attention
Title: Re: [XP] Control Config
Post by: Blizzard on August 12, 2010, 12:34:03 pm
Just take a second look the next time to make sure it's alright. ^_^

You can also check it in the index. If the link is messed up in the table somehow, it means you made a mistake in the header.