? SAFE JUMP: Don't Jump if its destination is OUT OF THE SCREEN (or) NOT PASSABLE. (Old jump will not check before jump)
? IMPROVED RANDOM MOVE Find the movable direction before move. (Old random move will just skip to move in that frame, if its destination is not passable.)
? IMPROVED COLLIDE_WITH_CHARACTERS CHECK 'Same as Characters' events are able to walk on other 'Below Characters' events.
? Note: If you don't want one of this improved command, just delete its part. (I put all of their command name above their script part) ################################
#=============================================================== # ? [VX] ? Improved & Special Move Commands ? ? #-------------------------------------------------------------- # ? by Woratana [woratana@hotmail.com] # ? Released on: 20/03/2008 # ? Version: 1.0 #-------------------------------------------------------------- =begin ?=====?=====?=====?=====?=====?=====?=====?=====?=====? + COMMANDS LIST + ?=====?=====?=====?=====?=====?=====?=====?=====?=====? ################################ ? IMPROVED MOVE COMMANDS ?
? SAFE JUMP: Don't Jump if its destination is OUT OF THE SCREEN (or) NOT PASSABLE. (Old jump will not check before jump)
? IMPROVED RANDOM MOVE Find the movable direction before move. (Old random move will just skip to move in that frame, if its destination is not passable.)
? IMPROVED COLLIDE_WITH_CHARACTERS CHECK 'Same as Characters' events are able to walk on other 'Below Characters' events.
? Note: If you don't want one of this improved command, just delete its part. (I put all of their command name above their script part) ################################
#------------------------------------------------------------- # IMPROVED RANDOM MOVE #------------------------------------------------------------- def move_random safe = false checked = [] while safe == false break if checked.include?(0) and checked.include?(1) and checked.include?(2) and checked.include?(3) case rand(4) when 0; return if checked.include?(0); checked.push 0 if passable?(@x, @y + 1) safe = true; move_down(false) end when 1; return if checked.include?(1); checked.push 1 if passable?(@x - 1, @y) safe = true; move_left(false) end when 2; return if checked.include?(2); checked.push 2 if passable?(@x + 1, @y) safe = true; move_right(false) end when 3; return if checked.include?(3); checked.push 3 if passable?(@x - 1, @y) safe = true; move_up(false) end end end end
#---------------------------------------------------------------------- # IMPROVED COLLIDE_WITH_CHARACTERS CHECK #---------------------------------------------------------------------- def collide_with_characters?(x, y) for event in $game_map.events_xy(x, y) # Matches event position unless event.through # Passage OFF? return true if event.priority_type == 1 # Target is normal char end end if @priority_type == 1 # Self is normal char return true if $game_player.pos_nt?(x, y) # Matches player position return true if $game_map.boat.pos_nt?(x, y) # Matches boat position return true if $game_map.ship.pos_nt?(x, y) # Matches ship position end return false end
################################################################## # SPECIAL(NEW) MOVE COMMANDS ################################################################## #-------------------------------------------------------------------------- # * Move toward Position #-------------------------------------------------------------------------- def move_toward_pos(x,y) sx = distance_x_from_pos(x) sy = distance_y_from_pos(y) if sx != 0 or sy != 0 if sx.abs > sy.abs # Horizontal distance is longer sx > 0 ? move_left : move_right # Prioritize left-right if @move_failed and sy != 0 sy > 0 ? move_up : move_down end else # Vertical distance is longer sy > 0 ? move_up : move_down # Prioritize up-down if @move_failed and sx != 0 sx > 0 ? move_left : move_right end end end end #-------------------------------------------------------------------------- # * Move away from Position #-------------------------------------------------------------------------- def move_away_from_pos(x,y) sx = distance_x_from_pos(x) sy = distance_y_from_pos(y) if sx != 0 or sy != 0 if sx.abs > sy.abs # Horizontal distance is longer sx > 0 ? move_right : move_left # Prioritize left-right if @move_failed and sy != 0 sy > 0 ? move_down : move_up end else # Vertical distance is longer sy > 0 ? move_down : move_up # Prioritize up-down if @move_failed and sx != 0 sx > 0 ? move_right : move_left end end end end #-------------------------------------------------------------------------- # * Move toward Event #-------------------------------------------------------------------------- def move_toward_event(id) move_toward_pos($game_map.events[id].x,$game_map.events[id].y) end #-------------------------------------------------------------------------- # * Move away from Event #-------------------------------------------------------------------------- def move_away_from_event(id) move_away_from_pos($game_map.events[id].x,$game_map.events[id].y) end #-------------------------------------------------------------------------- # * Turn toward Position #-------------------------------------------------------------------------- def turn_toward_pos(x,y) sx = distance_x_from_pos(x) sy = distance_y_from_pos(y) if sx.abs > sy.abs # Horizontal distance is longer sx > 0 ? turn_left : turn_right elsif sx.abs < sy.abs # Vertical distance is longer sy > 0 ? turn_up : turn_down end end #-------------------------------------------------------------------------- # * Turn away from Position #-------------------------------------------------------------------------- def turn_away_from_pos(x,y) sx = distance_x_from_pos(x) sy = distance_y_from_pos(y) if sx.abs > sy.abs # Horizontal distance is longer sx > 0 ? turn_right : turn_left elsif sx.abs < sy.abs # Vertical distance is longer sy > 0 ? turn_down : turn_up end end #-------------------------------------------------------------------------- # * Turn toward Event #-------------------------------------------------------------------------- def turn_toward_event(id) turn_toward_pos($game_map.events[id].x,$game_map.events[id].y) end #-------------------------------------------------------------------------- # * Turn away from Event #-------------------------------------------------------------------------- def turn_away_from_event(id) turn_away_from_pos($game_map.events[id].x,$game_map.events[id].y) end #-------------------------------------------------------------------------- # * Calculate X Distance From Event #-------------------------------------------------------------------------- def distance_x_from_pos(x) sx = @x - x if $game_map.loop_horizontal? # When looping horizontally if sx.abs > $game_map.width / 2 # Larger than half the map width? sx -= $game_map.width # Subtract map width end end return sx end #-------------------------------------------------------------------------- # * Calculate Y Distance From Event #-------------------------------------------------------------------------- def distance_y_from_pos(y) sy = @y - y if $game_map.loop_vertical? # When looping vertically if sy.abs > $game_map.height / 2 # Larger than half the map height? sy -= $game_map.height # Subtract map height end end return sy end end
Instruction You just need to place the script above main, for edited old commands.
? Open 'Move Route' window, (or event command 'Set Move Route') Click 'Script...' and type the move command you want...
Author's Notes Free for use in your non-commercial work if credit included. If your project is commercial, please contact me.
Please do not redistribute this script without permission. If you want to post it on any forum, please link to this topic.
Title: Re: +[Improved & Special Move Commands]+
Post by: modern algebra on March 25, 2008, 12:33:46 PM
Very cool script worale.
Title: Re: +[Improved & Special Move Commands]+
Post by: narcodis on July 29, 2008, 08:06:08 AM
Hella sweet script. I will make fine use of this!
Few questions/suggestions! a) Regarding the safe-jump.. Given that I am, for example, jumping from x5,y13 to x5,y15, and the spot on x5,y14 is impassable, is there a way to disregard the jump that way? b) Is it possible to bypass the safe-jump if the impassable spot is located on an event marked as "same as characters"?