Pomogła: 232 razy Dołączyła: 18 Wrz 2007 Posty: 2424
Wysłany: Nie 03 Sty, 2010 14:20
Silnik 2 graczy
~ Silnik 2 graczy ~
Krótki opis
Skrypt tworzy drugiego bohatera, którego można kontrolować i, który może wchodzić w interakcje z otoczeniem tak samo jak główna postać.
Dodatkowe opcje:
- Można przypisać klawisze do drugiej postaci.
- Druga postać porusza się w 8 kierunkach.
Autor skryptu
Woratana
Tłumaczenie
Ayene [yurika@o2.pl]
Kompatybilność
Tylko VX
Skrypt
Spoiler:
Kod:
#================================================
# Silnik 2 graczy [2 Player Engine]
#------------------------------------------------
# Autor: Woratana [woratana@hotmail.com]
# Tłumaczenie: Ayene [yurika@o2.pl]
# CREDIT: Wersja XP by Hima
# www.ultimateam.pl
#
# + [OPIS] +
# Skrypt tworzy drugiego bohatera, którego można kontrolować i, który może
# wchodzić w interakcje z otoczeniem tak samo jak główna postać.
# - Można przypisać klawisze do drugiej postaci.
# - Druga postać porusza się w 8 kierunkach.
#
# + [JAK UŻYĆ] +
# By stworzyć drugą postać, wywołaj skrypt:
# $game_player2 = Game_Player2.new
# $game_player2.create(x, y, actor id, follow?)
#
# x i y = współrzędne miejsca, w którym ma się pojawić bohater
# actor id - id bohatera z bazie danych, który ma być drugą postacią
# follow? = true (ekran podąża za nową postacią), false (nie podąża)
# *ZALECA SIĘ NIEUŻYWANIE TEJ OPCJI*
#
# By usunąć postać 2, wywołaj skrypt:
# $game_player2.delete
#==============================================================================
class Game_Player2 < Game_Character
#--------------------------------------------------------------------------
# KONFIGURACJA SKRYPTU
# * Stałe: Klawisze dla Game_Player 2
#--------------------------------------------------------------------------
DOWN = Input::Y # Dół - S na klawiaturze
LEFT = Input::X # Lewo - A na klawiaturze
RIGHT = Input::Z # Prawo - D na klawiaturze
UP = Input::R # Góra - W na klawiaturze
ENTER = Input::L # Enter - Q na klawiaturze
RUN = Input::A # Bieg - Shift na klawiaturze
#--------------------------------------------------------------------------
# KONIEC KONFIGURACJI SKRYPTU
#--------------------------------------------------------------------------
def stopping?
return false if @vehicle_getting_on
return false if @vehicle_getting_off
return super
end
def reserve_transfer(map_id, x, y, direction)
@transferring = true
@new_map_id = map_id
@new_x = x
@new_y = y
@new_direction = direction
end
def transfer?
return @transferring
end
def perform_transfer
return unless @transferring
@transferring = false
set_direction(@new_direction)
if $game_map.map_id != @new_map_id
$game_map.setup(@new_map_id)
end
moveto(@new_x, @new_y)
end
def map_passable?(x, y)
case @vehicle_type
when 0 # Boat
return $game_map.boat_passable?(x, y)
when 1 # Ship
return $game_map.ship_passable?(x, y)
when 2 # Airship
return true
else # Walking
return $game_map.passable?(x, y)
end
end
def can_walk?(x, y)
last_vehicle_type = @vehicle_type
@vehicle_type = -1
result = passable?(x, y)
@vehicle_type = last_vehicle_type
return result
end
def airship_land_ok?(x, y)
unless $game_map.airship_land_ok?(x, y)
return false
end
unless $game_map.events_xy(x, y).empty?
return false
end
return true
end
def in_vehicle?
return @vehicle_type >= 0
end
def in_airship?
return @vehicle_type == 2
end
def dash?
return false if @move_route_forcing
return false if $game_map.disable_dash?
return false if in_vehicle?
return Input.press?(RUN)
end
def debug_through?
return false unless $TEST
return Input.press?(Input::CTRL)
end
def center(x, y)
display_x = x * 256 - CENTER_X
unless $game_map.loop_horizontal?
max_x = ($game_map.width - 17) * 256
display_x = [0, [display_x, max_x].min].max
end
display_y = y * 256 - CENTER_Y
unless $game_map.loop_vertical?
max_y = ($game_map.height - 13) * 256
display_y = [0, [display_y, max_y].min].max
end
$game_map.set_display_pos(display_x, display_y)
end
def moveto(x, y)
super
make_encounter_count
if in_vehicle?
vehicle = $game_map.vehicles[@vehicle_type]
vehicle.refresh
end
end
def increase_steps
super
return if @move_route_forcing
return if in_vehicle?
$game_party.increase_steps
$game_party.on_player_walk
end
def encounter_count
return @encounter_count
end
def make_encounter_count
if $game_map.map_id != 0
n = $game_map.encounter_step
@encounter_count = rand(n) + rand(n) + 1
end
end
def in_area?(area)
return false if area == nil
return false if $game_map.map_id != area.map_id
return false if @x < area.rect.x
return false if @y < area.rect.y
return false if @x >= area.rect.x + area.rect.width
return false if @y >= area.rect.y + area.rect.height
return true
end
def make_encounter_troop_id
encounter_list = $game_map.encounter_list.clone
for area in $data_areas.values
encounter_list += area.encounter_list if in_area?(area)
end
if encounter_list.empty?
make_encounter_count
return 0
end
return encounter_list[rand(encounter_list.size)]
end
def refresh
if @actor_id != nil and $game_actors[@actor_id] != nil
actor = $game_actors[@actor_id] # Get front actor
@character_name = actor.character_name
@character_index = actor.character_index
else
@character_name = ""
end
end
def check_event_trigger_here(triggers)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(@x, @y)
if triggers.include?(event.trigger) and event.priority_type != 1
event.start
result = true if event.starting
end
end
return result
end
def check_event_trigger_there(triggers)
return false if $game_map.interpreter.running?
result = false
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
if result == false and $game_map.counter?(front_x, front_y)
front_x = $game_map.x_with_direction(front_x, @direction)
front_y = $game_map.y_with_direction(front_y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
end
return result
end
def check_event_trigger_touch(x, y)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(x, y)
if [1,2].include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
return result
end
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
if Input.press?(DOWN)
move_down
end
if Input.press?(LEFT)
move_left
end
if Input.press?(RIGHT)
move_right
end
if Input.press?(UP)
move_up
end
end
def movable?
return false if moving?
return false if @move_route_forcing
return false if @vehicle_getting_on
return false if @vehicle_getting_off
return false if $game_message.visible
return false if in_airship? and not $game_map.airship.movable?
return true
end
def update
last_real_x = @real_x
last_real_y = @real_y
last_moving = moving?
move_by_input
super
update_scroll(last_real_x, last_real_y) if @need_center
update_vehicle
update_nonmoving(last_moving)
end
def update_scroll(last_real_x, last_real_y)
ax1 = $game_map.adjust_x(last_real_x)
ay1 = $game_map.adjust_y(last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
if ay2 > ay1 and ay2 > CENTER_Y
$game_map.scroll_down(ay2 - ay1)
end
if ax2 < ax1 and ax2 < CENTER_X
$game_map.scroll_left(ax1 - ax2)
end
if ax2 > ax1 and ax2 > CENTER_X
$game_map.scroll_right(ax2 - ax1)
end
if ay2 < ay1 and ay2 < CENTER_Y
$game_map.scroll_up(ay1 - ay2)
end
end
def update_vehicle
return unless in_vehicle?
vehicle = $game_map.vehicles[@vehicle_type]
if @vehicle_getting_on
if not moving?
@direction = vehicle.direction
@move_speed = vehicle.speed
@vehicle_getting_on = false
@transparent = true
end
elsif @vehicle_getting_off
if not moving? and vehicle.altitude == 0
@vehicle_getting_off = false
@vehicle_type = -1
@transparent = false
end
else
vehicle.sync_with_player
end
end
def update_nonmoving(last_moving)
return if $game_map.interpreter.running?
return if moving?
return if check_touch_event if last_moving
if not $game_message.visible and Input.trigger?(ENTER)
return if get_on_off_vehicle
return if check_action_event
end
update_encounter if last_moving
end
def update_encounter
return if $TEST and Input.press?(Input::CTRL)
return if in_vehicle?
if $game_map.bush?(@x, @y)
@encounter_count -= 2
else
@encounter_count -= 1
end
end
def check_touch_event
return false if in_airship?
return check_event_trigger_here([1,2])
end
def check_action_event
return false if in_airship?
return true if check_event_trigger_here([0])
return check_event_trigger_there([0,1,2])
end
def get_on_off_vehicle
return false unless movable?
if in_vehicle?
return get_off_vehicle
else
return get_on_vehicle
end
end
def get_off_vehicle
if in_airship?
return unless airship_land_ok?(@x, @y)
else
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
return unless can_walk?(front_x, front_y)
end
$game_map.vehicles[@vehicle_type].get_off
if in_airship?
@direction = 2
else
force_move_forward
@transparent = false
end
@vehicle_getting_off = true
@move_speed = 4
@through = false
@walking_bgm.play
make_encounter_count
end
def force_move_forward
@through = true
move_forward
@through = false
end
end
class Scene_Title < Scene_Base
alias wor_twopla_scetit_cregam create_game_objects
def create_game_objects
wor_twopla_scetit_cregam
$game_player2 = nil
end
end
class Scene_Map < Scene_Base
alias wor_twopla_scemap_upd update
def update
wor_twopla_scemap_upd
$game_player2.update if $game_player2 != nil
end
end
class Spriteset_Map
alias wor_twopla_sprmap_crecha create_characters
alias wor_twopla_sprmap_updcha update_characters
def create_characters
wor_twopla_sprmap_crecha
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
@chara_two_pushed = false
end
def update_characters
if !(@chara_two_pushed) and $game_player2 != nil
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player2))
@chara_two_pushed = true
elsif @chara_two_pushed and $game_player2 == nil
for i in 0..@character_sprites.size
if @character_sprites[i].character.is_a?(Game_Player2)
@character_sprites[i].character.character_name = ""
@character_sprites[i].update
@character_sprites.delete_at(i)
break
end
end
@chara_two_pushed = false
end
wor_twopla_sprmap_updcha
end
end
class Game_Map
alias wor_twopla_gammap_passable passable?
def passable?(x, y, flag = 0x01)
if $game_player2 != nil and flag
return false if $game_player2.x == x and $game_player2.y == y
end
wor_twopla_gammap_passable(x, y, flag)
end
end
Demo
Screenshot
niepotrzebny
Instrukcja
1. Wklej skrypt nad "Main" w Edytorze Skryptu.
2. By stworzyć drugą postać, wywołaj skrypt:
Kod:
$game_player2 = Game_Player2.new
$game_player2.create(x, y, actor id, follow?)
Gdzie:
x i y = współrzędne miejsca, w którym ma się pojawić bohater
actor id - id bohatera z bazie danych, który ma być drugą postacią
follow? = true (ekran podąża za nową postacią), false (nie podąża)
*ZALECA SIĘ NIEUŻYWANIE TEJ OPCJI*
By usunąć postać 2, wywołaj skrypt:
Kod:
$game_player2.delete
3. Reszta instrukcji znajduje się w treści skryptu.
Pomogła: 232 razy Dołączyła: 18 Wrz 2007 Posty: 2424
Wysłany: Czw 21 Sty, 2010 19:31
Tego typu informacja nic nie mówi. Podaj pełną treść błędu albo wklej screenshota. Napisz ponadto, kiedy się błąd pojawia: przy starcie gry, czy przy konkretnej czynności?
Pomogła: 232 razy Dołączyła: 18 Wrz 2007 Posty: 2424
Wysłany: Czw 11 Lut, 2010 15:15
Przeczytaj uważnie instrukcję
Gdzie:
x i y = współrzędne miejsca, w którym ma się pojawić bohater
actor id - id bohatera z bazie danych, który ma być drugą postacią
follow? = true (ekran podąża za nową postacią), false (nie podąża)
*ZALECA SIĘ NIEUŻYWANIE TEJ OPCJI*
A w zdarzeniach nie ma potrzeby nic zmieniać. Wszystko zależy od tego, co ma Tobie aktywować drugiego gracza. Ale to już jest kwestia samej wiedzy na temat zdarzeń.
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