Introduction This script alters the behavior of the Random movement to appear more natural instead of the artificial-seeming default movement. It requires no special configuration to run.
Script
Script
CODE
#=============================================================================== # ** SAI Random Wander State #------------------------------------------------------------------------------- # Author: Bishop Myers ("Sailerius") # Version: 1.01 # Date: 2011.06.15 # SDK Version: 2.4 #=============================================================================== # Instructions # ------------------------------------------------------------------------------ # Just paste this script in below the SDK and all events using Random movement # will automatically begin using the wander state. # ------------------------------------------------------------------------------ # What It Does # ------------------------------------------------------------------------------ # The default Random movement looks very artificial. Instead of choosing a # random adjacent tile to move to, the events will not select a random # destination and walk to it, making it appear as if they're moving with # purpose. Once they reach their new destination, the events will select a new # point to wander to. #=============================================================================== #------------------------------------------------------------------------------- # * SDK Log #------------------------------------------------------------------------------- SDK.log('SAI Wander State', 'Sailerius', 1.0, '2011.06.13') SDK.log_overwrite(:Game_Character, :move_random)
#=============================================================================== # ** Game_Character #=============================================================================== class Game_Character #----------------------------------------------------------------------------- # * Alias Listings #----------------------------------------------------------------------------- alias_method :sailerius_saiwander_gamecharacter_initialize, :initialize alias_method :sailerius_saiwander_gamecharacter_movetyperandom, :move_type_random
#----------------------------------------------------------------------------- # * Public Instance Variables #----------------------------------------------------------------------------- attr_reader :wander_x # map x-coordinate to pursue attr_reader :wander_y # map y-coordinate to pursue
#-------------------------------------------------------------------------- # * Move Type : Random #-------------------------------------------------------------------------- def move_type_random # Check if reached destination if (@wander_x == @x and @wander_y == @y) set_wander_destination end sailerius_saiwander_gamecharacter_movetyperandom end
#-------------------------------------------------------------------------- # * Move at Random #-------------------------------------------------------------------------- def move_random # Get distance from destination dx = @x - @wander_x dy = @y - @wander_y # Move horizontally unless dx == 0 if dx < 0 # Go somewhere else if impassable if not passable?(@x + 1, @y, 0) set_wander_destination return end move_right(false) return else # Go somewhere else if impassable if not passable?(@x - 1, @y, 0) set_wander_destination return end move_left(false) return end end # Move vertically unless dy == 0 if dy < 0 # Go somewhere else if impassable if not passable?(@x, @y + 1, 0) set_wander_destination return end move_down(false) return else # Go somewhere else if impassable if not passable?(@x, @y - 1, 0) set_wander_destination return end move_up(false) return end end end
#-------------------------------------------------------------------------- # * Determine New Wander Destination #-------------------------------------------------------------------------- def set_wander_destination @wander_x = @x + rand(40) - 20 @wander_y = @y + rand(40) - 20 end end
Compatibility This script is designed to work with SDK 2.4, although it shouldn't have problems without it.
DEMO See attachment.
Installation Just paste the script somewhere below the SDK and let it work its magic.
FAQ Q: How does this differ from the default behavior? A: All events using the Random movement will now select a random destination to seek out. Once they reach this destination, they will choose a new one, making it feel as if their movement is purposeful.
Terms and Conditions This script is free for all use, including commercial.
Credits Please give credit to Bishop Myers ("Sailerius") if you use this script.
This post has been edited by Sailerius: Jun 15 2011, 07:13 PM