Opis:
Skrypt ten pozwala nam posługiwać się myszką podczas gry. Dzięki myszce możemy chodzić, aktywować zdarzenia, wchodzić/wychodzić z menu (lewy przycisk myszy działa jak Enter, zaś prawy jak Esc), wybierać opcję w oknach wyboru itd. Pozwala również wyświetlać krótkie informacje nad głową zdarzenia. Zawiera kilka opcji konfiguracji.
Jest również dodatek do skryptu, pozwalający uruchomić typowe zdarzenie po kliknięciu prawym bądź lewym przyciskiem myszy na postać lub kafelek z tilesetów B~E.
Dodałam kilka modyfikacji, m.in. możliwość uruchomienia typowego zdarzenia, po kliknięciu PPM na zdarzenie.
Autor:
Jet (Jet10985)
Wykorzystał fragmenty kodów autorstwa: Woratana, Berka
System myszki wykorzystuje skrypt Szukanie drogi Modern Algebra'y
Tłumaczenie i modyfikacje:
Avara
Skrypt:
Część I
Spoiler:
Kod:
#===============================================================================
# System Myszki / Mouse System
# Autor: Jet10985 (Jet)
# Część kodu autorstwa: Woratana, Berka
# Użyty do: skryptu Szukanie drogi Modern Algebra'y
# Super ciężkie testowanie/pomoc w usuwaniu bug'ów/na prośbę: Nathanial (Beleren)
# Tłumaczenie i modyfikacja kodu: Avara (www.ultimateam.pl)
# Wersja modyfikacji Avary: 1.0
#===============================================================================
# Skrypt ten pozwoli Ci w pełni korzystać z myszki wewnątrz rmvx do różnych
# celów.
# Skrypt ten posiada: 6 dostosowywania opcji.
#===============================================================================
# Nadpisane definicje:
# Brak
#-------------------------------------------------------------------------------
# Dopiski do definicji:
# Scene_Map: update, terminate, update_transfer_player, update_call_menu
# Input: update, trigger?, press?, repeat?, dir4, dir8
# Window_Selectable: update, top_row=
# Scene_File: update
# Window_NameInput: update
# Game_Temp: initialize
# Game_Event: initialize, update
#===============================================================================
#==============================================================================
# Szukanie drogi - Path Finding
# Wersja: 2.0
# Autor: modern algebra (rmrk.net)
# Data: April 10, 2008
#==============================================================================
# Podziękowania:
# Patrick Lester! For his tutorial on A* Pathfinding algorithm (found at:
# http://www.gamedev.net/reference/articles/article2003.asp) as well as
# another amazingly helpful tutorial on using binary heaps (found at:
# http://www.policyalmanac.org/games/binaryHeaps.htm). Without his excellent
# tutorials, this script would not exist. So major thanks to him.
# Zeriab, for tricking me into believing that this was an actual exercise.
# Also, his table printout actually makes Tables useable :P
#==============================================================================
=begin
Wyświetlanie tekstu nad zdarzeniem, po najechaniu myszką:
Jeśli chcesz aby pojawił się komunikat nad głową zdarzenia, gdy myszka jest nad
zdarzeniem, umieścić ten komentarz w zdarzeniu:
MOUSE TEXT Wiadomość
Wszystko po TEXT będzie wyświetlane nad zdarzeniem.
--------------------------------------------------------------------------------
Zmiana kursora myszki po najechaniu nią na zdarzenie:
Jeśli chcesz chwilowo zmienić kursor myszki na czas najechania nią na zdarzenie,
umieścić ten komentarz w zdarzeniu:
MOUSE PIC nazwa/numer
Możesz umieścisz nazwę obrazka z folderu "Graphics\System". Kursor myszki zmieni
się wówczas w ten obrazek. Jeśli jednak umieścisz numer, myszka zmieni się
w ikonę o podanym numerze ID.
--------------------------------------------------------------------------------
Sposób wyznaczania trasy do zdarzenia po kliknięciu myszki:
Jeśli chcesz aby gracz podszedł do zdarzenia z konkretnej strony, po kliknięciu
na zdarzenie, aby do tego zdarzenia podszedł, umieścić jeden z tych komentarzy
w zdarzeniu:
MOUSE MOVE UP/LEFT/RIGHT/DOWN
Umieścić tylko ten kierunek, z którego ma podejść gracz.
--------------------------------------------------------------------------------
Kliknięcie, aby aktywować:
Jeśli chcesz, aby automatycznie uruchomić zdarzenie (bez podchodzenia do niego),
gdy jest kliknięte, umieść to w komentarzu zdarzenia:
MOUSE CLICK
--------------------------------------------------------------------------------
Brak zatrzymania gracza, podczas przejścia nad zdarzeniem, uruchamianym dotykiem:
Domyślnie skrypt ten zatrzyma ruch spowodowany kliknięciem myszki, jeśli gracz
wejdzie nad/pod zdarzenie wywoływane dotykiem gracza/zdarzenia. Jeśli chcesz
aktywować zdarzenie, ale gracz ma kontynuować marsz do wyznaczonego miejsca,
umieścić ten komentarz w zdarzeniu:
MOUSE NOSTOP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Od Avary: Ja z takim problemem się nie spotkałam. W kodzie skryptu również nie
ma wykorzystania takiego polecenia. Prawdopodobnie problem został rozwiązany
i autor zapomniał usunąć to polecenie z instrukcji.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--------------------------------------------------------------------------------
Ignorowanie ​zdarzeń:
Jeśli chcesz, aby zdarzenie było ignorowane, podczas ruchu spowodowanego
kliknięciem ​​myszki (tak jakby zdarzenie nie istniało), umieścić ten komentarz
w zdarzeniu:
MOUSE THROUGH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Od Avary: Ta funkcja chyba nie działa. Jest wzięta pod uwagę w kodzie, jednak
podczas testów nie widziałam, by działała prawidłowo.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--------------------------------------------------------------------------------
Dodatkowe uwagi:
W oknach wyboru, które mają więcej opcji niż jest to pokazane, gracze mogą
albo umieścić kursor pod oknem, aby przewinąć w dół, lub użyć kółka myszki
do przewijania w górę/w dół.
Można aktywować zdarzenia, uruchamiane przyciskiem akcji, stojąc obok zdarzenia
i klikając na nie myszką.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Od Avary: W demie jest podane jeszcze jedno polecenie:
MOUSE CONTROL
Po kliknięciu PPM na zdarzenie powinno się przejąć nad nim kontrolę, ale nie
zostało wyjaśnione na czym ta kontrola polega. Również w kodzie skryptu nie
znalazłam wykorzystania tego polecenia.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--------------------------------------------------------------------------------
Modyfikacja Avary:
Dodałam 2 nowe polecenia.
-> Jeśli chcesz, by kliknięcie PPM na danym zdarzeniu, uruchamiało typowe
zdarzenie, wpiszcie w komentarzu zdarzenia:
MOUSE RIGHT-CLICK numer
Numer to ID typowego zdarzenia.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-> Jeśli chcesz nadać kolor tekstowi, wyświetlanego nad głową zdarzenia (za
pomocą polecenia MOUSE TEXT), to wówczas dodaj do komentarza polecenie:
MOUSE COLOR-TEXT numer
Gdzie "numer" to numer kolorowego kwadracika w pliku "Window", który powinieneś
znaleść w folderze Graphic\System swojej gry lub w miejscu gdzie masz
zainstalowane RTP, czyli domyślnie w folderze:
C:\Program Files\Common Files\Enterbrain\RGSS2\RPGVX\Graphics\System\
W prawym dolnym rogu pliku "Window" znajdują się 32 kolorowe kwadraciki. Pierwszy
z nich (biały) ma przypisany numer 0, ostatni zaś 31. Wpisz numer kwadracika,
w którego kolorze ma się wyświetlić tekst.
=end
module JetMouse
# Jeśli korzystasz z obrazków, to jest to.
# Musi być w folderze Graphics/System.
CURSOR_PICTURE = "cursor-mouse" # Nazwa podstawowego obrazka myszki.
# Jeśli nie korzystasz z obrazka myszki, ta ikona będzie wyświetlana jako mysz.
# Aby użyć ikony, wystarczy umieścić nazwę nieistniejącego obrazka
# jak w powyższej konfiguracji.
ICON_INDEX = 3 # Numer ID ikony.
# Czy chcesz aby gracz mógł chodzić klikając myszką?
ALLOW_MOUSE_MOVEMENT = true # true - tak ; false - nie
# Czy chcesz, aby ruch postaci po kliknięciu myszki był 8-kierunkowy?
# Wymaga skryptu 8-Dir Walking autorstwa Jet!
DO_8DIR_WALKING = false # true - tak ; false - nie
# Gdy ten przełącznik będzie włączony, kursor myszki będzie niewidoczny
# i bezużyteczny, aż przełącznik zostanie wyłączony.
TURN_MOUSE_OFF_SWITCH = 20 # Numer ID przełącznika.
# Czy chcesz, aby była możliwość przewijania kółkiem myszy w oknie wyboru?
# Gdy ta opcja jest wyłączona może zmniejszyć niektóre rzadkie przypadki lag'ów.
USE_WHEEL_DETECTION = false # true - tak ; false - nie
end
module Avara
module JetMouseSystem
# Jeśli NIE chcesz, aby PPM uruchamiał menu w grze zmień poniższą konfigurację
# na "true".
BLOKADA_MENU = false # true - blokada ; false - brak blokady
end
end
#===============================================================================
# DALEJ NIE EDYTUJ, CHYBA ŻE WIESZ CO ROBISZ!
#===============================================================================
module Mouse
def click?(button)
return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return true if @keys.include?(button)
return false
end
def press?(button)
return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return true if @press.include?(button)
return false
end
def set_pos(x_pos = 0, y_pos = 0)
width,height = client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
SetCursorPos.call(client_pos[0] + x_pos,client_pos[1] + y_pos)
end
end
def update
return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
@pos = Mouse.pos
@keys, @press = [], []
@keys.push(1) if GetAsyncKeyState.call(1)&0x01==1
@keys.push(2) if GetAsyncKeyState.call(2)&0x01==1
@keys.push(3) if GetAsyncKeyState.call(4)&0x01==1
@press.push(1) if pressed?(1)
@press.push(2) if pressed?(2)
@press.push(3) if pressed?(4)
end
def pressed?(key)
return true unless GetKeyState.call(key).between?(0, 1)
return false
end
def pos
return 0, 0 if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
x, y = screen_to_client(*global_pos)
width, height = client_size
begin
x = 0 if x <= 0; y = 0 if y <= 0
x = width if x >= width; y = height if y >= height
return x, y
end
end
def screen_to_client(x, y)
return nil unless x && y
pos = [x, y].pack('ll')
ScreenToClient.call(@handle, pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
end
def client_size
rect = [0, 0, 0, 0].pack('l4')
GetClientRect.call(@handle, rect)
right,bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def client_pos
rect=[0, 0, 0, 0].pack('l4')
GetWindowRect.call(@handle, rect)
left, upper = rect.unpack('l4')[0..1]
return left + 4, upper + 30
end
def grid
return [-1, -1] if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
return [-1, -1] if @pos.nil?
return [(@pos[0]/32), (@pos[1]/32)]
end
def change_cursor(cursor)
self.bitmap.dispose unless self.bitmap.nil?
self.bitmap = nil
begin
self.bitmap = Cache.system(cursor)
@current_cursor = cursor
@not_default = true
rescue
begin
self.bitmap = Bitmap.new(24, 24)
bitmap = Cache.system("Iconset")
rect = Rect.new(cursor % 16 * 24, cursor / 16 * 24, 24, 24)
self.bitmap.blt(0, 0, bitmap, rect)
@current_cursor = cursor
@not_default = true
rescue
create_cursor(CURSOR_PICTURE)
end
end
end
def update
if $game_switches[TURN_MOUSE_OFF_SWITCH]
self.opacity = 0 unless self.opacity == 0
end
self.opacity = 255 unless self.opacity == 255
super
x = self.x
y = self.y
self.x, self.y = Mouse.pos
self.x -= 8 if @not_default
self.y -= 8 if @not_default
end
def dispose
super
end
end
$cursor = Sprite_Cursor.new
module Input
class << self
alias jet5888_press? press? unless $@
def press?(arg)
if arg == Input::C
return true if Mouse.press?(1)
elsif arg == Input::B
return true if Mouse.press?(2)
end
jet5888_press?(arg)
end
alias jet5888_repeat? repeat? unless $@
def repeat?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_repeat?(arg)
end
alias jet5888_trigger? trigger? unless $@
def trigger?(arg)
if arg == Input::C
return true if Mouse.click?(1)
elsif arg == Input::B
return true if Mouse.click?(2)
end
jet5888_trigger?(arg)
end
alias jet8432_update update unless $@
def update(*args, &block)
jet8432_update(*args, &block)
if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH] && $cursor.opacity != 0
$cursor.opacity = 0
end
$cursor.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
Mouse.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
end
alias jet1626_dir4 dir4 unless $@
def dir4(*args, &block)
if !$game_temp.nil?
if $game_temp.move_because_of_mouse
if !$game_temp.mouse_path.empty? && $game_player.movable? &&
!$game_map.interpreter.running? && $scene.is_a?(Scene_Map)
f = $game_temp.mouse_path.reverse!.pop
$game_temp.mouse_path.reverse!
return f.code * 2
else
$game_temp.move_because_of_mouse = false
end
end
end
jet1626_dir4(*args, &block)
end
alias jet1626_dir8 dir8 unless $@
def dir8(*args, &block)
if !$game_temp.nil?
if $game_temp.move_because_of_mouse
if !$game_temp.mouse_path.empty? && $game_player.movable? &&
!$game_map.interpreter.running? && $scene.is_a?(Scene_Map)
f = $game_temp.mouse_path.reverse!.pop
$game_temp.mouse_path.reverse!
if [1, 2, 3, 4].include?(f.code)
return f.code * 2
else
case f.code
when 5
return 1
when 6
return 3
when 7
return 7
when 8
return 9
end
end
else
$game_temp.move_because_of_mouse = false
end
end
end
jet1626_dir8(*args, &block)
end
end
end
class Game_Character
def find_mouse_path(trgt_x, trgt_y)
path = $game_map.find_path (self.x, self.y, trgt_x, trgt_y,
JetMouse::DO_8DIR_WALKING, 0, self)
return [] if path.empty? or trgt_x == self.x && trgt_y == self.y
return path.reverse!
end
end
class Game_Map
def removefrom_binaryheap
@open_nodes[1] = @open_nodes[@listsize]
@listsize -= 1
v = 1
loop do
u = v
w = 2*u
if w + 1 <= @listsize
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
v = w + 1 if @total_cost[@open_nodes[v]] >= @total_cost[@open_nodes[w + 1]]
elsif w <= @listsize
v = w if @total_cost[@open_nodes[u]] >= @total_cost[@open_nodes[w]]
end
if u == v
break
else
temp = @open_nodes[u]
@open_nodes[u] = @open_nodes[v]
@open_nodes[v] = temp
end
end
end
def find_path (src_x, src_y, trgt_x, trgt_y, diagonal, max_iterations, char)
$game_temp.making_path = true
path = []
return path if !char.passable? (trgt_x, trgt_y)
max_elements = width*height + 2
openx = Table.new (max_elements)
openy = Table.new (max_elements)
@open_nodes = Table.new (max_elements)
@total_cost = Table.new (max_elements)
heuristic = Table.new (max_elements)
step_cost = Table.new (width, height)
parent_x = Table.new (width, height)
parent_y = Table.new (width, height)
actual_list = Table.new (width, height)
new_openid = 1
@open_nodes[1] = 1
openx[1] = src_x
openy[1] = src_y
dist = [(trgt_x - src_x).abs, (trgt_y - src_y).abs]
heuristic[1] = diagonal ? (dist.max*14) + (dist.min*10) : (dist[0] + dist[1])*10
@total_cost[1] = heuristic[1]
actual_list[src_x, src_y] = 1
@listsize = 1
count = 0
loop do
break if actual_list[trgt_x, trgt_y] != 0
count += 1
Graphics.update if count % 500 == 0
return path if count == max_iterations
return path if @listsize == 0
node = @open_nodes[1]
parent_xval, parent_yval = openx[node], openy[node]
actual_list[parent_xval, parent_yval] = 2
removefrom_binaryheap
for i in 0...8
break if i > 3 && !diagonal
x, y = case i
when 0 then [parent_xval, parent_yval - 1]
when 1 then [parent_xval, parent_yval + 1]
when 2 then [parent_xval - 1, parent_yval]
when 3 then [parent_xval + 1, parent_yval]
when 4 then [parent_xval - 1, parent_yval - 1]
when 5 then [parent_xval + 1, parent_yval - 1]
when 6 then [parent_xval - 1, parent_yval + 1]
when 7 then [parent_xval + 1, parent_yval + 1]
end
next if actual_list[x,y] == 2
next unless char.passable? (x, y)
if i > 3
next unless case i
when 4 then char.passable? (x + 1, y) || char.passable? (x, y + 1)
when 5 then char.passable? (x - 1, y) || char.passable? (x, y + 1)
when 6 then char.passable? (x + 1, y) || char.passable? (x, y - 1)
when 7 then char.passable? (x - 1, y) || char.passable? (x, y - 1)
end
end
plus_step_cost = ((x - parent_xval).abs + (y - parent_yval).abs) > 1 ? 14 : 10
temp_step_cost = step_cost[parent_xval, parent_yval] + plus_step_cost
if actual_list[x,y] == 1
if temp_step_cost < step_cost[x, y]
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
step_cost[x, y] = temp_step_cost
index = 1
while index < @listsize
index += 1
break if openx[@open_nodes[index]] == x &&
openy[@open_nodes[index]] == y
end
@total_cost[@open_nodes[index]] = temp_step_cost + heuristic[@open_nodes[index]]
else
next
end
else
new_openid += 1
@listsize += 1
@open_nodes[@listsize] = new_openid
step_cost[x, y] = temp_step_cost
d = [(trgt_x - x).abs, (trgt_y - y).abs]
heuristic[new_openid] = diagonal ? (d.max*14) + (d.min*10) : (d[0] + d[1])*10
@total_cost[new_openid] = temp_step_cost + heuristic[new_openid]
parent_x[x, y] = parent_xval
parent_y[x, y] = parent_yval
openx[new_openid] = x
openy[new_openid] = y
index = @listsize
actual_list[x, y] = 1
end
while index != 1
temp_node = @open_nodes[index]
if @total_cost[temp_node] <= @total_cost[@open_nodes[index / 2]]
@open_nodes[index] = @open_nodes[index / 2]
index /= 2
@open_nodes[index] = temp_node
else
break
end
end
end
end
path_x, path_y = trgt_x, trgt_y
while path_x != src_x || path_y != src_y
prnt_x, prnt_y = parent_x[path_x, path_y], parent_y[path_x, path_y]
if path_x < prnt_x
code = path_y < prnt_y ? 7 : path_y > prnt_y ? 5 : 2
elsif path_x > prnt_x
code = path_y < prnt_y ? 8 : path_y > prnt_y ? 6 : 3
else
code = path_y < prnt_y ? 4 : 1
end
path.push (RPG::MoveCommand.new (code))
path_x, path_y = prnt_x, prnt_y
end
$game_temp.making_path = false
return path
end
end
alias jet6742_initialize initialize unless $@
def initialize(*args, &block)
jet6742_initialize(*args, &block)
@move_because_of_mouse = false
@making_path = false
@mouse_path = []
end
end
class Window_Selectable
alias jet6742_update update unless $@
def update(*args, &block)
jet6742_update(*args, &block)
form_rect_array if @rect_array.nil?
update_mouse if self.active && self.visible && !@rect_array.nil?
end
alias jet7222_top_row top_row= unless $@
def top_row=(*args, &block)
@last_cursor_move = 0 if @last_cursor_move.nil?
@last_cursor_move -= 1
return if @in_rect_loop || @last_cursor_move > 0
jet7222_top_row(*args, &block)
@last_cursor_move = 10
end
def form_rect_array
@rect_array = []
orig_index = @index
@in_rect_loop = true
(0..@item_max - 1).each do |i|
@index = i
update_cursor
rect = self.cursor_rect
ix = self.x + 16 + rect.x
iy = self.y + 16 + rect.y
@rect_array.push(Rect.new(ix, iy, rect.width, rect.height))
end
@in_rect_loop = false
@index = orig_index
update
end
def update_mouse
if JetMouse::USE_WHEEL_DETECTION
f = Mouse.scroll
if !f.nil?
if f[2] < 0
if contents.height > self.height && self.oy - contents.height < -self.height + 32
self.top_row = self.top_row + 1
end
else
self.top_row = self.top_row - 1 if contents.height > self.height
end
end
end
original_index = @index
fake_index = -2
for rect in @rect_array
if Mouse.area?(rect.x - self.ox, rect.y - self.oy, rect.width, rect.height)
fake_index = @rect_array.index(rect)
break
end
end
@index = fake_index == -2 ? original_index : fake_index
update_cursor
end
end
class Window_NameInput
alias wor_winnam_upd_mouse update unless $@
def update(*args, &block)
wor_winnam_upd_mouse(*args, &block)
if self.active and self.visible
(0..TABLE[@mode].size - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy
@index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
end
class Window_PartyCommand
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 16 + irect.x - self.ox
iry = 288 + 16 + irect.y - self.oy
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
class Window_ActorCommand
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.viewport.ox + 288 + 16 + irect.x
iry = 288 + 16 + irect.y
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
class Window_Message
def update_mouse
(0..@item_max - 1).each do |i|
irect = item_rect(i)
irx = self.x + 16 + irect.x - self.ox
iry = self.y + 16 + irect.y - self.oy + ($game_message.choice_start * WLH)
self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
end
end
end
class Window_ShopSell
def refresh
super
form_rect_array
end
end
class Scene_File
alias wor_scefil_upd_mouse update unless $@
def update(*args, &block)
(0..@item_max - 1).each do |i|
ix = @savefile_windows[i].x
iy = @savefile_windows[i].y
iw = @savefile_windows[i].width
ih = @savefile_windows[i].height
if Mouse.area?(ix, iy, iw, ih)
@savefile_windows[@index].selected = false
@savefile_windows[i].selected = true
@index = i
end
end
wor_scefil_upd_mouse(*args, &block)
end
end
class Window_EventPopUp < Window_Base
def initialize(x, y, width, height, text, color)
super(x, y, width, height)
self.opacity = 0
@text = text
@color = color
refresh
end
def text_color(n)
x = 64 + (n % 8) * 8
y = 96 + (n / 8) * 8
return windowskin.get_pixel(x, y)
end
def refresh
self.contents.clear
self.contents.font.color = text_color(@color)
self.contents.draw_text(0, 0, self.width, 24, @text)
end
end
class Game_Event
attr_accessor :popup_window, :page
def check_for_comment(regexp)
return false if @list.nil?
for item in @list
if item.code == 108 or item.code == 408
if !item.parameters[0][regexp].nil?
return $1.nil? ? true : $1
end
end
end
return false
end
def through
return true if check_for_comment(/MOUSE THROUGH/i) && $game_temp.making_path
return @through
end
alias jet2734_update update unless $@
def update(*args, &block)
jet2734_update(*args, &block)
update_mouse_popup
update_mouse_change
update_mouse_right_click
end
def update_mouse_popup
switch = $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
if Mouse.true_grid == [self.x, self.y] && !switch && !@erased
f = self.check_for_comment(/MOUSE TEXT (.+)/i)
if f != false
q = Bitmap.new(1, 1)
size = q.text_size(f)
x = self.screen_x - 16 - size.width / 2
y = self.screen_y - 52 - size.height / 2
if self.popup_window != nil
self.popup_window.dispose
self.popup_window = nil
end
if self.check_for_comment(/MOUSE COLOR-TEXT (.+)/i)
color = (self.check_for_comment(/MOUSE COLOR-TEXT (.+)/i) rescue 0).to_i
else
color = 0
end
self.popup_window = Window_EventPopUp.new(x, y,
size.width + 34, size.height + 34, f, color)
q.dispose
q = nil
end
else
if self.popup_window != nil
self.popup_window.dispose
self.popup_window = nil
end
end
end
def update_mouse_change
if Mouse.true_grid == [self.x, self.y]
f = (self.check_for_comment(/MOUSE PIC (.+)/i) rescue false)
if f != false
if f.to_i != 0
$cursor.change_cursor(f.to_i) unless $cursor.current_cursor == f.to_i
else
$cursor.change_cursor(f) unless $cursor.current_cursor == f
end
$game_temp.did_mouse_change = true
end
end
end
def update_mouse_right_click
return if $game_map.interpreter.running?
if Mouse.click?(2)
if Mouse.true_grid == [self.x, self.y]
if self.check_for_comment(/MOUSE RIGHT-CLICK (.+)/i)
f = (self.check_for_comment(/MOUSE RIGHT-CLICK (.+)/i) rescue false)
if f != false
if f.to_i != 0
$game_temp.common_event_id = f.to_i
end
end
end
end
end
end
end
class Scene_Map
alias jet6742_update update unless $@
def update(*args, &block)
if !$game_message.visible
update_mouse_left_click
end
jet6742_update(*args, &block)
check_mouse_change
end
alias jet7811_terminate terminate unless $@
def terminate(*args, &block)
for event in $game_map.events.values
next if event.popup_window.nil?
event.popup_window.dispose unless event.popup_window.disposed?
event.popup_window = nil
end
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
$cursor.opacity = 0
jet7811_terminate(*args, &block)
$cursor.opacity = 255 unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
end
alias jet8887_update_transfer_player update_transfer_player unless $@
def update_transfer_player(*args, &block)
if $game_player.transfer?
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
end
jet8887_update_transfer_player(*args, &block)
end
def check_mouse_change
return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
if $game_message.visible || $game_player.transfer?
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
JetMouse::ICON_INDEX].include?($cursor.current_cursor)
return
end
$cursor.create_cursor(JetMouse::CURSOR_PICTURE) if $game_temp.did_mouse_change.nil? &&
![JetMouse::CURSOR_PICTURE, JetMouse::ICON_INDEX].include?($cursor.current_cursor)
$game_temp.did_mouse_change = nil
end
def do_closest_path_check(ev)
se = $game_player
sx = se.x - ev.x
sy = se.y - ev.y
if sx != 0 or sy != 0
if sx.abs >= sy.abs
if sx >= 0
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
if sy >= 0
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
end
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
if sy < 0
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
end
elsif sx < 0
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
if sy >= 0
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
end
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
if sy < 0
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
end
end
else
if sy > 0
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
if sx >= 0
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
end
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
if sx < 0
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
end
elsif sy < 0
if $game_map.passable?(ev.x, ev.y - 1)
return [ev.x, ev.y - 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y - 1, false, 0, se).empty?
end
if sx >= 0
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
end
if $game_map.passable?(ev.x, ev.y + 1)
return [ev.x, ev.y + 1] unless $game_map.find_path(se.x, se.y,
ev.x, ev.y + 1, false, 0, se).empty?
end
if sx < 0
if $game_map.passable?(ev.x + 1, ev.y)
return [ev.x + 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x + 1, ev.y, false, 0, se).empty?
end
else
if $game_map.passable?(ev.x - 1, ev.y)
return [ev.x - 1, ev.y] unless $game_map.find_path(se.x, se.y,
ev.x - 1, ev.y, false, 0, se).empty?
end
end
end
end
end
return false
end
def update_mouse_left_click
return if $game_map.interpreter.running? || $game_player.transfer?
if Mouse.click?(1)
event_activated = false
for event in $game_map.events_xy(*Mouse.true_grid)
if event.check_for_comment(/MOUSE CLICK/i)
event.start
event_activated = true
elsif (event.x - $game_player.x).abs + (event.y - $game_player.y).abs == 1
if ![3, 4].include?(event.trigger) &&
(![0, 2].include?(event.priority_type) || event.trigger == 0) &&
![0, 1].include?(event.page.list.size)
if (event.y - $game_player.y).abs >
(event.x - $game_player.x).abs
if event.y - $game_player.y > 0
$game_player.turn_down
else
$game_player.turn_up
end
else
if event.x - $game_player.x > 0
$game_player.turn_right
else
$game_player.turn_left
end
end
event.start
event_activated = true
break
end
end
if !event_activated
for i in ["UP", "DOWN", "RIGHT", "LEFT"]
if event.check_for_comment(/MOUSE MOVE #{i}/i)
event_activated = true
case i
when "UP"
x, y = event.x, event.y - 1
when "DOWN"
x, y = event.x, event.y + 1
when "LEFT"
x, y = event.x - 1, event.y
when "RIGHT"
x, y = event.x + 1, event.y
end
break
end
end
end
if !event_activated
if $game_player.passable?(*Mouse.true_grid)
x, y = *Mouse.true_grid
event_activated = true
break
end
end
if !event_activated
q = do_closest_path_check(event)
if q != false
x, y = q[0], q[1]
event_activated = true
break
end
end
end
if !event_activated
if $game_player.map_passable?(*Mouse.true_grid)
x, y = *Mouse.true_grid
end
end
if !x.nil?
$game_temp.move_because_of_mouse = true
g = $game_player.find_mouse_path(x, y)
$game_temp.mouse_path = g
end
end
end
alias avara_up_ca_me update_call_menu
def update_call_menu
for event in $game_map.events_xy(*Mouse.true_grid)
return if event.check_for_comment(/MOUSE RIGHT-CLICK (.+)/i)
end
return if Avara::JetMouseSystem::BLOKADA_MENU & Mouse.click?(2)
avara_up_ca_me
end
end
Część II
Spoiler:
Kod:
# UWAGA: Podczas ustawiania typowego zdarzenia (Common event), użyj 0 dla żadnego!
module MouseClick
# To są ID typowych zdarzeń, które zostaną aktywowane, gdy gracz kliknie na
# głównego bohatera na mapie.
# Pierwszy jest dla kliknięcia lewym przyciskiem myszy (LPM), drugi zaś dla
# kliknięcia PPM.
COMMON_EVENT_ID = [5, 6]
# Są to numery ID kafelek, które po kliknięciu spowodują typowe zdarzenie.
# Dla oznaczenia ID kafelków można używać tablicy wpisów (tzn. [0, 1, 2]) lub
# pojedynczego wpisu (tj. 6). ID typowych zdarzeń muszą być wpisane dwa w tablicy.
# Pierwsza dla kliknięcia LPM, zaś druga dla kliknięcia PPM.
# Musi mieć to następujący format (TZ - typowe zdarzenie):
# [tile_id, tile_id, tile_id] => [TZ LPM, TZ PPM]
# lub:
# tile_id => [TZ LPM, TZ PPM]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Od Avary: ID kafelek liczymy od pierwszej kratki tilesetu B, z czego pierwsza
# kratka ma ID o wartości 0. Jeśli chcemy, by TZ o ID 2 uruchamiało się po
# kliknięciu LPM na tabliczkę z mieczem (z podstawowego tilesetu B), ale aby
# PPM nie uruchamiać żadnego zdarzenia, należy wpisać coś takiego:
# 1 => [2, 0]
# Jeden cały tileset ma 256 kafelków (z czego pierwszy kafelek ma id = 0, więc
# 1 musimy odjąć). ID pierwszych kafelków tilesetów są równe odpowiednio dla:
# tilesetu B = 0,
# tilesetu C = 256,
# tilesetu D = 512,
# tilesetu E = 768,
# zaś ostatni kafelek tilesetu E ma ID równy 1023.
# Jeśli nie chcesz przypisywać żadnych zdarzeń dla poszczególnych kafelek, to
# usuń dwie linijki z tablicami lub przed każdą z nich wstaw znak # lub
# w nawiasach kwadratowych (po prawej stronie strzałki) zamień wszystkie cyfry
# na zera.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TILE_COMMON_EVENTS = {
[2, 32, 56] => [5, 6], # Wszystkie linijki tego fragmentu konfiguracji (prócz
89 => [4, 1] # ostatniej) muszą mieć na końcu przecinek!
}
# Jest to ID przełącznika, który, jeśli jest włączony, wyłącza właściwości
# tego skryptu (TZ po kliknięciu na kafelek).
TURN_OFF_FEATURE_SWITCH = 1
end
#===============================================================================
# DALEJ NIE EDYTUJ, CHYBA ŻE WIESZ CO ROBISZ!
#===============================================================================
class Game_Map
attr_reader :map
end
class Scene_Map
alias jet1835_update update unless $@
def update(*args, &block)
add_x = $game_map.display_x / 256
add_y = $game_map.display_y / 256
if !$game_switches[MouseClick::TURN_OFF_FEATURE_SWITCH]
if !$game_map.interpreter.running?
mouse_x, mouse_y = *Mouse.true_grid
[1, 2].each {|index|
if Mouse.click?(index)
if [mouse_x, mouse_y] == [$game_player.x, $game_player.y]
$game_temp.common_event_id = MouseClick::COMMON_EVENT_ID[index - 1]
end
for i in [2, 1, 0]
tile_id = $game_map.map.data[mouse_x, mouse_y, i]
MouseClick::TILE_COMMON_EVENTS.each {|key, value|
if (key.is_a?(Array) ? key.include?(tile_id) : key == tile_id)
$game_temp.common_event_id = value[index - 1]
end
}
end
end
}
end
end
jet1835_update(*args, &block)
end
end
Screeny:
Spoiler:
Demo:
Dodatkowe informacje:
Jest możliwość, aby połączyć ten skrypt ze skryptem 8-kierunkowego poruszania się autorstwa Jet'a. Należy zmienić ustawienie w skrypcie (część I) w linijce 162. na "true". Demo zawiera jedną dodatkową grafikę przydatną do skryptu, do którego znajdziecie link poniżej.
Prosty mechanizm ruchu w 8 kierunkach by Jet
Mam pytanie co do tego skryptu. Dało by radę połączyć go ze skryptem Ruch w 8 kierunkach? Chodzi mi, że postać parzy się w miejsce kursora z wykorzystaniem dodatkowych animacji właśnie z 8 kierunków. Chciałbym, aby w mojej grze, którą zaczynam tworzyć, był ruch w 8 kierunkach, sterując WSAD, a animacja chodzenia zależała by od miejsca położenia myszki. LPM by się strzelało. R przeładowywało, a 1,2,3,4 wybierało broń. Może to i duże wymagania, ale pytanie, czy coś takiego jest w ogóle do zrobienia?
DonMateo07, czytaj dokładnie temat Masz wszystko napisane w "Dodatkowych informacjach" i w instrukcji skryptu, do którego jest link Aż mam ochotę dać Ci ostrzeżenie za głupotę (bez obrazy) -.-
Tylko chodzenia WSAD-em tam nie ma.
//Edit: Nie doczytałam. Wątpię byś znalazł taki skrypt, gdzie postać idzie za kursorem myszki. I nie wiem, czy będzie ktoś komu będzie się chciało to robić. I trzeba by to też było połączyć od razu z systemem walki w czasie rzeczywistym. Ja bym Ci radziła sobie odpuścić coś takiego.
Do zrobienia może i jest, ale raczej nikt się tego nie podejmie.
Skrypt jest naprawdę fajny,możliwe ze go użyje w moim projekcie.
Ten Skrypt jest w fazie ulepszeń czy może już skończony bo według mnie powinni
coś dodać. Na przykład to co UP napisał bardzo by się przydało.
To jest skrypt Jet'a. Nic nie wiem o tym, by chciał go ulepszyć. Ja go przetłumaczyłam i dodałam kilka opcji. Mogę spróbować dodać obracanie się postaci, ale nic nie obiecuję.
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach Nie możesz załączać plików na tym forum Możesz ściągać załączniki na tym forum