Okay Ty🙂
Amaranth's Super Simple Mouse System for Ace
RGSS3 Scripts (RMVX Ace)Broken Link! Can someone pass the script for me?
Introduction
This is a complete overhaul and Ace conversion of the script originally written for XP by Near Fantastica and SephirothSpawn, heavily modified by Amaranth and used in all of the Aveyond games.
Features
- Custom mouse icons and text popups over events
- Pathfinding for player AND events
- Mouse control in menus and other windows
- Easy configuration options
Screenshots
Mouse Icons and Event Descriptions:
Even though it would take fewer steps to approach the shopkeeper on the left from below, the -2 0 in the comment tells the pathfinding script to move the player to the tile on the other side of the counter.
The shopkeeper on the right will be approached via the path that takes the fewest steps (from below) since there is no position override in the comment on that event.
The event's description (shown as text beside the icon) can be as many words as you like.
This is a complete overhaul and Ace conversion of the script originally written for XP by Near Fantastica and SephirothSpawn, heavily modified by Amaranth and used in all of the Aveyond games.
Features
- Custom mouse icons and text popups over events
- Pathfinding for player AND events
- Mouse control in menus and other windows
- Easy configuration options
Screenshots
Mouse Icons and Event Descriptions:
The shopkeeper on the right will be approached via the path that takes the fewest steps (from below) since there is no position override in the comment on that event.
The event's description (shown as text beside the icon) can be as many words as you like.
HOWEVER, if you used the keyboard instead of the mouse, pathfinding is overridden, and you WOULD be able to open the chest while standing on the tile to the right.
When you click on the Imp, the player will also walk up the steps to fight it.
HOWEVER, if the imp were set to Approach Player and Event Touch, it WOULD attack the player if the imp is on the hill and the player is below the hill on an adjacent tile.
Pathfinding and mouse processing do NOT override what the player can do via the keyboard, or what events are already programmed to do by the default scripts.
The mouse system is a series of 8 scripts (kept separate for ease of maintenance). Open the .rar file below, open each .rb file in a plain text editor, and copy and paste the scripts each into new slots in Materials. Most of the methods are aliased, so this can go below other custom scripts. ALL scripts should be used together.
Mouse Icons
- Add, change and remove icons through the ICON hash, just below the comments in the Mouse 1 - Sprite script.
- The hash key is the name (one word, alpha characters only, lower case), and the number value is the icon index in your System IconSet.
- DEFAULT_ICON must have the name of one of the keys in the hash. This is what your mouse cursor will look like when it's not over an event that sets a custom cursor.
Add comments to your event pages in the following format to control mouse and pathfinding behaviour:
<mouse icon x y name>
- icon is the name of the icon to show when the mouse is moved over the event. This must exist in the ICON hash.
- x y is an optional addition, to force the pathfinding to move the player to an offset from the current event.
- name is an optional description that will be shown beside the mouse icon. It may be one or more words.
- <mouse fight> will show the 'fight' icon when the mouse is over the event
- <mouse look 0 1> will show the 'look' icon when the mouse is over the event, and will make the player walk to the tile below the event before the event is triggered (good for signs, mailboxes, etc, where you want the player to stand below the event and face up)
- <mouse talk 0 2 Shopkeeper> will show the name Shopkeeper and a 'talk' icon when the mouse is over the event, and when clicked, will move the player to the tile two below the event (good for shopkeepers where there is a counter between the event and the player)
- <mouse talk Nasty Girl> will show the text Nasty Girl along with a 'talk' icon when the mouse is over the event
- To make the player, or an event, walk to a particular tile, without having to check where they currently are and adding lots of directional moves, simply add a Move Route command, choose Script, and enter find_path(x, y).
- The script will ATTEMPT to find a path to that tile (or an adjacent tile if the original one is impassable).
- If a path is not found, no movement will occur.
- If a path is found, the player or event will start following the path. But if, after starting to follow the path, an obstacle moves in its way and blocks the path, the player or event will only walk as far as the obstacle.
- Adding Wait to the move route WILL NOT make the event wait until the path has been followed. Only until the path has been determined. If you want to pause processing until the player or event has reached the destination, you will need to do that separately (keeping in mind that the player/event may not actually reach the destination).
- Any Set Move Route on the player or event while they are following a path will cause them to stop following the path and obey the new move route, even if there are no actual movement commands.
$mouse.enabled = falseThis value is NOT saved anywhere - it is up to you to save it in a preferences file or as game data, and to load that value and call the command whenever your game is started or your save file loaded.Script
Get it here
Patches & Compatibility
Engr. Adiktuzmiko wrote a script that lets you save the enabled/disabled state.
You can find it here.
lordosthyvel has also made a patch for this script that allows diagonal movement.
You can find it here.
Magno has made a patch that fixes a problem in widescreen resolution when using Tsukihime's Unlimited Resolution script.
You can find it here.
Known Bugs
This does not work on maps that have horizontal or vertical looping (in Map Properties).
F12 causes the game to crash. I do not intend to address this, as F12 is not the standard or recommended way of starting a new game.
Script crashes if game title has non-Latin characters
FAQ
Q: Is this compatible with other scripts?
A: It is compatible with RTP scripts. It SHOULD be compatible with most other scripts, with the exception of those that do their own things with player/event collision (like pixel movement scripts) and possibly custom windows that don't behave like Window_Selectable. I don't know if the mouse scripts will work with those or not, but I do NOT plan to make mods to this script to make it compatible with any non-RTP scripts.
Credit and Thanks
- Shaz, Near Fantastica, SephirothSpawn, Amaranth Games
- lordosthyvel, for his diagonal movement patch
Author's Notes
- Okay for use in free and commercial games. Credit must be given.
- Do NOT repost this script on other sites. Please provide a link here instead. I will NOT be going to other sites to give support for this script.
- Post any issues in this thread. I will attempt to fix any bugs with this script, when used with the RTP scripts. I will not attempt to fix bugs that are caused by using the mouse script with other custom scripts.
- I do not recommend you use the find_path method on many events at a time (especially if they are likely to cross paths), or to make them walk long distances.
Hello!
I'm using your script for a while, and it works great, but one thing was always bothering me. Menu navigation is quite cumbersome with it, because you can't just easily navigate the submenus. For example, if I go into the Item menu, and into the weapon tab inside it, i have to press esc (or right click) to exit the weapon tab first, and only after that can I enter the armor tab. I can't go from the weapon tab to another tab directly with the mouse. Same with any other menus.
Is there a solution for this?
That is the default behaviour with keyboard also, and in fact is the way it works with the mouse, touch and keyboard in MV as well (which was made by the original developers, after this script was made).
The armor/weapon/item selection is one window, the list is another. Only one window can be active at a time, by default - you have to use click and right-click to define which one you want to be active.
It IS possible to rewrite the windows in such a way that they are ALL active at the same time, and ALL monitor for mouse clicks. But that would be a huge rewrite (changing not only the code associated with mouse control, but all the other stuff that's not touched by mouse control), and is not something I would consider doing. You would need to ask someone to do this for you, and I doubt anyone would take it on unless you were willing to pay a pretty substantial amount.
The armor/weapon/item selection is one window, the list is another. Only one window can be active at a time, by default - you have to use click and right-click to define which one you want to be active.
It IS possible to rewrite the windows in such a way that they are ALL active at the same time, and ALL monitor for mouse clicks. But that would be a huge rewrite (changing not only the code associated with mouse control, but all the other stuff that's not touched by mouse control), and is not something I would consider doing. You would need to ask someone to do this for you, and I doubt anyone would take it on unless you were willing to pay a pretty substantial amount.
Yeah, I had a feeling that this would be more complicated than I'd like. Guess I have to bear with it. Maybe I could rearrenge the windows a little with Luna Engine so navigating them would need less entering/exiting windows. Like, i would have direct access to some windows from the main menu, instead of navigating deep into some submenus. 🙂
I'll figure something out. Thanks for the reply Shaz.
Shaz, is it possible to add the "display onscreen buttons" functionality to your scipt? I'm using the Super Simple Mouse script, and it works very well, but then I saw some other scripts which make it possible to have an inventory button on the screen for example. Like in the Mouse Buttons 2,5 script:
Unfortunately those scipts have their own quirks, so I don't (can't) use them in my game. But it would be awesome if your script had this function. Being a total programmer n00b, I can't look at other scripts and add this functionality myself.
Unfortunately those scipts have their own quirks, so I don't (can't) use them in my game. But it would be awesome if your script had this function. Being a total programmer n00b, I can't look at other scripts and add this functionality myself.
That is a hud, and yes, it's possible.
In fact, I wrote a small hud for someone else's request in this thread. I know there's a few pages, but if you look through them you should be able to find the request and the script. Hopefully you'll find it easy enough to modify yourself for the buttons you want, but if you can't, just let me know.
In fact, I wrote a small hud for someone else's request in this thread. I know there's a few pages, but if you look through them you should be able to find the request and the script. Hopefully you'll find it easy enough to modify yourself for the buttons you want, but if you can't, just let me know.
Thanks, I will look it up.
Edit: Found it. It is the #51 post in this thread. Just a few quick questions:
- Looking at the code, am I assuming right that this script will make a horizontal HUD at the buttom? So if I enter let's say 32 as HUD_HEIGHT, then the whole bottom line of tiles will be taken up by the HUD, and won't register movement.
- How will I add the button icons/pictures to be always visible. Call it as a Show picture script on every map?
- Could you help me with this line: # replace menu_icon_x1 and menu_icon_x2 with the left & right x positions of the menu icon - Does this mean that if I have a menu icon let's say 3 tiles wide, I have to enter the the leftmost and rightmost coordinates of the icon?
Edit 2: I made the script changes, but I think I messed up something. Although the game runs (I ran a fresh new game by the way), there is nothing new in it, and I definitely can't see any hud. Here is my script:
#============================================================================# SUPER SIMPLE MOUSE SCRIPT
# v1.10 by Shaz
#----------------------------------------------------------------------------
# This is a conversion of the XP Mouse script by Near Fantastica and
# SephirothSpawn modified by Amaranth Games, to run under VX Ace.
#----------------------------------------------------------------------------
# To Install:
# Copy and paste into a new slot in materials, below all other scripts
#----------------------------------------------------------------------------
# To Customize:
# Add keyword icon index pairs to the ICON hash (below this documentation).
# Each of the keywords can be used in an event comment to make the mouse
# cursor change into that icon when hovering over the event.
#----------------------------------------------------------------------------
# To Use:
# Add the following comment to an event page:
# <mouse icon [x y] [name]>
# where icon is the keyword from the ICON hash below
# x and y are the offsets to override player movement (optional)
# name is the text to display next to the icon when hovering over the event (optional)
#
# Examples:
# <mouse fight>
# will change the cursor into the 'fight' icon when over the event
# <mouse touch 0 1>
# will change the cursor into the 'touch' icon when over the event, and
# make the player walk to the tile below the event when the mouse button is
# clicked
# <mouse talk Gloria>
# will change the cursor into the 'talk' icon and display the name Gloria
# <mouse talk 0 2 Henry Smith>
# will change the cursor into the 'talk' icon and display the name Henry Smith,
# and when the mouse button is clicked, the player will walk to the tile
# two below the event (good to use for shops where there's a counter in between)
#
# To force pathfinding on the player or an event, simply add a move route with
# the player or event as the subject, with a Script command, and call
# find_path(x, y) where x and y are the coordinates of the tile you want to move to
# Examples:
# Set Move Route (Player): Script: find_path(5, 8)
# will make the player find a path to tile 5, 8
# Set Move Route (This Event): Script: find_path(10, 5)
# will make the event find a path to tile 10, 5
#
# NOTE: The path will be ATTEMPTED. If there is no path TO that exact tile,
# a path to an adjacent tile will be attempted. If no path is found there
# either, no movement will occur.
# If a route is found, the player or event will begin moving towards it. But
# if their path is blocked while they are moving, movement will be cancelled.
#----------------------------------------------------------------------------
# Author's Notes:
# This script should work with any RTP script.
# I do not guarantee that it will work with ANY other script (especially anything
# that overrides player or event movement, such as pixel movement scripts, or
# custom window scripts).
#
# Script OVERWRITES the following methods:
# Game_Map.setup_starting_map_event
# Game_Map.setup_autorun_common_event
#
# If you have other scripts that ALIAS these methods, this mouse script should
# be placed above them.
#----------------------------------------------------------------------------
# Terms:
# Use in free and commercial games
# Credit: Near Fantastica, SephirothSpawn, Amaranth Games, Shaz
#----------------------------------------------------------------------------
# Versions:
# 1.0 - 6 Sept 2013 - initial release
# 1.02 - 7 Sept 2013 - fixed crash when loading games saved prior to adding script
# - fixed player gets stuck on impassable area on world map
# when clicking while leaving air ship
# 1.03 - 8 Sept 2013 - fixed actor moving to diagonal tile instead of adjacent
# 1.04 - 10 Sept 2013 - fixed vehicle pathfinding on world map
# - fixed event trigger when no path found
# 1.05 - 14 Sept 2013 - tweaked accessing of tilemap offset
# 1.06 - 3 Nov 2013 - disabled mouse movement when waiting for NPC move route
# - fixed events not triggering after player finishes walking
# 1.07 - 6 Nov 2013 - slow down mouse scrolling, and don't loop save files
# 1.08 - 24 Nov 2013 - cater for YEA Core large resolution with too-small maps
# - fixed early event activation bug introduced in 1.06
# - replaced calc of Windows_Selectable boundaries with item_rect
# - added ability to completely disable mouse
# 1.09 - 21 Dec 2013 - fixed mouse re-enable when calling common events
# 1.10 - 6 Apr 2014 - add interaction for top part of > 32pixel high event
# - activate an event without walking up to it
# (add <autoactivate> comment at top of event page)
# - arrow keys override mouse movement when pathfinding
# - ignore mouse in menus when using keyboard
# - make player walk to counter opposite shopkeepers
#============================================================================
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Mouse Sprite
#============================================================================
# Add/remove/change icon names here. The icon name is what will be used in the
# event <mouse ...> command to show a different mouse icon when hovering over
# the event. These MUST be in lower case here!
ICON = {'arrow' => 386, 'talk' => 4, 'look' => 3, 'fight' => 116,
'touch' => 491, 'exit' => 121}
DEFAULT_ICON = 'arrow'
class Sprite_Mouse < Sprite
#--------------------------------------------------------------------------
# * Initialization
#--------------------------------------------------------------------------
def initialize
super
self.z = 10100
self.ox = 4
update
@dummy = Bitmap.new(32, 32)
self.bitmap = Bitmap.new(32, 32)
@enabled = true
@ignored = false
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
return if !@enabled
super
if !SceneManager.scene.nil?
if !Mouse.position.nil?
mx, my = *Mouse.position
if @cursor == DEFAULT_ICON
self.x = mx unless mx.nil?
else
self.x = [mx, Graphics.width - self.bitmap.width].min unless mx.nil?
end
self.y = my unless my.nil?
end
if @scene != SceneManager.scene.class || Mouse.trigger?
@scene = SceneManager.scene.class
set_bitmap
end
end
end
#--------------------------------------------------------------------------
# * Set Bitmap
#--------------------------------------------------------------------------
def set_bitmap(cursor = DEFAULT_ICON, text = nil)
if @ignored
cursor = DEFAULT_ICON
text = nil
end
if @cursor != cursor || @text != text
@cursor = cursor
@text = text
item_cursor = ICON[cursor]
rect = Rect.new(item_cursor % 16 * 24, item_cursor / 16 * 24, 24, 24)
if @text.nil?
self.bitmap = Bitmap.new(24, 32)
self.bitmap.blt(0, 0, Cache.system('Iconset'), rect)
else
w = @dummy.text_size(@text).width
h = @dummy.font.size
bitmap = Bitmap.new(26 + w, [32, h+2].max)
bitmap.font.size = @dummy.font.size
bitmap.font.shadow = true
if self.x + 26 + w > Graphics.width
bitmap.draw_text(0, 0, w, h, @text)
bitmap.blt(w, 0, Cache.system('Iconset'), rect)
else
bitmap.blt(0, 0, Cache.system('Iconset'), rect)
bitmap.draw_text(26, 0, w, h, @text)
end
self.bitmap = bitmap
end
end
end
#--------------------------------------------------------------------------
# * Update Event Cursors
#--------------------------------------------------------------------------
def update_event_cursors
# Remove mouse icon and text if we're off the grid
if Mouse.grid.nil?
set_bitmap
return
end
# Set cursor and text according to event
x, y = *Mouse.grid
event = $game_map.lowest_mouse_event_xy(x, y)
unless event.nil? && y < 410
if !event.mouse_icon.nil? || !event.mouse_text.nil?
set_bitmap(event.mouse_icon, event.mouse_text)
return
end
end
# default bitmap if not over an event
set_bitmap
end
#--------------------------------------------------------------------------
# * Enable Mouse
#--------------------------------------------------------------------------
def enabled=(value)
@enabled = value
self.visible = value
end
#--------------------------------------------------------------------------
# * Mouse Enabled?
#--------------------------------------------------------------------------
def enabled?
@enabled
end
#--------------------------------------------------------------------------
# * Ignore Mouse
#--------------------------------------------------------------------------
def ignored=(value)
@ignored = value
end
#--------------------------------------------------------------------------
# * Mouse Ignored?
#--------------------------------------------------------------------------
def ignored?
@ignored
end
end
$mouse = Sprite_Mouse.new
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Mouse Module
#============================================================================
#==============================================================================
# ** Mouse Module
#------------------------------------------------------------------------------
# by Near Fantastica and SephirothSpawn
# adapted and converted to VX Ace by Shaz
#==============================================================================
module Mouse
#--------------------------------------------------------------------------
# * Mouse to Input Triggers
# key => Input::KeyCONSTANT (key: 0 - left, 1 - middle, 2 - right)
#--------------------------------------------------------------------------
Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
#--------------------------------------------------------------------------
# * API Declarations
#--------------------------------------------------------------------------
GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
#--------------------------------------------------------------------------
# * Module Variables
#--------------------------------------------------------------------------
@triggers = [[0, 1], [0, 2], [0, 4]]
@old_pos = 0
@pos_i = 0
@sys_cursor_visible = false
#--------------------------------------------------------------------------
# * Mouse Grid Position
#--------------------------------------------------------------------------
def self.grid
return nil if @pos.nil?
mx, my = SceneManager.scene.instance_variable_get🙂@spriteset).tilemap_offset
x = (@pos[0] + mx) / 32
y = (@pos[1] + my) / 32
return [x, y]
end
#--------------------------------------------------------------------------
# * Mouse Position
#--------------------------------------------------------------------------
def self.position
return @pos.nil? ? [0, 0] : @pos
end
#--------------------------------------------------------------------------
# * Mouse Global Position
#--------------------------------------------------------------------------
def self.global_pos
pos = [0, 0].pack('ll')
return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
end
#--------------------------------------------------------------------------
# * Screen to Client
#--------------------------------------------------------------------------
def self.screen_to_client(x=0, y=0)
pos = [x, y].pack('ll')
return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
end
#--------------------------------------------------------------------------
# * Mouse Position
#--------------------------------------------------------------------------
def self.pos
gx, gy = global_pos
x, y = screen_to_client(gx, gy)
# Test boundaries
begin
if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
return x, y
else
return -20, -20
end
rescue
return 0, 0
end
end
#--------------------------------------------------------------------------
# * Update Mouse Position
#--------------------------------------------------------------------------
def self.update
old_pos = @pos
@pos = self.pos
# Has mouse been moved?
if old_pos != @pos
Input.method = :mouse
end
# Which mouse to show - custom, or system?
if $mouse.enabled? == @sys_cursor_visible
@sys_cursor_visible = !@sys_cursor_visible
ShowCursor.call(@sys_cursor_visible ? 1 : 0)
end
return if !$mouse.enabled?
# Leaving / Entering Range?
if old_pos != [-20, -20] && @pos == [-20, -20] # leaving range
ShowCursor.call(1)
elsif old_pos == [-20, -20] && @pos != [-20, -20] # entering range
ShowCursor.call(0)
end
# Update Triggers
for i in @triggers
n = GAKS.call(i[1])
if [0, 1].include?(n)
i[0] = (i[0] > 0 ? i[0] * -1 : 0)
else
i[0] = (i[0] > 0 ? i[0] + 1 : 1)
end
end
end
#--------------------------------------------------------------------------
# * Trigger?
# id : 0:Left, 1:Right, 2:Center
#--------------------------------------------------------------------------
def self.trigger?(id = 0)
if pos != [-20, -20]
return @triggers[id][0] == 1
end
return false
end
#--------------------------------------------------------------------------
# * Repeat?
# id : 0:Left, 1:Right, 2:Center
#--------------------------------------------------------------------------
def self.repeat?(id = 0)
return @triggers[id][0] > 0 && @triggers[id][0] % 5 == 1
end
#--------------------------------------------------------------------------
# * Hwnd
#--------------------------------------------------------------------------
def self.hwnd
if @hwnd.nil?
title = "\0" * 256
Readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
title.delete!("\0")
@hwnd = Findwindow.call('RGSS Player', title)
ShowCursor.call(0)
end
return @hwnd
end
#--------------------------------------------------------------------------
# * Client Size
#--------------------------------------------------------------------------
def self.client_size
rect = [0, 0, 0, 0].pack('l4')
Client_rect.call(self.hwnd, rect)
return rect.unpack('l4')[2..3]
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Input
#============================================================================
class << Input
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :method
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias :seph_mouse_input_update :update
alias :seph_mouse_input_trigger? :trigger?
alias :seph_mouse_input_repeat? :repeat?
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
$mouse.update
Mouse.update
seph_mouse_input_update
# Are we using the mouse or the keyboard?
@method = :keyboard if dir4 != 0 || dir8 != 0
end
#--------------------------------------------------------------------------
# * Trigger? Test
#--------------------------------------------------------------------------
def trigger?(constant)
return true if seph_mouse_input_trigger?(constant)
if $mouse.enabled? && !Mouse.pos.nil?
if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
return true if Mouse.trigger?(Mouse::Mouse_to_Input_Triggers.index(constant))
end
end
return false
end
#--------------------------------------------------------------------------
# * Repeat? Test
#--------------------------------------------------------------------------
def repeat?(constant)
return true if seph_mouse_input_repeat?(constant)
if $mouse.enabled? && !Mouse.pos.nil?
if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
return true if Mouse.repeat?(Mouse::Mouse_to_Input_Triggers.index(constant))
end
end
return false
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Map
#============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Tilemap Offset
#--------------------------------------------------------------------------
def tilemap_offset
if $imported && $imported["YEA-CoreEngine"]
[@tilemap.ox - @viewport1.rect.x, @tilemap.oy - @viewport1.rect.y]
else
[@tilemap.ox, @tilemap.oy]
end
end
end
class Game_Map
#--------------------------------------------------------------------------
# * Detect/Set Up Starting Map Event
#--------------------------------------------------------------------------
def setup_starting_map_event
event = @events.values.find {|event| event.starting }
event.clear_starting_flag if event
@interpreter.setup(event.list, event.id, event.trigger_in?([0,1,2,3])) if event
event
end
#--------------------------------------------------------------------------
# * Detect/Set Up Autorun Common Event
#--------------------------------------------------------------------------
def setup_autorun_common_event
event = $data_common_events.find do |event|
event && event.autorun? && $game_switches[event.switch_id]
end
@interpreter.setup(event.list, 0, true) if event
event
end
#--------------------------------------------------------------------------
# * Get ID of Lowest Mouse-enabled Event at Designated Coordinates
#--------------------------------------------------------------------------
def lowest_mouse_event_xy(x, y)
list = events_xy(x, y) + events_xy(x, y+1)
list.sort! {|a, b| b.y - a.y}
evt = nil
list.each do |event|
if (event.pos?(x, y) || (event.pos?(x, y+1) && event.height > 32)) &&
(evt.nil? || event.y > evt.y)
evt = event
break
end
end
return evt
end
end
class Scene_Map
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_scene_map_update update
def update
$mouse.update_event_cursors
update_hud
shaz_mouse_scene_map_update
end
end
#--------------------------------------------------------------------------
# * HUD
#--------------------------------------------------------------------------
def update_hud
mx, my = Mouse.pos
# if mouse is clicked over the hud
if my <= 32 && Mouse.trigger?(0)
# set the menu actor as the leader for any 'personal' commands (equip, skills, etc)
$game_party.menu_actor = $game_party.members[0]
# determine what icon was clicked on
# Menu
if mx.between?(menu_icon_x1, menu_icon_x2) # replace menu_icon_x1 and menu_icon_x2 with the left & right x positions of the menu icon
SceneManager.call(Scene_Menu)
Window_MenuCommand::init_command_position
end
# Items
if mx.between?(items_icon_x1, items_icon_x2)
SceneManager.call(Scene_Item)
end
# Skills
if mx.between?(skill_icon_x1, skill_icon_x2)
SceneManager.call(Scene_Skills)
end
# Equip
if mx.between?(equip_icon_x1, equip_icon_x2)
SceneManager.call(Scene_Equip)
end
# and so on for the rest of your icons
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Event
#============================================================================
module RPG
class Event
class Page
#--------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------
attr_reader :mouse_icon
attr_reader :mouse_text
attr_reader :mouse_position
attr_reader :mouse_autoactivate
#--------------------------------------------------------------------
# * Build Stats
#--------------------------------------------------------------------
def build_stats
# Mouse icons (icon mandatory, others optional)
# <mouse icon destx desty name>
@mouse_icon = nil
@mouse_text = nil
@mouse_position = [0, 0]
@mouse_autoactivate = false
# look for mouse instructions
list.each do |command|
if [108, 408].include?(command.code)
comment = command.parameters[0]
case comment
when /<mouse/i
params = /<mouse (.*)>/i.match(comment)[1].split(' ')
@mouse_icon = params.shift
if params.size > 1 && params[0] =~ /\d+/ && params[1] =~ /\d+/
@mouse_position = [params.shift.to_i, params.shift.to_i]
end
if params.size > 0
@mouse_text = params.join(' ')
end
when /<autoactivate>/
@mouse_autoactivate = true
end
end #if
end #do
end #def
end
end
end
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :mouse_icon
attr_reader :mouse_text
attr_reader :mouse_position
attr_reader :mouse_autoactivate
#--------------------------------------------------------------------------
# * Start Event
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_start start
def start
$game_player.start_event(@id) if !empty?
shaz_mouse_game_event_start
end
#--------------------------------------------------------------------------
# * Clear Event Page Settings
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_clear_page_settings clear_page_settings
def clear_page_settings
shaz_mouse_game_event_clear_page_settings
@mouse_icon = nil
@mouse_text = nil
@mouse_position = [0, 0]
@mouse_autoactivate = false
@height = 0
end
#--------------------------------------------------------------------------
# * Set Up Event Page Settings
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_setup_page_settings setup_page_settings
def setup_page_settings
shaz_mouse_game_event_setup_page_settings
@page.build_stats
@mouse_icon = @page.mouse_icon
@mouse_text = @page.mouse_text
@mouse_position = @page.mouse_position
@mouse_autoactivate = @page.mouse_autoactivate
set_size
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Character
#============================================================================
class Game_CharacterBase
attr_reader :height # Height of character bitmap
#--------------------------------------------------------------------------
# * Initialize Public Member Variables
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_init_public_members init_public_members
def init_public_members
shaz_mouse_game_characterbase_init_public_members
@height = 0
end
#--------------------------------------------------------------------------
# * Change Graphics
# character_name : new character graphic filename
# character_index : new character graphic index
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_set_graphic set_graphic
def set_graphic(character_name, character_index)
shaz_mouse_game_characterbase_set_graphic(character_name, character_index)
set_size
end
#--------------------------------------------------------------------------
# * Set character width/height size
#--------------------------------------------------------------------------
def set_size
bw = Cache.character(@character_name).width
bh = Cache.character(@character_name).height
sign = @character_name[/^[\!\$]./]
if sign && sign.include?('$')
@width = bw / 3
@height = bh / 4
else
@width = bw / 12
@height = bh / 8
end
end
#--------------------------------------------------------------------------
# * Detect Collision with Event
#--------------------------------------------------------------------------
def collide_with_events?(x, y)
$game_map.events_xy_nt(x, y).any? do |event|
self != event && (event.normal_priority? || self.is_a?(Game_Event))
end
end
#--------------------------------------------------------------------------
# * Detect Collision with Vehicle
#--------------------------------------------------------------------------
def collide_with_vehicles?(x, y)
!self.is_a?(Game_Player) && ($game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y))
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_update update
def update
run_path if @runpath
shaz_mouse_game_characterbase_update
end
#--------------------------------------------------------------------------
# * Run Path
#--------------------------------------------------------------------------
def run_path
return if moving?
@step = @map.nil? || @map[@x, @y].nil? ? 0 : @map[@x, @y] - 1
if @step < 1
clear_path
else
x, y = @x, @y
dirs = []
dirs.push(6) if @map[@x+1, @y] == @step && passable?(@x, @y, 6)
dirs.push(2) if @map[@x, @y+1] == @step && passable?(@x, @y, 2)
dirs.push(4) if @map[@x-1, @y] == @step && passable?(@x, @y, 4)
dirs.push(8) if @map[@x, @y-1] == @step && passable?(@x, @y, 8)
while dirs.size > 0
dir = dirs.delete_at(rand(dirs.size))
move_straight(dir)
break if x != @x || y != @y
end
# clear the path if we couldn't move
clear_path if x == @x && y == @y
end
end
#--------------------------------------------------------------------------
# * Find Path
#--------------------------------------------------------------------------
def find_path(x, y)
sx, sy = @x, @y
@tx, @ty = x, y
result = setup_map(sx, sy)
@runpath = result[0]
@map = result[1]
@map[sx, sy] = result[2] if result[2] != nil
end
#--------------------------------------------------------------------------
# * Clear Path
#--------------------------------------------------------------------------
def clear_path
@map = nil
@runpath = false
end
#--------------------------------------------------------------------------
# * Setup Map
#--------------------------------------------------------------------------
def setup_map(sx, sy)
map = Table.new($game_map.width, $game_map.height)
update_counter = 0
map[@tx, @ty] = 1
old_positions = [[@tx, @ty]]
new_positions = []
# if tile is impassable, but CAN move to adjacent tiles, use the adjacent tiles instead
if (!passable?(@tx, @ty, 2) && !passable?(@tx, @ty, 4) &&
!passable?(@tx, @ty, 6) && !passable?(@tx, @ty, 8)) ||
$game_map.events_xy_nt(@tx, @ty).any? { |evt| evt.normal_priority? && evt != self }
old_positions = []
# Can we move from the destination tile in any direction?
if map_passable?(@tx, @ty, 2)
map[@tx, @ty+1] = 1
old_positions.push([@tx, @ty+1])
end
if map_passable?(@tx, @ty, 8)
map[@tx, @ty-1] = 1
old_positions.push([@tx, @ty-1])
end
if map_passable?(@tx, @ty, 4)
map[@tx-1, @ty] = 1
old_positions.push([@tx-1, @ty])
end
if map_passable?(@tx, @ty, 6)
map[@tx+1, @ty] = 1
old_positions.push([@tx+1, @ty])
end
# If not, can we at least move up to the destination tile?
if old_positions.size == 0
if map_passable?(@tx-1,@ty,6)
map[@tx-1,@ty] = 1
old_positions.push([@tx-1,@ty])
end
if map_passable?(@tx+1,@ty,4)
map[@tx+1,@ty] = 1
old_positions.push([@tx+1,@ty])
end
if map_passable?(@tx,@ty-1,2)
map[@tx,@ty-1] = 1
old_positions.push([@tx,@ty-1])
end
if map_passable?(@tx,@ty+1,8)
map[@tx,@ty+1] = 1
old_positions.push([@tx,@ty+1])
end
end
end
# If there are any counters, can we move to the tile on the other side?
if map_passable?(@tx-2,@ty,6) && $game_map.counter?(@tx-1,@ty)
map[@tx-2,@ty] = 1
old_positions.push([@tx-2,@ty])
end
if map_passable?(@tx+2,@ty,4) && $game_map.counter?(@tx+1,@ty)
map[@tx+2,@ty] = 1
old_positions.push([@tx+2,@ty])
end
if map_passable?(@tx,@ty-2,2) && $game_map.counter?(@tx,@ty-1)
map[@tx,@ty-2] = 1
old_positions.push([@tx,@ty-2])
end
if map_passable?(@tx,@ty+2,2) && $game_map.counter?(@tx,@ty+1)
map[@tx,@ty+2] = 1
old_positions.push([@tx,@ty+2])
end
depth = 2
depth.upto(100) { |step|
break if old_positions[0].nil?
@step = step
loop do
break if old_positions[0].nil?
x, y = old_positions.shift
return [true, map, @step-1] if x == sx && y == sy
if map[x, y + 1] == 0 && passable?(x, y, 2)
map[x, y + 1] = @step
new_positions.push([x, y + 1])
end
if map[x - 1, y] == 0 && passable?(x, y, 4)
map[x - 1, y] = @step
new_positions.push([x - 1, y])
end
if map[x + 1, y] == 0 && passable?(x, y, 6)
map[x + 1, y] = @step
new_positions.push([x + 1, y])
end
if map[x, y - 1] == 0 && passable?(x, y, 8)
map[x, y - 1] = @step
new_positions.push([x, y - 1])
end
# Update graphics? (to reduce lag)
update_counter += 1
if update_counter > 50
Graphics.update
update_counter = 0
end
end
old_positions = new_positions
new_positions = []
}
return [false, nil, nil]
end
end
class Game_Character < Game_CharacterBase
#--------------------------------------------------------------------------
# * Force Move Route
#--------------------------------------------------------------------------
alias shaz_mouse_game_character_force_move_route force_move_route
def force_move_route(move_route)
clear_path
shaz_mouse_game_character_force_move_route(move_route)
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Player
#============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Trigger Map Event
# triggers : Trigger array
# normal : Is priority set to [same as Characters] ?
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_start_map_event start_map_event
def start_map_event(x, y, triggers, normal)
@started_events = []
shaz_mouse_game_player_start_map_event(x, y, triggers, normal)
end
#--------------------------------------------------------------------------
# * Start Event
#--------------------------------------------------------------------------
def start_event(event_id)
@started_events = [] if @started_events.nil?
@started_events.push(event_id)
end
#--------------------------------------------------------------------------
# * Processing of Movement via Input from Directional Buttons
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_move_by_input move_by_input
def move_by_input
if Input.dir4 > 0
clear_path
shaz_mouse_game_player_move_by_input
else
# Move by mouse input
if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&
!@vehicle_getting_on && !@vehicle_getting_off &&
Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored? && Mouse.pos[1] > 32
mx, my = *Mouse.grid
# turn in direction
if (@x - mx).abs >= (@y - my).abs
set_direction(@x > mx ? 4 : 6)
else
set_direction(@y > my ? 8 : 2)
end
# find path
@event = $game_map.lowest_mouse_event_xy(mx, my)
if @event.nil?
find_path(mx, my)
elsif @event.mouse_autoactivate
@event.start
@started_events = []
clear_path
else
find_path(@event.x + @event.mouse_position[0],
@event.y + @event.mouse_position[1])
end
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_update update
def update
shaz_mouse_game_player_update
update_pathfinding if [email protected]? && !moving?
end
#--------------------------------------------------------------------------
# * Check event after pathfinding
#--------------------------------------------------------------------------
def update_pathfinding
if @map.nil? || @map[@x, @y] <= 1
dir = @x < @event.x ? 6 : @x > @event.x ? 4 : @y < @event.y ? 2 : @y > @event.y ? 8 : 0
# Face event and trigger it (only if not triggered by start_map_event)
turn_toward_character(@event) if [email protected]?(@x, @y)
if !@started_events.include?(@event.id) && [email protected]? && !in_airship?
@event.start
@started_events = []
end
clear_path
end
end
#--------------------------------------------------------------------------
# * Clear Path
#--------------------------------------------------------------------------
def clear_path
@event = nil
super
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Interpreter
#============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Event Setup
#--------------------------------------------------------------------------
alias shaz_mouse_game_interpreter_setup setup
def setup(list, event_id = 0, lock_player = false)
shaz_mouse_game_interpreter_setup(list, event_id)
@lock_player = lock_player
end
#--------------------------------------------------------------------------
# * Execute
#--------------------------------------------------------------------------
alias shaz_mouse_game_interpreter_run run
def run
$mouse.ignored = true if @lock_player
shaz_mouse_game_interpreter_run
$mouse.ignored = false if @lock_player
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Windows
#============================================================================
class Window_Selectable < Window_Base
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_window_selectable_update update
def update
shaz_mouse_window_selectable_update
process_mouse_handling if Input.method == :mouse
end
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled? && cursor_movable?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
if mx.between?(vx, vx + self.width) &&
my.between?(vy, vy + self.height)
mx -= vx
mx -= padding
my -= vy
my -= padding
my += oy
for i in 0 ... item_max
rect = item_rect(i)
if mx.between?(rect.x, rect.x + rect.width) &&
my.between?(rect.y, rect.y + rect.height)
last_index = @index
select(i)
if @index != last_index
Sound.play_cursor
end
break
end
end
end
end
end
class Window_NameInput < Window_Selectable
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = (self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x) + padding
vy = (self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y) + padding
if mx.between?(vx, vx + self.width - padding * 2) &&
my.between?(vy, vy + self.height - padding * 2)
mx -= vx
my -= vy
x = (mx > 5*32+16 ? mx-16 : mx) / 32
y = my / line_height
last_index = @index
@index = y * 10 + x
Sound.play_cursor if @index != last_index
end
end
end
class Scene_File < Scene_MenuBase
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
alias shaz_mouse_scene_file_update_cursor update_cursor
def update_cursor
shaz_mouse_scene_file_update_cursor
process_mouse_handling if Input.method == :mouse
end
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = @savefile_viewport.ox + mx
vy = @savefile_viewport.oy + my
last_index = @index
new_index = vy / savefile_height
if @index != new_index
if new_index > @index
cursor_down(false)
else
cursor_up(false)
end
Sound.play_cursor
@savefile_windows[last_index].selected = false
@savefile_windows[@index].selected = true
end
end
end
# v1.10 by Shaz
#----------------------------------------------------------------------------
# This is a conversion of the XP Mouse script by Near Fantastica and
# SephirothSpawn modified by Amaranth Games, to run under VX Ace.
#----------------------------------------------------------------------------
# To Install:
# Copy and paste into a new slot in materials, below all other scripts
#----------------------------------------------------------------------------
# To Customize:
# Add keyword icon index pairs to the ICON hash (below this documentation).
# Each of the keywords can be used in an event comment to make the mouse
# cursor change into that icon when hovering over the event.
#----------------------------------------------------------------------------
# To Use:
# Add the following comment to an event page:
# <mouse icon [x y] [name]>
# where icon is the keyword from the ICON hash below
# x and y are the offsets to override player movement (optional)
# name is the text to display next to the icon when hovering over the event (optional)
#
# Examples:
# <mouse fight>
# will change the cursor into the 'fight' icon when over the event
# <mouse touch 0 1>
# will change the cursor into the 'touch' icon when over the event, and
# make the player walk to the tile below the event when the mouse button is
# clicked
# <mouse talk Gloria>
# will change the cursor into the 'talk' icon and display the name Gloria
# <mouse talk 0 2 Henry Smith>
# will change the cursor into the 'talk' icon and display the name Henry Smith,
# and when the mouse button is clicked, the player will walk to the tile
# two below the event (good to use for shops where there's a counter in between)
#
# To force pathfinding on the player or an event, simply add a move route with
# the player or event as the subject, with a Script command, and call
# find_path(x, y) where x and y are the coordinates of the tile you want to move to
# Examples:
# Set Move Route (Player): Script: find_path(5, 8)
# will make the player find a path to tile 5, 8
# Set Move Route (This Event): Script: find_path(10, 5)
# will make the event find a path to tile 10, 5
#
# NOTE: The path will be ATTEMPTED. If there is no path TO that exact tile,
# a path to an adjacent tile will be attempted. If no path is found there
# either, no movement will occur.
# If a route is found, the player or event will begin moving towards it. But
# if their path is blocked while they are moving, movement will be cancelled.
#----------------------------------------------------------------------------
# Author's Notes:
# This script should work with any RTP script.
# I do not guarantee that it will work with ANY other script (especially anything
# that overrides player or event movement, such as pixel movement scripts, or
# custom window scripts).
#
# Script OVERWRITES the following methods:
# Game_Map.setup_starting_map_event
# Game_Map.setup_autorun_common_event
#
# If you have other scripts that ALIAS these methods, this mouse script should
# be placed above them.
#----------------------------------------------------------------------------
# Terms:
# Use in free and commercial games
# Credit: Near Fantastica, SephirothSpawn, Amaranth Games, Shaz
#----------------------------------------------------------------------------
# Versions:
# 1.0 - 6 Sept 2013 - initial release
# 1.02 - 7 Sept 2013 - fixed crash when loading games saved prior to adding script
# - fixed player gets stuck on impassable area on world map
# when clicking while leaving air ship
# 1.03 - 8 Sept 2013 - fixed actor moving to diagonal tile instead of adjacent
# 1.04 - 10 Sept 2013 - fixed vehicle pathfinding on world map
# - fixed event trigger when no path found
# 1.05 - 14 Sept 2013 - tweaked accessing of tilemap offset
# 1.06 - 3 Nov 2013 - disabled mouse movement when waiting for NPC move route
# - fixed events not triggering after player finishes walking
# 1.07 - 6 Nov 2013 - slow down mouse scrolling, and don't loop save files
# 1.08 - 24 Nov 2013 - cater for YEA Core large resolution with too-small maps
# - fixed early event activation bug introduced in 1.06
# - replaced calc of Windows_Selectable boundaries with item_rect
# - added ability to completely disable mouse
# 1.09 - 21 Dec 2013 - fixed mouse re-enable when calling common events
# 1.10 - 6 Apr 2014 - add interaction for top part of > 32pixel high event
# - activate an event without walking up to it
# (add <autoactivate> comment at top of event page)
# - arrow keys override mouse movement when pathfinding
# - ignore mouse in menus when using keyboard
# - make player walk to counter opposite shopkeepers
#============================================================================
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Mouse Sprite
#============================================================================
# Add/remove/change icon names here. The icon name is what will be used in the
# event <mouse ...> command to show a different mouse icon when hovering over
# the event. These MUST be in lower case here!
ICON = {'arrow' => 386, 'talk' => 4, 'look' => 3, 'fight' => 116,
'touch' => 491, 'exit' => 121}
DEFAULT_ICON = 'arrow'
class Sprite_Mouse < Sprite
#--------------------------------------------------------------------------
# * Initialization
#--------------------------------------------------------------------------
def initialize
super
self.z = 10100
self.ox = 4
update
@dummy = Bitmap.new(32, 32)
self.bitmap = Bitmap.new(32, 32)
@enabled = true
@ignored = false
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
return if !@enabled
super
if !SceneManager.scene.nil?
if !Mouse.position.nil?
mx, my = *Mouse.position
if @cursor == DEFAULT_ICON
self.x = mx unless mx.nil?
else
self.x = [mx, Graphics.width - self.bitmap.width].min unless mx.nil?
end
self.y = my unless my.nil?
end
if @scene != SceneManager.scene.class || Mouse.trigger?
@scene = SceneManager.scene.class
set_bitmap
end
end
end
#--------------------------------------------------------------------------
# * Set Bitmap
#--------------------------------------------------------------------------
def set_bitmap(cursor = DEFAULT_ICON, text = nil)
if @ignored
cursor = DEFAULT_ICON
text = nil
end
if @cursor != cursor || @text != text
@cursor = cursor
@text = text
item_cursor = ICON[cursor]
rect = Rect.new(item_cursor % 16 * 24, item_cursor / 16 * 24, 24, 24)
if @text.nil?
self.bitmap = Bitmap.new(24, 32)
self.bitmap.blt(0, 0, Cache.system('Iconset'), rect)
else
w = @dummy.text_size(@text).width
h = @dummy.font.size
bitmap = Bitmap.new(26 + w, [32, h+2].max)
bitmap.font.size = @dummy.font.size
bitmap.font.shadow = true
if self.x + 26 + w > Graphics.width
bitmap.draw_text(0, 0, w, h, @text)
bitmap.blt(w, 0, Cache.system('Iconset'), rect)
else
bitmap.blt(0, 0, Cache.system('Iconset'), rect)
bitmap.draw_text(26, 0, w, h, @text)
end
self.bitmap = bitmap
end
end
end
#--------------------------------------------------------------------------
# * Update Event Cursors
#--------------------------------------------------------------------------
def update_event_cursors
# Remove mouse icon and text if we're off the grid
if Mouse.grid.nil?
set_bitmap
return
end
# Set cursor and text according to event
x, y = *Mouse.grid
event = $game_map.lowest_mouse_event_xy(x, y)
unless event.nil? && y < 410
if !event.mouse_icon.nil? || !event.mouse_text.nil?
set_bitmap(event.mouse_icon, event.mouse_text)
return
end
end
# default bitmap if not over an event
set_bitmap
end
#--------------------------------------------------------------------------
# * Enable Mouse
#--------------------------------------------------------------------------
def enabled=(value)
@enabled = value
self.visible = value
end
#--------------------------------------------------------------------------
# * Mouse Enabled?
#--------------------------------------------------------------------------
def enabled?
@enabled
end
#--------------------------------------------------------------------------
# * Ignore Mouse
#--------------------------------------------------------------------------
def ignored=(value)
@ignored = value
end
#--------------------------------------------------------------------------
# * Mouse Ignored?
#--------------------------------------------------------------------------
def ignored?
@ignored
end
end
$mouse = Sprite_Mouse.new
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Mouse Module
#============================================================================
#==============================================================================
# ** Mouse Module
#------------------------------------------------------------------------------
# by Near Fantastica and SephirothSpawn
# adapted and converted to VX Ace by Shaz
#==============================================================================
module Mouse
#--------------------------------------------------------------------------
# * Mouse to Input Triggers
# key => Input::KeyCONSTANT (key: 0 - left, 1 - middle, 2 - right)
#--------------------------------------------------------------------------
Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
#--------------------------------------------------------------------------
# * API Declarations
#--------------------------------------------------------------------------
GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
#--------------------------------------------------------------------------
# * Module Variables
#--------------------------------------------------------------------------
@triggers = [[0, 1], [0, 2], [0, 4]]
@old_pos = 0
@pos_i = 0
@sys_cursor_visible = false
#--------------------------------------------------------------------------
# * Mouse Grid Position
#--------------------------------------------------------------------------
def self.grid
return nil if @pos.nil?
mx, my = SceneManager.scene.instance_variable_get🙂@spriteset).tilemap_offset
x = (@pos[0] + mx) / 32
y = (@pos[1] + my) / 32
return [x, y]
end
#--------------------------------------------------------------------------
# * Mouse Position
#--------------------------------------------------------------------------
def self.position
return @pos.nil? ? [0, 0] : @pos
end
#--------------------------------------------------------------------------
# * Mouse Global Position
#--------------------------------------------------------------------------
def self.global_pos
pos = [0, 0].pack('ll')
return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
end
#--------------------------------------------------------------------------
# * Screen to Client
#--------------------------------------------------------------------------
def self.screen_to_client(x=0, y=0)
pos = [x, y].pack('ll')
return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
end
#--------------------------------------------------------------------------
# * Mouse Position
#--------------------------------------------------------------------------
def self.pos
gx, gy = global_pos
x, y = screen_to_client(gx, gy)
# Test boundaries
begin
if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
return x, y
else
return -20, -20
end
rescue
return 0, 0
end
end
#--------------------------------------------------------------------------
# * Update Mouse Position
#--------------------------------------------------------------------------
def self.update
old_pos = @pos
@pos = self.pos
# Has mouse been moved?
if old_pos != @pos
Input.method = :mouse
end
# Which mouse to show - custom, or system?
if $mouse.enabled? == @sys_cursor_visible
@sys_cursor_visible = !@sys_cursor_visible
ShowCursor.call(@sys_cursor_visible ? 1 : 0)
end
return if !$mouse.enabled?
# Leaving / Entering Range?
if old_pos != [-20, -20] && @pos == [-20, -20] # leaving range
ShowCursor.call(1)
elsif old_pos == [-20, -20] && @pos != [-20, -20] # entering range
ShowCursor.call(0)
end
# Update Triggers
for i in @triggers
n = GAKS.call(i[1])
if [0, 1].include?(n)
i[0] = (i[0] > 0 ? i[0] * -1 : 0)
else
i[0] = (i[0] > 0 ? i[0] + 1 : 1)
end
end
end
#--------------------------------------------------------------------------
# * Trigger?
# id : 0:Left, 1:Right, 2:Center
#--------------------------------------------------------------------------
def self.trigger?(id = 0)
if pos != [-20, -20]
return @triggers[id][0] == 1
end
return false
end
#--------------------------------------------------------------------------
# * Repeat?
# id : 0:Left, 1:Right, 2:Center
#--------------------------------------------------------------------------
def self.repeat?(id = 0)
return @triggers[id][0] > 0 && @triggers[id][0] % 5 == 1
end
#--------------------------------------------------------------------------
# * Hwnd
#--------------------------------------------------------------------------
def self.hwnd
if @hwnd.nil?
title = "\0" * 256
Readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
title.delete!("\0")
@hwnd = Findwindow.call('RGSS Player', title)
ShowCursor.call(0)
end
return @hwnd
end
#--------------------------------------------------------------------------
# * Client Size
#--------------------------------------------------------------------------
def self.client_size
rect = [0, 0, 0, 0].pack('l4')
Client_rect.call(self.hwnd, rect)
return rect.unpack('l4')[2..3]
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Input
#============================================================================
class << Input
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :method
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias :seph_mouse_input_update :update
alias :seph_mouse_input_trigger? :trigger?
alias :seph_mouse_input_repeat? :repeat?
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
$mouse.update
Mouse.update
seph_mouse_input_update
# Are we using the mouse or the keyboard?
@method = :keyboard if dir4 != 0 || dir8 != 0
end
#--------------------------------------------------------------------------
# * Trigger? Test
#--------------------------------------------------------------------------
def trigger?(constant)
return true if seph_mouse_input_trigger?(constant)
if $mouse.enabled? && !Mouse.pos.nil?
if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
return true if Mouse.trigger?(Mouse::Mouse_to_Input_Triggers.index(constant))
end
end
return false
end
#--------------------------------------------------------------------------
# * Repeat? Test
#--------------------------------------------------------------------------
def repeat?(constant)
return true if seph_mouse_input_repeat?(constant)
if $mouse.enabled? && !Mouse.pos.nil?
if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
return true if Mouse.repeat?(Mouse::Mouse_to_Input_Triggers.index(constant))
end
end
return false
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Map
#============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Tilemap Offset
#--------------------------------------------------------------------------
def tilemap_offset
if $imported && $imported["YEA-CoreEngine"]
[@tilemap.ox - @viewport1.rect.x, @tilemap.oy - @viewport1.rect.y]
else
[@tilemap.ox, @tilemap.oy]
end
end
end
class Game_Map
#--------------------------------------------------------------------------
# * Detect/Set Up Starting Map Event
#--------------------------------------------------------------------------
def setup_starting_map_event
event = @events.values.find {|event| event.starting }
event.clear_starting_flag if event
@interpreter.setup(event.list, event.id, event.trigger_in?([0,1,2,3])) if event
event
end
#--------------------------------------------------------------------------
# * Detect/Set Up Autorun Common Event
#--------------------------------------------------------------------------
def setup_autorun_common_event
event = $data_common_events.find do |event|
event && event.autorun? && $game_switches[event.switch_id]
end
@interpreter.setup(event.list, 0, true) if event
event
end
#--------------------------------------------------------------------------
# * Get ID of Lowest Mouse-enabled Event at Designated Coordinates
#--------------------------------------------------------------------------
def lowest_mouse_event_xy(x, y)
list = events_xy(x, y) + events_xy(x, y+1)
list.sort! {|a, b| b.y - a.y}
evt = nil
list.each do |event|
if (event.pos?(x, y) || (event.pos?(x, y+1) && event.height > 32)) &&
(evt.nil? || event.y > evt.y)
evt = event
break
end
end
return evt
end
end
class Scene_Map
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_scene_map_update update
def update
$mouse.update_event_cursors
update_hud
shaz_mouse_scene_map_update
end
end
#--------------------------------------------------------------------------
# * HUD
#--------------------------------------------------------------------------
def update_hud
mx, my = Mouse.pos
# if mouse is clicked over the hud
if my <= 32 && Mouse.trigger?(0)
# set the menu actor as the leader for any 'personal' commands (equip, skills, etc)
$game_party.menu_actor = $game_party.members[0]
# determine what icon was clicked on
# Menu
if mx.between?(menu_icon_x1, menu_icon_x2) # replace menu_icon_x1 and menu_icon_x2 with the left & right x positions of the menu icon
SceneManager.call(Scene_Menu)
Window_MenuCommand::init_command_position
end
# Items
if mx.between?(items_icon_x1, items_icon_x2)
SceneManager.call(Scene_Item)
end
# Skills
if mx.between?(skill_icon_x1, skill_icon_x2)
SceneManager.call(Scene_Skills)
end
# Equip
if mx.between?(equip_icon_x1, equip_icon_x2)
SceneManager.call(Scene_Equip)
end
# and so on for the rest of your icons
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Event
#============================================================================
module RPG
class Event
class Page
#--------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------
attr_reader :mouse_icon
attr_reader :mouse_text
attr_reader :mouse_position
attr_reader :mouse_autoactivate
#--------------------------------------------------------------------
# * Build Stats
#--------------------------------------------------------------------
def build_stats
# Mouse icons (icon mandatory, others optional)
# <mouse icon destx desty name>
@mouse_icon = nil
@mouse_text = nil
@mouse_position = [0, 0]
@mouse_autoactivate = false
# look for mouse instructions
list.each do |command|
if [108, 408].include?(command.code)
comment = command.parameters[0]
case comment
when /<mouse/i
params = /<mouse (.*)>/i.match(comment)[1].split(' ')
@mouse_icon = params.shift
if params.size > 1 && params[0] =~ /\d+/ && params[1] =~ /\d+/
@mouse_position = [params.shift.to_i, params.shift.to_i]
end
if params.size > 0
@mouse_text = params.join(' ')
end
when /<autoactivate>/
@mouse_autoactivate = true
end
end #if
end #do
end #def
end
end
end
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :mouse_icon
attr_reader :mouse_text
attr_reader :mouse_position
attr_reader :mouse_autoactivate
#--------------------------------------------------------------------------
# * Start Event
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_start start
def start
$game_player.start_event(@id) if !empty?
shaz_mouse_game_event_start
end
#--------------------------------------------------------------------------
# * Clear Event Page Settings
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_clear_page_settings clear_page_settings
def clear_page_settings
shaz_mouse_game_event_clear_page_settings
@mouse_icon = nil
@mouse_text = nil
@mouse_position = [0, 0]
@mouse_autoactivate = false
@height = 0
end
#--------------------------------------------------------------------------
# * Set Up Event Page Settings
#--------------------------------------------------------------------------
alias shaz_mouse_game_event_setup_page_settings setup_page_settings
def setup_page_settings
shaz_mouse_game_event_setup_page_settings
@page.build_stats
@mouse_icon = @page.mouse_icon
@mouse_text = @page.mouse_text
@mouse_position = @page.mouse_position
@mouse_autoactivate = @page.mouse_autoactivate
set_size
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Character
#============================================================================
class Game_CharacterBase
attr_reader :height # Height of character bitmap
#--------------------------------------------------------------------------
# * Initialize Public Member Variables
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_init_public_members init_public_members
def init_public_members
shaz_mouse_game_characterbase_init_public_members
@height = 0
end
#--------------------------------------------------------------------------
# * Change Graphics
# character_name : new character graphic filename
# character_index : new character graphic index
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_set_graphic set_graphic
def set_graphic(character_name, character_index)
shaz_mouse_game_characterbase_set_graphic(character_name, character_index)
set_size
end
#--------------------------------------------------------------------------
# * Set character width/height size
#--------------------------------------------------------------------------
def set_size
bw = Cache.character(@character_name).width
bh = Cache.character(@character_name).height
sign = @character_name[/^[\!\$]./]
if sign && sign.include?('$')
@width = bw / 3
@height = bh / 4
else
@width = bw / 12
@height = bh / 8
end
end
#--------------------------------------------------------------------------
# * Detect Collision with Event
#--------------------------------------------------------------------------
def collide_with_events?(x, y)
$game_map.events_xy_nt(x, y).any? do |event|
self != event && (event.normal_priority? || self.is_a?(Game_Event))
end
end
#--------------------------------------------------------------------------
# * Detect Collision with Vehicle
#--------------------------------------------------------------------------
def collide_with_vehicles?(x, y)
!self.is_a?(Game_Player) && ($game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y))
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_game_characterbase_update update
def update
run_path if @runpath
shaz_mouse_game_characterbase_update
end
#--------------------------------------------------------------------------
# * Run Path
#--------------------------------------------------------------------------
def run_path
return if moving?
@step = @map.nil? || @map[@x, @y].nil? ? 0 : @map[@x, @y] - 1
if @step < 1
clear_path
else
x, y = @x, @y
dirs = []
dirs.push(6) if @map[@x+1, @y] == @step && passable?(@x, @y, 6)
dirs.push(2) if @map[@x, @y+1] == @step && passable?(@x, @y, 2)
dirs.push(4) if @map[@x-1, @y] == @step && passable?(@x, @y, 4)
dirs.push(8) if @map[@x, @y-1] == @step && passable?(@x, @y, 8)
while dirs.size > 0
dir = dirs.delete_at(rand(dirs.size))
move_straight(dir)
break if x != @x || y != @y
end
# clear the path if we couldn't move
clear_path if x == @x && y == @y
end
end
#--------------------------------------------------------------------------
# * Find Path
#--------------------------------------------------------------------------
def find_path(x, y)
sx, sy = @x, @y
@tx, @ty = x, y
result = setup_map(sx, sy)
@runpath = result[0]
@map = result[1]
@map[sx, sy] = result[2] if result[2] != nil
end
#--------------------------------------------------------------------------
# * Clear Path
#--------------------------------------------------------------------------
def clear_path
@map = nil
@runpath = false
end
#--------------------------------------------------------------------------
# * Setup Map
#--------------------------------------------------------------------------
def setup_map(sx, sy)
map = Table.new($game_map.width, $game_map.height)
update_counter = 0
map[@tx, @ty] = 1
old_positions = [[@tx, @ty]]
new_positions = []
# if tile is impassable, but CAN move to adjacent tiles, use the adjacent tiles instead
if (!passable?(@tx, @ty, 2) && !passable?(@tx, @ty, 4) &&
!passable?(@tx, @ty, 6) && !passable?(@tx, @ty, 8)) ||
$game_map.events_xy_nt(@tx, @ty).any? { |evt| evt.normal_priority? && evt != self }
old_positions = []
# Can we move from the destination tile in any direction?
if map_passable?(@tx, @ty, 2)
map[@tx, @ty+1] = 1
old_positions.push([@tx, @ty+1])
end
if map_passable?(@tx, @ty, 8)
map[@tx, @ty-1] = 1
old_positions.push([@tx, @ty-1])
end
if map_passable?(@tx, @ty, 4)
map[@tx-1, @ty] = 1
old_positions.push([@tx-1, @ty])
end
if map_passable?(@tx, @ty, 6)
map[@tx+1, @ty] = 1
old_positions.push([@tx+1, @ty])
end
# If not, can we at least move up to the destination tile?
if old_positions.size == 0
if map_passable?(@tx-1,@ty,6)
map[@tx-1,@ty] = 1
old_positions.push([@tx-1,@ty])
end
if map_passable?(@tx+1,@ty,4)
map[@tx+1,@ty] = 1
old_positions.push([@tx+1,@ty])
end
if map_passable?(@tx,@ty-1,2)
map[@tx,@ty-1] = 1
old_positions.push([@tx,@ty-1])
end
if map_passable?(@tx,@ty+1,8)
map[@tx,@ty+1] = 1
old_positions.push([@tx,@ty+1])
end
end
end
# If there are any counters, can we move to the tile on the other side?
if map_passable?(@tx-2,@ty,6) && $game_map.counter?(@tx-1,@ty)
map[@tx-2,@ty] = 1
old_positions.push([@tx-2,@ty])
end
if map_passable?(@tx+2,@ty,4) && $game_map.counter?(@tx+1,@ty)
map[@tx+2,@ty] = 1
old_positions.push([@tx+2,@ty])
end
if map_passable?(@tx,@ty-2,2) && $game_map.counter?(@tx,@ty-1)
map[@tx,@ty-2] = 1
old_positions.push([@tx,@ty-2])
end
if map_passable?(@tx,@ty+2,2) && $game_map.counter?(@tx,@ty+1)
map[@tx,@ty+2] = 1
old_positions.push([@tx,@ty+2])
end
depth = 2
depth.upto(100) { |step|
break if old_positions[0].nil?
@step = step
loop do
break if old_positions[0].nil?
x, y = old_positions.shift
return [true, map, @step-1] if x == sx && y == sy
if map[x, y + 1] == 0 && passable?(x, y, 2)
map[x, y + 1] = @step
new_positions.push([x, y + 1])
end
if map[x - 1, y] == 0 && passable?(x, y, 4)
map[x - 1, y] = @step
new_positions.push([x - 1, y])
end
if map[x + 1, y] == 0 && passable?(x, y, 6)
map[x + 1, y] = @step
new_positions.push([x + 1, y])
end
if map[x, y - 1] == 0 && passable?(x, y, 8)
map[x, y - 1] = @step
new_positions.push([x, y - 1])
end
# Update graphics? (to reduce lag)
update_counter += 1
if update_counter > 50
Graphics.update
update_counter = 0
end
end
old_positions = new_positions
new_positions = []
}
return [false, nil, nil]
end
end
class Game_Character < Game_CharacterBase
#--------------------------------------------------------------------------
# * Force Move Route
#--------------------------------------------------------------------------
alias shaz_mouse_game_character_force_move_route force_move_route
def force_move_route(move_route)
clear_path
shaz_mouse_game_character_force_move_route(move_route)
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Player
#============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Trigger Map Event
# triggers : Trigger array
# normal : Is priority set to [same as Characters] ?
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_start_map_event start_map_event
def start_map_event(x, y, triggers, normal)
@started_events = []
shaz_mouse_game_player_start_map_event(x, y, triggers, normal)
end
#--------------------------------------------------------------------------
# * Start Event
#--------------------------------------------------------------------------
def start_event(event_id)
@started_events = [] if @started_events.nil?
@started_events.push(event_id)
end
#--------------------------------------------------------------------------
# * Processing of Movement via Input from Directional Buttons
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_move_by_input move_by_input
def move_by_input
if Input.dir4 > 0
clear_path
shaz_mouse_game_player_move_by_input
else
# Move by mouse input
if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&
!@vehicle_getting_on && !@vehicle_getting_off &&
Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored? && Mouse.pos[1] > 32
mx, my = *Mouse.grid
# turn in direction
if (@x - mx).abs >= (@y - my).abs
set_direction(@x > mx ? 4 : 6)
else
set_direction(@y > my ? 8 : 2)
end
# find path
@event = $game_map.lowest_mouse_event_xy(mx, my)
if @event.nil?
find_path(mx, my)
elsif @event.mouse_autoactivate
@event.start
@started_events = []
clear_path
else
find_path(@event.x + @event.mouse_position[0],
@event.y + @event.mouse_position[1])
end
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_game_player_update update
def update
shaz_mouse_game_player_update
update_pathfinding if [email protected]? && !moving?
end
#--------------------------------------------------------------------------
# * Check event after pathfinding
#--------------------------------------------------------------------------
def update_pathfinding
if @map.nil? || @map[@x, @y] <= 1
dir = @x < @event.x ? 6 : @x > @event.x ? 4 : @y < @event.y ? 2 : @y > @event.y ? 8 : 0
# Face event and trigger it (only if not triggered by start_map_event)
turn_toward_character(@event) if [email protected]?(@x, @y)
if !@started_events.include?(@event.id) && [email protected]? && !in_airship?
@event.start
@started_events = []
end
clear_path
end
end
#--------------------------------------------------------------------------
# * Clear Path
#--------------------------------------------------------------------------
def clear_path
@event = nil
super
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Interpreter
#============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Event Setup
#--------------------------------------------------------------------------
alias shaz_mouse_game_interpreter_setup setup
def setup(list, event_id = 0, lock_player = false)
shaz_mouse_game_interpreter_setup(list, event_id)
@lock_player = lock_player
end
#--------------------------------------------------------------------------
# * Execute
#--------------------------------------------------------------------------
alias shaz_mouse_game_interpreter_run run
def run
$mouse.ignored = true if @lock_player
shaz_mouse_game_interpreter_run
$mouse.ignored = false if @lock_player
end
end
#============================================================================
# SUPER SIMPLE MOUSE SCRIPT
# Windows
#============================================================================
class Window_Selectable < Window_Base
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias shaz_mouse_window_selectable_update update
def update
shaz_mouse_window_selectable_update
process_mouse_handling if Input.method == :mouse
end
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled? && cursor_movable?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
if mx.between?(vx, vx + self.width) &&
my.between?(vy, vy + self.height)
mx -= vx
mx -= padding
my -= vy
my -= padding
my += oy
for i in 0 ... item_max
rect = item_rect(i)
if mx.between?(rect.x, rect.x + rect.width) &&
my.between?(rect.y, rect.y + rect.height)
last_index = @index
select(i)
if @index != last_index
Sound.play_cursor
end
break
end
end
end
end
end
class Window_NameInput < Window_Selectable
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = (self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x) + padding
vy = (self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y) + padding
if mx.between?(vx, vx + self.width - padding * 2) &&
my.between?(vy, vy + self.height - padding * 2)
mx -= vx
my -= vy
x = (mx > 5*32+16 ? mx-16 : mx) / 32
y = my / line_height
last_index = @index
@index = y * 10 + x
Sound.play_cursor if @index != last_index
end
end
end
class Scene_File < Scene_MenuBase
#--------------------------------------------------------------------------
# * Update Cursor
#--------------------------------------------------------------------------
alias shaz_mouse_scene_file_update_cursor update_cursor
def update_cursor
shaz_mouse_scene_file_update_cursor
process_mouse_handling if Input.method == :mouse
end
#--------------------------------------------------------------------------
# * Mouse Movement Processing
#--------------------------------------------------------------------------
def process_mouse_handling
return unless $mouse.enabled?
# Add a delay to prevent too-fast scrolling
@delay = @delay ? @delay + 1 : 0
return if @delay % 3 > 0
mx, my = *Mouse.position
vx = @savefile_viewport.ox + mx
vy = @savefile_viewport.oy + my
last_index = @index
new_index = vy / savefile_height
if @index != new_index
if new_index > @index
cursor_down(false)
else
cursor_up(false)
end
Sound.play_cursor
@savefile_windows[last_index].selected = false
@savefile_windows[@index].selected = true
end
end
end
If you make changes to a script and need help, if it's a huge script, please don't post the whole thing - just the bits that you changed.
Those changes are based on a hud going the whole way across the bottom. For your purposes, that won't be good, because your hud is along the right, and you don't want to make the entire bottom of every map to the height of the hud inaccessible.
I really should redo it to make it easier to have hud elements anywhere on the screen. Can you work on other things in the meantime and just leave the hud processing out for a while? I do have to do some work for someone else on the mouse script in the next couple of days, so I'll try and take care of this at the same time.
Those changes are based on a hud going the whole way across the bottom. For your purposes, that won't be good, because your hud is along the right, and you don't want to make the entire bottom of every map to the height of the hud inaccessible.
I really should redo it to make it easier to have hud elements anywhere on the screen. Can you work on other things in the meantime and just leave the hud processing out for a while? I do have to do some work for someone else on the mouse script in the next couple of days, so I'll try and take care of this at the same time.
Oh sure, it is not that important that I need it right away. Just do you work and if you have some time, maybe you can do this. Thank you.
How would I change the size of the text that is displayed when you hover the mouse over an event?
The popup text is a little large for my needs, so if it could be changed that'd be grand
The popup text is a little large for my needs, so if it could be changed that'd be grand
Try this ... find this line in the script (in the current version in pastebin, it's line 121):
Immediately after it, add this line:
changing n to whatever font size you want to use. I forget what the default is (I think it might be 24, so maybe try 22 or 20) - just experiment until you find something that you're happy with.
Code:
@dummy = Bitmap.new(32, 32)
Immediately after it, add this line:
Code:
@dummy.font.size = n
changing n to whatever font size you want to use. I forget what the default is (I think it might be 24, so maybe try 22 or 20) - just experiment until you find something that you're happy with.
Thank you, worked like an absolute charm. And thank you also for the near-instant reply! I'm also having another issue with this script, if you could lend me your ear for a little longer.
Regarding the ability to 'offset' the pathfinding to an event (mouse look 2, 0): after playing with the script for a while, it seems that an event with an offset involved won't run when clicked on if you're already standing next to it.
OH! And (sorry about the question storm) is there a way to implement a ranged attack, i.e., to activate an event via mouse click without the player character first having to move towards it? I'm working on a Blade Runner-esque cyberpunk game and the ability to shoot would be v.useful.
Thanks again!
EDIT
Yikes, could I also ask if there's a way to make the player-character something you can click on to run a common event?
The issue with the offset has already been reported - I thought I had resolved that. Do you have the latest version of the script?
Yes, you can do a ranged attack, where an event will activate without the player first moving towards it. Check the notes on version 1.10 in the script header.
There is no way to make the player clickable - it only works on events. You would need a mod to trigger a common event when clicking on the player.
Yes, you can do a ranged attack, where an event will activate without the player first moving towards it. Check the notes on version 1.10 in the script header.
There is no way to make the player clickable - it only works on events. You would need a mod to trigger a common event when clicking on the player.
Is version 1.10 the most recent version? If so, that's the one I'm already using and the offset issue is still there 🙁
Not being able to click on the player is okay, was just a thought. Although I do want to assign a different button to the right button on the mouse.
I've found that section of the script (or at least I think I have), and changed it to this:
Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::X, 2 => Input::X}
But when I have a parallel process event running, "IF button 'X' is pressed, do this", the right mouse button doesn't activate it. Pressing the 'A' key on the keyboard (X=A) activates the event, so I know the event is working right.
I can't find anything about ranged attacks in the script notes. I've tinkered with a few different settings and wotnot but the player character either moves or the event won't activate 🙁
The version number may not be correct. Does your version have this at the top, as the last revision comment?
Putting <autoactivate> in a comment at the top of the event page will cause the event to activate when clicked on, without the player walking up to it.
Code:
# 1.10 - 6 Apr 2014 - add interaction for top part of > 32pixel high event
# - activate an event without walking up to it
# (add <autoactivate> comment at top of event page)
# - arrow keys override mouse movement when pathfinding
# - ignore mouse in menus when using keyboard
# - make player walk to counter opposite shopkeepers
Putting <autoactivate> in a comment at the top of the event page will cause the event to activate when clicked on, without the player walking up to it.
I read on your profile page that you hail from Australia - even so, did you hear the thunderous clapping sound as my palm met my forehead?
I was determined not to post my last comment until I was sure I'd read the notes thoroughly, like you suggested. Sincere apologies.
Any thoughts on why I can't get my RMB to activate a parallel process event?
So, I've got another idea for my game, I don't know if it is possible to do for this mouse script.
What if there would be some simple animation on the ground at the point where we click. Is it possible to implement?
What if there would be some simple animation on the ground at the point where we click. Is it possible to implement?
@Shaz I ran into a pretty strange problem when I'm using your HUD extension of your mouse script. First, here is the part of your mouse script, which prevents me from activating the events when I'm standing next to them, if I click on a HUD icon. This is fine, it works as intended.

Now, unfortunately this has a strange side effect. If an event is outside of the 590/380 pixel area specified above (this is shown with red in the following picture), then I can't activate an event if I'm standing next to it, only if I activate them from more than a tile distance.


Now, unfortunately this has a strange side effect. If an event is outside of the 590/380 pixel area specified above (this is shown with red in the following picture), then I can't activate an event if I'm standing next to it, only if I activate them from more than a tile distance.

Original thread: https://forums.rpgmakerweb.com/threads/amaranths-super-simple-mouse-system-for-ace.17829/