PDA

View Full Version : how do you center a party member in battle with RPGMXP?


jiros
18-04-2006, 09:27
hi, there , fellow RPG fanatics, i have a question, not the first and not the last... with some ruby script you can adjust settings that weren't possible without it. now i'm wondering...can you center a battler in battle? even when he's the only one in the party?

Dusk
18-06-2006, 19:51
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# œ ƒoƒgƒ‹‰– X •W‚Ž“
#--------------------------------------------------------------------------
def screen_x
# ƒp[ƒeƒB“‚•‚я‡‚‚ X •W‚ŒvŽZ‚‚•‚
if self.index != nil
return self.index * 160 + (4 - $game_party.actors.size) * 80 + 80
else
return 0
end
end
end

#================================================= =============================
# Spriteset_Battle
#------------------------------------------------------------------------------
# @ƒoƒgƒ‹‰–‚ƒXƒvƒ‰ƒCƒg‚‚‚‚‚ƒNƒ‰ƒX‚‚B‚‚ ƒNƒ‰ƒX‚ Scene_Battle ƒNƒ‰
# ƒX‚“•”‚Žg—p‚‚‚‚B
#================================================= =============================

class Spriteset_Battle
#--------------------------------------------------------------------------
# œ ƒIƒuƒWƒFƒNƒg‰Š‰
#--------------------------------------------------------------------------
def initialize
# ƒrƒ…[ƒ|[ƒg‚쐬
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport4 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 101
@viewport3.z = 200
@viewport4.z = 5000
# ƒoƒgƒ‹ƒoƒbƒNƒXƒvƒ‰ƒCƒg‚쐬
@battleback_sprite = Sprite.new(@viewport1)
# ƒGƒlƒ~[ƒXƒvƒ‰ƒCƒg‚쐬
@enemy_sprites = []
for enemy in $game_troop.enemies.reverse
@enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
end
# ƒAƒNƒ^[ƒXƒvƒ‰ƒCƒg‚쐬
@actor_sprites = []
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
# “VŒ‚쐬
@weather = RPG::Weather.new(@viewport1)
# ƒsƒNƒ`ƒƒƒXƒvƒ‰ƒCƒg‚쐬
@picture_sprites = []
for i in 51..100
@picture_sprites.push(Sprite_Picture.new(@viewport 3,
$game_screen.pictures[i]))
end
# ƒ^ƒCƒ}[ƒXƒvƒ‰ƒCƒg‚쐬
@timer_sprite = Sprite_Timer.new
# ƒtƒŒ[ƒ€XV
update
end
#--------------------------------------------------------------------------
# œ ƒtƒŒ[ƒ€XV
#--------------------------------------------------------------------------
def update
# ƒAƒNƒ^[ƒXƒvƒ‰ƒCƒg‚“—e‚XV (ƒAƒNƒ^[‚“‚‘‚‚‘‰ž)
@actor_sprites[0].battler = $game_party.actors[0]
@actor_sprites[1].battler = $game_party.actors[1]
@actor_sprites[2].battler = $game_party.actors[2]
@actor_sprites[3].battler = $game_party.actors[3]
# ƒoƒgƒ‹ƒoƒbƒN‚ƒtƒ@ƒCƒ‹–‚Œ‚‚‚‚ˆ‚‡
if @battleback_name != $game_temp.battleback_name
@battleback_name = $game_temp.battleback_name
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
@battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
@battleback_sprite.src_rect.set(0, 0, 640, 480)
if @battleback_sprite.bitmap.height == 320
@battleback_sprite.zoom_x = 2.0
@battleback_sprite.zoom_y = 2.0
@battleback_sprite.x = 320
@battleback_sprite.y = 480
@battleback_sprite.ox = @battleback_sprite.bitmap.width / 2
@battleback_sprite.oy = @battleback_sprite.bitmap.height
else
@battleback_sprite.x = 0
@battleback_sprite.y = 0
@battleback_sprite.ox = 0
@battleback_sprite.oy = 0
@battleback_sprite.zoom_x = 1
@battleback_sprite.zoom_y = 1
end
end
# ƒoƒgƒ‰[ƒXƒvƒ‰ƒCƒg‚XV
for sprite in @enemy_sprites + @actor_sprites
sprite.update
end
# “VŒƒOƒ‰ƒtƒBƒbƒN‚XV
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.update
# ƒsƒNƒ`ƒƒƒXƒvƒ‰ƒCƒg‚XV
for sprite in @picture_sprites
sprite.update
end
# ƒ^ƒCƒ}[ƒXƒvƒ‰ƒCƒg‚XV
@timer_sprite.update
# ‰–‚̐F’‚ƒVƒFƒCƒNˆ’u‚’
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# ‰–‚ƒtƒ‰ƒbƒVƒ…F‚’
@viewport4.color = $game_screen.flash_color
# ƒrƒ…[ƒ|[ƒg‚XV
@viewport1.update
@viewport2.update
@viewport4.update
end
end

#================================================= =============================
# Window_BattleStatus
#------------------------------------------------------------------------------
# @ƒoƒgƒ‹‰–‚ƒp[ƒeƒBƒƒ“ƒo[‚ƒXƒe[ƒ^ƒX‚•\Ž‚‚ƒEƒBƒ“ƒhƒE‚‚B
#================================================= =============================

class Window_BattleStatus < Window_Base
#--------------------------------------------------------------------------
# œ ƒIƒuƒWƒFƒNƒg‰Š‰
#--------------------------------------------------------------------------
def initialize
x = (4 - $game_party.actors.size) * 80
width = $game_party.actors.size * 160
super(x, 320, width, 160)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@level_up_flags = [false, false, false, false]
refresh
end
#--------------------------------------------------------------------------
# œ ƒtƒŒ[ƒ€XV
#--------------------------------------------------------------------------
def update
super
if self.x != (4 - $game_party.actors.size) * 80
self.x = (4 - $game_party.actors.size) * 80
self.width = $game_party.actors.size * 160
self.contents = Bitmap.new(self.width - 32, self.height - 32)
refresh
end
# ƒƒCƒ“ƒtƒF[ƒY‚‚‚‚•s“–“x‚‚‚‰‚‚
if $game_temp.battle_main_phase
self.contents_opacity -= 4 if self.contents_opacity > 191
else
self.contents_opacity += 4 if self.contents_opacity < 255
end
end
end

#================================================= =============================
# Scene_Battle (•Š„’‹` 3)
#------------------------------------------------------------------------------
# @ƒoƒgƒ‹‰–‚̏ˆ—‚s‚ƒNƒ‰ƒX‚‚B
#================================================= =============================

class Scene_Battle
#--------------------------------------------------------------------------
# œ ƒAƒNƒ^[ƒRƒ}ƒ“ƒhƒEƒBƒ“ƒhƒE‚ƒZƒbƒgƒAƒbƒv
#--------------------------------------------------------------------------
def phase3_setup_command_window
# ƒp[ƒeƒBƒRƒ}ƒ“ƒhƒEƒBƒ“ƒhƒE‚–Œ‰
@party_command_window.active = false
@party_command_window.visible = false
# ƒAƒNƒ^[ƒRƒ}ƒ“ƒhƒEƒBƒ“ƒhƒE‚—LŒ‰
@actor_command_window.active = true
@actor_command_window.visible = true
# ƒAƒNƒ^[ƒRƒ}ƒ“ƒhƒEƒBƒ“ƒhƒE‚ˆ’u‚’
@actor_command_window.x = @actor_index * 160 +
(4 - $game_party.actors.size) * 80
# ƒCƒ“ƒfƒbƒNƒX‚ 0 ‚ɐ’
@actor_command_window.index = 0
end
end

#================================================= =============================
# Spriteƒ‚ƒWƒ…[ƒ‹
#------------------------------------------------------------------------------
# @ƒAƒjƒ[ƒVƒ‡ƒ“‚Š—‚s‚ƒ‚ƒWƒ…[ƒ‹‚‚B
#================================================= =============================

module RPG
class Sprite < ::Sprite
def animation_set_sprites(sprites, cell_data, position)
for i in 0..15
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite == nil or pattern == nil or pattern == -1
sprite.visible = false if sprite != nil
next
end
sprite.visible = true
sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
if position == 3
if self.viewport != nil
sprite.x = self.viewport.rect.width / 2
if $game_temp.in_battle and self.battler.is_a?(Game_Actor)
sprite.y = self.viewport.rect.height - 160
else
sprite.y = self.viewport.rect.height - 320
end
else
sprite.x = 320
sprite.y = 240
end
else
sprite.x = self.x + self.viewport.rect.x - self.ox + self.src_rect.width / 2
sprite.y = self.y + self.viewport.rect.y - self.oy * self.zoom_y + self.src_rect.height * self.zoom_y / 2
sprite.y -= self.src_rect.height / 4 if position == 0
sprite.y += self.src_rect.height / 4 if position == 2
end
sprite.x += cell_data[i, 1]
sprite.y += cell_data[i, 2]
sprite.z = 2000
sprite.ox = 96
sprite.oy = 96
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
sprite.blend_type = cell_data[i, 7]
end
end
end
end

alexanderpas
19-06-2006, 11:20
and now for those that actually have bought the official verion! (scrollbar at bottom of post, so don't type over, copy-paste)
---
Update Respective Section(s) in: Game_Actor#======================================= =======================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#================================================= =============================

class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Get Battle Screen X-Coordinate
#--------------------------------------------------------------------------
def screen_x
# Return after calculating x-coordinate by order of members in party
if self.index != nil
return self.index * 160 + (4 - $game_party.actors.size) * 80 + 80
else
return 0
end
end
end
---
Update Respective Section(s) in: Game_Actor#======================================= =======================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within
# the Scene_Battle class.
#================================================= =============================

class Spriteset_Battle
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport4 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 101
@viewport3.z = 200
@viewport4.z = 5000
# Make battleback sprite
@battleback_sprite = Sprite.new(@viewport1)
# Make enemy sprites
@enemy_sprites = []
for enemy in $game_troop.enemies.reverse
@enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
end
# Make actor sprites
@actor_sprites = []
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
@actor_sprites.push(Sprite_Battler.new(@viewport2) )
# Make weather
@weather = RPG::Weather.new(@viewport1)
# Make picture sprites
@picture_sprites = []
for i in 51..100
@picture_sprites.push(Sprite_Picture.new(@viewport 3,
$game_screen.pictures[i]))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update actor sprite contents (corresponds with actor switching)
@actor_sprites[0].battler = $game_party.actors[0]
@actor_sprites[1].battler = $game_party.actors[1]
@actor_sprites[2].battler = $game_party.actors[2]
@actor_sprites[3].battler = $game_party.actors[3]
# If battleback file name is different from current one
if @battleback_name != $game_temp.battleback_name
@battleback_name = $game_temp.battleback_name
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
@battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
@battleback_sprite.src_rect.set(0, 0, 640, 480)
if @battleback_sprite.bitmap.height == 320
@battleback_sprite.zoom_x = 2.0
@battleback_sprite.zoom_y = 2.0
@battleback_sprite.x = 320
@battleback_sprite.y = 480
@battleback_sprite.ox = @battleback_sprite.bitmap.width / 2
@battleback_sprite.oy = @battleback_sprite.bitmap.height
else
@battleback_sprite.x = 0
@battleback_sprite.y = 0
@battleback_sprite.ox = 0
@battleback_sprite.oy = 0
@battleback_sprite.zoom_x = 1
@battleback_sprite.zoom_y = 1
end
end
# Update battler sprites
for sprite in @enemy_sprites + @actor_sprites
sprite.update
end
# Update weather graphic
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.update
# Update picture sprites
for sprite in @picture_sprites
sprite.update
end
# Update timer sprite
@timer_sprite.update
# Set screen color tone and shake position
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# Set screen flash color
@viewport4.color = $game_screen.flash_color
# Update viewports
@viewport1.update
@viewport2.update
@viewport4.update
end
end
---
Update Respective Section(s) in: Window_BattleStatus#============================== ================================================
# ** Window_BattleStatus
#------------------------------------------------------------------------------
# This window displays the status of all party members on the battle screen.
#================================================= =============================

class Window_BattleStatus < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
x = (4 - $game_party.actors.size) * 80
width = $game_party.actors.size * 160
super(x, 320, width, 160)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@level_up_flags = [false, false, false, false]
refresh
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if self.x != (4 - $game_party.actors.size) * 80
self.x = (4 - $game_party.actors.size) * 80
self.width = $game_party.actors.size * 160
self.contents = Bitmap.new(self.width - 32, self.height - 32)
refresh
end
# Slightly lower opacity level during main phase
if $game_temp.battle_main_phase
self.contents_opacity -= 4 if self.contents_opacity > 191
else
self.contents_opacity += 4 if self.contents_opacity < 255
end
end
end
---
Update Respective Section(s) in: Scene_Battle 3#================================================ ==============================
# ** Scene_Battle (part 3)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#================================================= =============================

class Scene_Battle
#--------------------------------------------------------------------------
# * Actor Command Window Setup
#--------------------------------------------------------------------------
def phase3_setup_command_window
# Disable party command window
@party_command_window.active = false
@party_command_window.visible = false
# Enable actor command window
@actor_command_window.active = true
@actor_command_window.visible = true
# Set actor command window position
@actor_command_window.x = @actor_index * 160 + (4 - $game_party.actors.size) * 80
# Set index to 0
@actor_command_window.index = 0
end
end
---
Create new, right before Main.
module RPG
class Sprite < ::Sprite
def animation_set_sprites(sprites, cell_data, position)
for i in 0..15
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite == nil or pattern == nil or pattern == -1
sprite.visible = false if sprite != nil
next
end
sprite.visible = true
sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)
if position == 3
if self.viewport != nil
sprite.x = self.viewport.rect.width / 2
if $game_temp.in_battle and self.battler.is_a?(Game_Actor)
sprite.y = self.viewport.rect.height - 160
else
sprite.y = self.viewport.rect.height - 320
end
else
sprite.x = 320
sprite.y = 240
end
else
sprite.x = self.x + self.viewport.rect.x - self.ox + self.src_rect.width / 2
sprite.y = self.y + self.viewport.rect.y - self.oy * self.zoom_y + self.src_rect.height * self.zoom_y / 2
sprite.y -= self.src_rect.height / 4 if position == 0
sprite.y += self.src_rect.height / 4 if position == 2
end
sprite.x += cell_data[i, 1]
sprite.y += cell_data[i, 2]
sprite.z = 2000
sprite.ox = 96
sprite.oy = 96
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
sprite.blend_type = cell_data[i, 7]
end
end
end
end

Dusk
19-06-2006, 13:34
There is a japense version aswell as an engilsh version, the code should work in the jap or english version they both use the same RGSS engine only one uses an english .DLL

The only thing you have done really is changed the comments and seperate each part whereas putting it all in one script does the same job and is alot simpler for people who are new at RGSS.

Edit: Tested in Engilsh version, works fine.