#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Mouse Controller Enhancement Script by Nathmatt
# Version: 1.44
# Type: Add On
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# 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.
# #
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Instrutions:
#
# To use the event effects in this script you will need to name the following.
#
# defenitions
# w = the events width must be atleast 1
# h = the events height must be atleast 1
# d = 2 down, 4 left 6, right, or 8 up
# right click to acess an events command list
#
# \direction[d] If an event has no graphic or isn't direction specific
# they must be named this d as the open direction
#
# \commands[w,h] This will create a command list for each page with the
# name of the first avalible comment
#
# \curser[w,h,graphic] This will change the graphic of the curser while
# over that event
#
# \auto[w,h] This will start the event as soon as you click it
#
# \door[w,h,id] This will run the pages of an event as the following
# id is the item id needed to unlock the door
# first page when door is locked
# secound page when unlocking the door
# third page any time after being unlocked
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Script Calls:
#
# $MCES.disabled = true/false whether or not this script is disabled
#
# $MCES.movement_disabled = true/false whether or not movement is disabled
#
# $MCES.pick_up(id) is the id of the item that is picked up
#
# $MCES.drop drops the item
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module Mouse_Controller_Enhancement_Script
Version = 1.44
module Config
Cant_go = 7 # The terrain tag for unreachable locations
Size = 20 # The size of the event name text
Color = Color.new(0,0,160,255) # The color of the event name text
Grab = false # false or the graphic for when you have
# an item in hand
end
#============================================================================
# ** Processor
#----------------------------------------------------------------------------
# This class performs the mouse processing.
#============================================================================
class Processor
attr_accessor :disabled,:movement_disabled,:wait
attr_reader :event_start,:item
def initialize
@disabled = false
@movement_disabled = false
@event_start = false
@unlock = []
@wait = 5
end
def update
return if @disabled
if !$scene.is_a?(Scene_Map)
@wait = 5
return
end
@int = $game_system.map_interpreter
@wait -= 1 if @wait > 0
@x,@y = $mouse.pos
if Input.trigger?(Input::Key['Mouse Right']) &&
!$game_temp.message_window_showing && @wait == 0
@wait = 5
check_right
elsif Input.trigger?(Input::Key['Mouse Left']) &&
!$game_temp.message_window_showing && @wait == 0
@wait = 5
check_left
end
force_moving if !$game_player.moving?
@commands.update if @commands != nil
check_mouse
check_item
check_finished
get_path
end
def check_left
check_events_left
check_tile
check_command
end
def check_right
check_events_right
end
def check_finished
return if @request == nil
if $game_player.x == @request.tx &&
$game_player.y == @request.ty
if @id != nil
turn_toward_event
@event_start = true
$game_map.events[@id].start
@event_start = false
end
@result = nil
@get_path = false
@id = nil
@request = nil
end
end
def check_events_left
$game_map.events.each_value{|event|
check_auto(event)
check_door(event)
check_event(event)}
end
def check_command
return if @commands == nil || @command_event == nil
if @commands.indexes >= 0 && @commands.index >= 0
event = @command_event
i = @commands.indexes
@int.setup(event.rpg_event.pages[i].list,event.id)
end
@commands.dispose
@commands = nil
@movement_disabled = false
end
def check_commands(event)
return if $game_map.commands[event.id] == nil || @commands != nil
if event.x == @x && event.y == @y || get_size(event)
@commands = Event_Command.new(event.commands)
@commands.x = event.screen_x
@commands.y = event.screen_y
@commands.z = 5000
@command_event = event
@movement_disabled = true
end
end
def check_events_right
$game_map.events.each_value{|event|
check_commands(event)}
end
def check_auto(event)
return if event.character_name == '' || !$game_map.auto[event.id]
if event.x == @x && event.y == @y || get_size(event)
@event_start = true
event.start
@event_start = false
end
end
def check_event(event)
return if $game_map.auto[event.id] || @movement_disabled
if event.x == @x && event.y == @y
@id = event.id
@d = ($game_map.event_direction[@id] != nil ?
$game_map.event_direction[@id]: $game_map.events[@id].direction)
case @d
when 2 then @y += 1
when 4 then @x -= 1
when 6 then @x += 1
when 8 then @y -= 1
end
request_path(@x, @y)
@result = nil
@get_path = true
end
end
def check_tile
return if @get_path || !$game_map.passable?(@x,@y,0) ||
@movement_disabled || check_terrain_tag || get_size
request_path(@x, @y)
@result = nil
@get_path = true
end
def check_door(event)
return if $game_map.door[event.id] == nil
if $game_map.door[event.id] == @item.id
@int.setup(event.rpg_event.pages[1].list,event.id)
$game_party.gain_item(@item.id, -1)
change_graphic
@unlock[event.id] = true
elsif @unlock[id]
@int.setup(event.rpg_event.pages[2].list,event.id)
else
@int.setup(event.rpg_event.pages[0].list,event.id)
end
return
end
def check_mouse
$game_map.events.each_value{|event|
if @x == event.x && @y == event.y || get_size(event)
$mouse.change_graphic($game_map.mouse_over_icons[event.id])
check_message(event)
else
$mouse.change_graphic
end}
end
def check_message(event)
if $game_map.msg[event.id] != nil
if @sprite == nil || @map != $game_map.map_id || @last_id != event.id
@map = $game_map.map_id
@last_id = event.id
@sprite = Sprite.new
@sprite.z = 1000
@sprite.bitmap = Bitmap.new(640,32)
@sprite.bitmap.font.size = Config::Size
@sprite.bitmap.font.color = Config::Color
@w = @sprite.bitmap.text_size($game_map.msg[id]).width
h = @sprite.bitmap.text_size($game_map.msg[id]).height
@sprite.bitmap.draw_text(0,0,@w,h,$game_map.msg[id].to_s)
end
@sprite.x = $game_map.events[id].screen_x - (@w / 2)
@sprite.y = $game_map.events[id].screen_y - 64
elsif @sprite != nil
@sprite.dispose
@sprite = nil
end
end
def check_item
if @item != nil
if @cursor == nil
@cursor = Sprite.new
@cursor.z = 1000000
@cursor.bitmap = RPG::Cache.icon(@item.icon_name)
end
@cursor.x , @cursor.y = $mouse.position
@cursor.x -= 5
@cursor.y += 5
elsif @cursor != nil
@cursor.dispose
@cursor = nil
end
end
def check_terrain_tag
if $game_map.terrain_tag(@x, @y) == Config::Cant_go
return true
end
end
def get_size(event = nil)
if event == nil
$game_map.events.each_value{|event|
return $game_map.size[event.id] != nil &&
$game_map.size[event.id]['X'].include?(@x) &&
$game_map.size[event.id]['Y'].include?(@y)}
end
return $game_map.size[event.id] != nil &&
$game_map.size[event.id]['X'].include?(@x) &&
$game_map.size[event.id]['Y'].include?(@y)
end
def get_path
if @get_path && @result == nil
@result = find_path
end
end
def pick_up(id)
@item = $data_items[id]
$mouse.change_graphic(Config::Grab) if Config::Grab != false
end
def drop
@item = nil
$mouse.change_graphic
end
def force_moving
return if @result == nil || @result == []
$network.send_player_data if $network != nil
case @result[0][0]
when 2 then $game_player.move_down
when 4 then $game_player.move_left
when 6 then $game_player.move_right
when 8 then $game_player.move_up
end
@result.shift
end
def turn_toward_event
case @d
when 2 then $game_player.turn_up
when 4 then $game_player.turn_right
when 6 then $game_player.turn_left
when 8 then $game_player.turn_down
end
end
def request_path(x, y = nil)
# if request does not exist yet
if x != nil && y != nil && @request == nil
# add request
@request = PathRequest.new(x, y)
end
end
def find_path
char = $game_player
# get pixel movement rate
pix = 1
# use request
request = @request
# if no nodes to test
if request.open.size == 0
# abort testing for this character
@request = nil
# stop execution
return []
end
# found
found = false
# find minimal key
key = request.open.keys.min {|a, b|
Math.hypot(a[0] - request.tx, a[1] - request.ty) <=>
Math.hypot(b[0] - request.tx, b[1] - request.ty)}
# this node is now logged as checked
request.closed[key[0], key[1]] = request.open[key]
# remove this node from the pending array
request.open.delete(key)
# iterate through all possible directions with relative offsets
pathDirs = [[0, 1, 2], [-1, 0, 4], [1, 0, 6], [0, -1, 8]]
pathDirs.each {|dir|
# coordinates of new position
kx, ky = key[0] + dir[0], key[1] + dir[1]
# if new coordinates are destination
if kx == request.tx && ky == request.ty
# the new node was checked
request.closed[kx, ky] = dir[2]
# path was found
found = true
# stop checking
break
# if new node not checked yet and coordinates are passable
elsif request.closed[kx, ky] == 0 &&
char.passable?(key[0] * pix, key[1] * pix, dir[2])
# add new node to be checked
request.open[[kx, ky]] = dir[2]
end}
# stop execution except if found path
return nil unless found
# backtrack the path
result = request.backtrack
# finish testing for this character
return result
end
end
class PathRequest
# setting all accessible variables
attr_reader :open
attr_reader :closed
attr_reader :sx
attr_reader :sy
attr_reader :tx
attr_reader :ty
def initialize(tx, ty)
a = $game_player
@sx, @sy, @tx, @ty = a.x, a.y, tx, ty
@x_off, @y_off = a.x - @sx, a.y - @sy
@open = {[@sx, @sy] => -1}
@closed = Table.new($game_map.width, $game_map.height)
end
def backtrack
pix = 1
tdirs = [[0, true], [1, true], [2, true], [3, true], [4, true], [5, true],
[6, true], [7, true], [8, true], [9, true]]
dirOffsets = [[0, 0], [-1, 1], [0, 1], [1, 1], [-1, 0], [0, 0], [1, 0],
[-1, -1], [0, -1], [1, -1]]
cx, cy, x, y, result = @tx, @ty, 0, 0, []
loop do
cx, cy = cx - x, cy - y
break if cx == @sx && cy == @sy
pix.times {result.unshift(tdirs[@closed[cx, cy]])}
x, y = dirOffsets[@closed[cx, cy]]
end
return result
end
end
end
class Mouse
def pos
return if $game_map.display_x == nil
x, y = self.position
x = ( x + $game_map.display_x / 4) / 32
y = ( y + $game_map.display_y / 4) / 32
return x, y
end
def change_graphic(graphic = nil)
if graphic != nil
@cursor.bitmap = RPG::Cache.picture(graphic)
@graphic = graphic
elsif @cursor.bitmap != RPG::Cache.picture(MOUSE_ICON)
@cursor.bitmap = RPG::Cache.picture(MOUSE_ICON)
end
end
end
class Event_Command < Window_Command
def initialize(commands)
@size = 0
@main_commands = commands
@array = []
commands.each{|command|
@array.push(command) if command != nil
@size = (commands.size * 32) if (commands.size * 32) > @size}
super(@size,@array)
end
def indexes
return @main_commands.index(@array[self.index])
end
end
class Game_Event < Game_Character
attr_reader :first
alias page_name initialize
def initialize(m,e)
@first = {}
page_name(m,e)
end
def start
return if @trigger == 0 && !$MCES.event_start
if @list.size > 1
@starting = true
end
end
def rpg_event
return @event
end
def commands
com = []
@event.pages.each{|page|
page.list.each{|list|
@last_list = list if @last_list == nil
if list.code == 108
if check_condition(@last_list)
com[@event.pages.index(page)] = list.parameters[0]
end
end
@last_list = list}}
return com
end
def check_condition(list)
return false if list.code == 411 && @result
return true if list.code != 111
result = false
par = list.parameters
case par[0]
when 0
result = ($game_switches[par[1]] == (par[2] == 0))
when 1
value1 = $game_variables[par[1]]
value2 = (par[2] == 0 ? par[3] : $game_variables[par[3]])
case par[4]
when 0
result = (value1 == value2)
when 1
result = (value1 >= value2)
when 2
result = (value1 <= value2)
when 3
result = (value1 > value2)
when 4
result = (value1 < value2)
when 5
result = (value1 != value2)
end
when 2
if @id > 0
key = [$game_map.map_id, @id, par[1]]
if par[2] == 0
result = ($game_self_switches[key] == true)
else
result = ($game_self_switches[key] != true)
end
end
when 3
if $game_system.timer_working
sec = $game_system.timer / Graphics.frame_rate
if par[2] == 0
result = (sec >= par[1])
else
result = (sec <= par[1])
end
end
when 4
actor = $game_actors[par[1]]
if actor != nil
case par[2]
when 0
result = ($game_party.actors.include?(actor))
when 1
result = (actor.name == parameters[3])
when 2
result = (actor.skill_learn?(parameters[3]))
when 3
result = (actor.weapon_id == parameters[3])
when 4
result = (actor.armor1_id == par[3] || actor.armor2_id == par[3] ||
actor.armor3_id == par[3] || actor.armor4_id == par[3])
when 5
result = (actor.state?(par[3]))
end
end
when 5
enemy = $game_troop.enemies[par[1]]
if enemy != nil
case par[2]
when 0
result = (enemy.exist?)
when 1
result = (enemy.state?(par[3]))
end
end
when 6
character = get_character(par[1])
if character != nil
result = (character.direction == par[2])
end
when 7
if parameters[2] == 0
result = ($game_party.gold >= par[1])
else
result = ($game_party.gold <= par[1])
end
when 8
result = ($game_party.item_number(par[1]) > 0)
when 9
result = ($game_party.weapon_number(par[1]) > 0)
when 10
result = ($game_party.armor_number(par[1]) > 0)
when 11
result = (Input.press?(par[1]))
when 12
result = eval(par[1])
end
@result = result
return result
end
end
module Input
class << Input
alias update_mouse_enhancement_later update
end
def self.update
$MCES.update
update_mouse_enhancement_later
end
end
$MCES = Mouse_Controller_Enhancement_Script::Processor.new
class Game_Map
attr_reader :map
attr_reader :mouse_over_icons
attr_reader :event_direction
attr_reader :commands
attr_reader :msg
attr_reader :auto
attr_reader :info
attr_reader :door
attr_reader :size
attr_accessor :event_index
alias setup_mouse_path_finder_later setup
def setup(map_id)
setup_mouse_path_finder_later(map_id)
check_names
end
def check_names
@mouse_over_icons = []
@event_direction = []
@commands = []
@event_index = []
@msg = []
@auto = []
@door = []
@size = []
$game_map.events.each_key {|i|
check_event_names(i) if $game_map.events[i] != nil}
end
def check_event_names(event_id)
event = @map.events[event_id]
if event.name.clone.gsub!(/\\[Cc]ommands\[([\d, ]+)\]/) {"#[$1]"}
array = eval("[#{$1}]")
@commands[event_id] = true
end
if event.name.clone.gsub!(/\\[Cc]urser\[([\S, ]+)\]/) {"#[$1]"}
array = eval("[#{$1}]")
end
if event.name.clone.gsub!(/\\[Mm]sg\[(.+?)\]/) {"#[$1]"}
@msg[event_id] = $1.to_s
end
if event.name.clone.gsub!(/\\[Dd]irection\[(\d)\]/) {"#[$1]"}
@event_direction[event_id] = $1.to_i
end
if event.name.clone.gsub!(/\\[Aa]uto\[([\d, ]+)\]/) {"#[$1]"}
array = eval("[#{$1}]")
@auto[event_id] = true
elsif event.name.clone.gsub!(/\\[Dd]oor\[([\d, ]+)\]/) {"#[$1]"}
array = eval("[#{$1}]")
@door[event_id] = array[2]
end
if array != nil
@size[event_id] = {}
@size[event_id]['X'] = []
@size[event_id]['Y'] = []
sx = event.x - ((array[0] - 1) / 2)
sy = event.y - (array[1] - 1)
ex = ((array[0] - 1) / 2) + event.x
ey = event.y
(sx..ex).each {|i| @size[event_id]['X'].push(i)}
(sy..ey).each {|i| @size[event_id]['Y'].push(i)}
end
end
end
if $network != nil
class Scene_Map
alias mces_create_trade_windows create_trade_windows
def create_trade_windows
$MCES.movement_disabled = true
mces_create_trade_windows
end
alias mces_dispose_trade_windows dispose_trade_windows
def dispose_trade_windows
$MCES.movement_disabled = false
mces_dispose_trade_windows
end
end
end