PDA

View Full Version : [Essentials script] Diagonal Movement


Pia Carrot
July 3rd, 2013, 03:41 PM
Original script is by Paradog, I've messed with this script a lot and fixed most of the Essentials-related bugs. Read the instructions carefully.

#==============================================================================
# Diagonal Movement for Essentials V1.0
#  Script by ParaDog and Modified by Pia Carrot
#------------------------------------------------------------------------------
# Additional 'diagonal' movement is now possible by pushing combinations of the
# vertical and horizontal controls (up & left, etc) simultaneously.
#
# Additional charsets for the 8-directional movement are to be stored within
# the "Graphics/Characters" folder, just like the regular charactersets.
#
# Name the new diagonal movement charactersets the same as the regular ones,
# but with a new '_quarter' extension. As such, you would name a copy of a character
#file named "Red" as: Red_quarter.
#
#
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================

class PokemonMenu_Scene
def pbShowCommands(commands)
ret=-1
cmdwindow=@sprites["cmdwindow"]
cmdwindow.viewport=@viewport
cmdwindow.index=$PokemonTemp.menuLastChoice
cmdwindow.resizeToFit(commands)
cmdwindow.commands=commands
cmdwindow.x=Graphics.width-cmdwindow.width
cmdwindow.y=0
cmdwindow.visible=true
loop do
$game_switches[60]=true
cmdwindow.update
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::B)
$game_switches[60]=false
ret=-1
break
end
if Input.trigger?(Input::C)
ret=cmdwindow.index
$PokemonTemp.menuLastChoice=ret
break
end
end
return ret
end
end

class PokemonMenu
def initialize(scene)
@scene=scene
end

def pbShowMenu
@scene.pbRefresh
@scene.pbShowMenu
end

def pbStartPokemonMenu
@scene.pbStartScene
endscene=true
pbSetViableDexes
commands=[]
cmdPokedex=-1
cmdPokemon=-1
cmdBag=-1
cmdTrainer=-1
cmdSave=-1
cmdOption=-1
cmdPokegear=-1
cmdDebug=-1
cmdQuit=-1
if !$Trainer
if $DEBUG
Kernel.pbMessage(_INTL("The player trainer was not defined, so the menu can't be displayed."))
Kernel.pbMessage(_INTL("Please see the documentation to learn how to set up the trainer player."))
end
return
end
commands[cmdPokedex=commands.length]=_INTL("Pokédex") if $Trainer.pokedex && $PokemonGlobal.pokedexViable.length>0
commands[cmdPokemon=commands.length]=_INTL("Pokémon") if $Trainer.party.length>0
commands[cmdBag=commands.length]=_INTL("Bag") if !pbInBugContest?
commands[cmdPokegear=commands.length]=_INTL("Pokégear") if $Trainer.pokegear
commands[cmdTrainer=commands.length]=$Trainer.name
if pbInSafari?
if SAFARISTEPS<=0
@scene.pbShowInfo(_INTL("Balls: {1}",pbSafariState.ballcount))
else
@scene.pbShowInfo(_INTL("Steps: {1}/{2}\nBalls: {3}",pbSafariState.steps,SAFARISTEPS,pbSafariState.ballcount))
end
commands[cmdQuit=commands.length]=_INTL("Quit")
elsif pbInBugContest?
if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("Caught: {1}\nLevel: {2}\nBalls: {3}",
PBSpecies.getName(pbBugContestState.lastPokemon.species),
pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount))
else
@scene.pbShowInfo(_INTL("Caught: None\nBalls: {1}",pbBugContestState.ballcount))
end
commands[cmdQuit=commands.length]=_INTL("Quit")
else
commands[cmdSave=commands.length]=_INTL("Save") if !$game_system || !$game_system.save_disabled
end
commands[cmdOption=commands.length]=_INTL("Options")
commands[cmdDebug=commands.length]=_INTL("Debug") if $DEBUG
commands[commands.length]=_INTL("Exit")
loop do
command=@scene.pbShowCommands(commands)
if cmdPokedex>=0 && command==cmdPokedex
if DEXDEPENDSONLOCATION
pbFadeOutIn(99999) {
scene=PokemonPokedexScene.new
screen=PokemonPokedex.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
else
if $PokemonGlobal.pokedexViable.length==1
$PokemonGlobal.pokedexDex=$PokemonGlobal.pokedexViable[0]
$PokemonGlobal.pokedexDex=-1 if $PokemonGlobal.pokedexDex==$PokemonGlobal.pokedexUnlocked.length-1
pbFadeOutIn(99999) {
scene=PokemonPokedexScene.new
screen=PokemonPokedex.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
else
pbLoadRpgxpScene(Scene_PokedexMenu.new)
end
end
elsif cmdPokegear>=0 && command==cmdPokegear
pbLoadRpgxpScene(Scene_Pokegear.new)
elsif cmdPokemon>=0 && command==cmdPokemon
sscene=PokemonScreen_Scene.new
sscreen=PokemonScreen.new(sscene,$Trainer.party)
hiddenmove=nil
pbFadeOutIn(99999) {
hiddenmove=sscreen.pbPokemonScreen
if hiddenmove
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if hiddenmove
Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
return
end
elsif cmdBag>=0 && command==cmdBag
item=0
scene=PokemonBag_Scene.new
screen=PokemonBagScreen.new(scene,$PokemonBag)
pbFadeOutIn(99999) {
item=screen.pbStartScreen
if item>0
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if item>0
Kernel.pbUseKeyItemInField(item)
return
end
elsif cmdTrainer>=0 && command==cmdTrainer
PBDebug.logonerr {
scene=PokemonTrainerCardScene.new
screen=PokemonTrainerCard.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
@scene.pbRefresh
}
}
elsif cmdQuit>=0 && command==cmdQuit
@scene.pbHideMenu
if pbInSafari?
if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
@scene.pbEndScene
pbSafariState.decision=1
pbSafariState.pbGoToStart
return
else
pbShowMenu
end
else
if Kernel.pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
@scene.pbEndScene
pbBugContestState.pbStartJudging
return
else
pbShowMenu
end
end
elsif cmdSave>=0 && command==cmdSave
@scene.pbHideMenu
scene=PokemonSaveScene.new
screen=PokemonSave.new(scene)
if screen.pbSaveScreen
$game_switches[60]=false
@scene.pbEndScene
endscene=false
break
else
pbShowMenu
end
elsif cmdDebug>=0 && command==cmdDebug
pbFadeOutIn(99999) {
pbDebugMenu
@scene.pbRefresh
}
elsif cmdOption>=0 && command==cmdOption
scene=PokemonOptionScene.new
screen=PokemonOption.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
pbUpdateSceneMap
@scene.pbRefresh
}
else
break
end
end
@scene.pbEndScene if endscene
end
end

class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Frame update
#--------------------------------------------------------------------------
alias update_para_quarter update
def update
update_para_quarter
unless moving? or $game_system.map_interpreter.running? or $game_switches[61] or
pbGetTerrainTag($game_player)==PBTerrain::Ice or @move_route_forcing or $game_temp.message_window_showing or
$game_switches[60]
# If the direction button is pushed, move the player in that direction
case Input.dir8
when 1 # Move Lower Left
move_lower_left
when 3 # Move Lower Right
move_lower_right
when 7 # Move Upper Left
move_upper_left
when 9 # Move Upper Right
move_upper_right
end
end
end
end

#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias update_para_quarter update
def update
update_para_quarter
if @tile_id == 0
if (@character.direction - 2) % 2 == 1
# Checking the presence of the diagonal charset
if quarter_graphic_exist?(@character)
# Set the diagonal charset
if character.dash_on and dash_quarter_graphic_exist?(@character)
@character_name = @character.character_name + "_dash_quarter"
else
@character_name = @character.character_name + "_quarter"
end
self.bitmap = RPG::Cache.character(@character_name,
@character.character_hue)
# Acquire direction
case @character.direction
when 1
n = 0
when 3
n = 2
when 7
n = 1
when 9
n = 3
end
else
@character.direction = @character.sub_direction
# When the diagonal charset does not exist, direction
n = (@character.direction - 2) / 2
end
# Set original transfer rectangle
sx = @character.pattern * @cw
sy = n * @ch
self.src_rect.set(sx, sy, @cw, @ch)
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
# Set original transfer rectangle
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end
end
#--------------------------------------------------------------------------
# * Diagonal Charset?
#--------------------------------------------------------------------------
def quarter_graphic_exist?(character)
# Reading check
begin
RPG::Cache.character(character.character_name.to_s + "_quarter", character.character_hue)
rescue
return false
end
return true
end
#--------------------------------------------------------------------------
# * Dashing Diagonal Charset?
#--------------------------------------------------------------------------
def dash_quarter_graphic_exist?(character)
# Reading check
begin
RPG::Cache.character(character.character_name.to_s + "_dash_quarter", character.character_hue)
rescue
return false
end
return true
end
end

#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================

class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :direction # direction
attr_accessor :sub_direction # sub_direction
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left
# If no direction fix
unless @direction_fix
@sub_direction = @direction
@direction = 1
# Face left if facing right, and face down if facing up
@sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 8 ? 2 : @sub_direction)
end
return if pbLedge(-1,1)
return if pbEndSurf(-1,1)
return if moving?
# When a down to left or a left to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# Update coordinates
@x -= 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right
# If no direction fix
unless @direction_fix
@sub_direction = @direction
@direction = 3
# Face right if facing left, and face down if facing up
@sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 8 ? 2 : @sub_direction)
end
return if pbLedge(1,1)
return if pbEndSurf(1,1)
return if moving?
# When a down to right or a right to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# Update coordinates
@x += 1
@y += 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left
# If no direction fix
unless @direction_fix
@sub_direction = @direction
@direction = 7
# Face left if facing right, and face up if facing down
@sub_direction = (@sub_direction == 6 ? 4 : @sub_direction == 2 ? 8 : @sub_direction)
end
return if pbLedge(-1,-1)
return if pbEndSurf(-1,-1)
return if moving?
# When an up to left or a left to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# Update coordinates
@x -= 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right
# If no direction fix
unless @direction_fix
@sub_direction = @direction
@direction = 9
# Face right if facing left, and face up if facing down
@sub_direction = (@sub_direction == 4 ? 6 : @sub_direction == 2 ? 8 : @sub_direction)
end
return if pbLedge(1,-1)
return if pbEndSurf(1,-1)
return if moving?
# When an up to right or a right to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# Update coordinates
@x += 1
@y -= 1
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Dash
#--------------------------------------------------------------------------
def dash_on
if @dash_on != nil
return @dash_on
else
return false
end
end
end

Instructions
README:
First off, if you walk diagonally on ice tiles you will break the game with a hangover error.
So, I have disabled diagonal walking on ice tiles. I do not know how I can remedy this.
Also, two switches (60 and 61) if left on will cause diagonal walking to cease. Use this
to your advantage. If you want to change the switches find $game_switches[61] and
$game_switches[60] to whatever you want (the number only).

Credits
Credit Paradog and Pia Carrot for the script.

Screenshots
Hard to tell but ehhh
http://yandereheaven.com/images/gamesfolder/mint.png

Compatability and Bugs
I've fixed them all as far as I'm concerned. But if one pops up, let me know.

Yay for add-ons!

Pia Carrot
January 17th, 2014, 09:25 AM
If anyone has used this and has encountered a bug please let me know. I have yet to try this on Essentials v13 with its new Ice terrain fixes.

Soul.//Silver
January 19th, 2014, 05:19 PM
Installed the script, no problems so far. I've actually wanted to have something like the 8-directional script in Essentials since I started my little project, so thanks :D

Could you perhaps upload an example for character sheet layouts?

GReusch
January 20th, 2014, 10:41 AM
One thing to note about this script is that it breaks the current animation for climbing sideways stairs (since it uses a "Move: Upper Right/Left" command in the event screen). An easy fix, but important to note that you will be changing all of your stair animations if you used the default included with Essentials.

EDIT: Of course, you could also turn on the two switches that disable diagonal movement before the stair animation. You'll still be copy/pasting to all of your staircases though.

Pia Carrot
January 20th, 2014, 10:59 AM
Installed the script, no problems so far. I've actually wanted to have something like the 8-directional script in Essentials since I started my little project, so thanks :D

Could you perhaps upload an example for character sheet layouts?

http://fc09.deviantart.net/fs71/f/2012/019/4/1/yellow_isometric_sprites_by_pokemon_tiler-d4my3b1.png
As for FRLG styled ones I know I have seen isometric sprites of Red.

One thing to note about this script is that it breaks the current animation for climbing sideways stairs (since it uses a "Move: Upper Right/Left" command in the event screen). An easy fix, but important to note that you will be changing all of your stair animations if you used the default included with Essentials.

EDIT: Of course, you could also turn on the two switches that disable diagonal movement before the stair animation. You'll still be copy/pasting to all of your staircases though.

This is true, I'd most likely just disable the diagonal on stairs anyway though. Eventually I'd love to have this script plug-and-play, I will work on it sometime.

Update: Script is now plug-and-play, no longer do you need to edit pre-existing scripts!