Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Heretic86

XP Script - Heretic's Idiot Ruby / RGSS Questions...

Question

Am I getting annoying yet?

 

Okay, trying to create a new def that updates itself. Mostly for debug purposes, displaying variable values in a Sprite on the screen so I can watch them realtime. I got the graphics working so dont need to mess with that, just need to know how to run a continual update without hitting Stack Level Too Deep. It appears that an update cant self reference.

 

What is the best way to create a new anything that can self update?

 

(edit: Changed thread title to be more accurate)

Edited by Heretic86

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0

This is not possible.

 

If you want a process to self update without hanging, you need to put a Graphics.update command that will advance frames. But if you do that, you're overriding the main porcess's Graphics.update, so the rest of the game won't run anymore. You have to include whatever portion of code you'd like to add in the class's update method, then call it from the main process (or from an object called from the main process).

Share this post


Link to post
Share on other sites
  • 0

Ok, that makes sense. Dont wanna mess with Main. Could you provide an easy example, if it isnt too much work? (I know it is a lot of work...) Say something like a frame_counter...

Edited by Heretic86

Share this post


Link to post
Share on other sites
  • 0

Well, really I am trying to understand how RMXP works better. Since most of what I know is php, it loads, runs, and its done, otherwise the page doesnt come up. The example I was hoping for was to back your explanation of graphics.update, as I tried that, and it either doesnt update, or comes up with Stack Level Too Deep, so I know I am doing something wrong...

Share this post


Link to post
Share on other sites
  • 0

Well, the thing is, I don't know what you are doing. That's why I don't know what example to give you.

 

Basically, the main process creates a Scene object and calls its main method, which loops until the scene is exited (either replaced by another scene or not, in which case the game stops). The scene in turn creates windows and sprites and stuff, and for each, calls their update method. Since the scene loops over one update call, then a frame refresh, each object is updated once per frame. So, whatever you are trying to do, there's no other way to update your objects than referencing them in the appropriate scene and have it call their update method. I don't know if this is of any help, since this is what one could infer from reading RMXP's default scripts.

Share this post


Link to post
Share on other sites
  • 0

module Graphics

class << self

alias custom_update update
def update
custom_update
if $sprite == nil
viewport = Viewport.new(0, 0, 160, 32)
viewport.z = 99999
$sprite = Sprite.new(viewport)
$sprite.bitmap = Bitmap.new(160, 32)
end
$sprite.bitmap.clear
$sprite.bitmap.draw_text(0, 0, 160, 32, self.frame_count.to_s, 1)
end
end
end

 

Here is a basic example. This style of doing is by creating a meta-class of the Graphics module and aliasing the update method. It give you a separate update method that will run no matter what, as long as the Graphics are being updated. I don't suggest redrawing a bitmap every frame or anything like the example, but its just there to give you the idea.

Share this post


Link to post
Share on other sites
  • 0

If this forum had a +Rep system, you'd be #1 by making like 4 posts!

 

Good news, it works great. Using more as a Dev tool rather than intended for actual gameplay. It was for the Cloud Altitude script you also helped me with there, Forever... Bad news, now when I try to access the Global Variable ($game_map.fog_altitude) Undefined Method error! Global Variables are only Global for that Module? What the hell is the a Module? Class container? I have so damn much to learn. /cry

 

(And yes, I've been trying my damnedest to read the tutorials on RGSS...)

Share this post


Link to post
Share on other sites
  • 0

The Graphics update is running before they are defined.

 

You can do something like:

 

if $game_system != nil
 # Do some stuff with the Game_System class
end

 

Basically just make sure that things are defined before referencing them. That is one drawback of using the Graphics update as an alias. Some stuff won't be created yet when it begins to update. Its usually wiser to alias Game_System's update method, since every scene will likely be calling it, and it is only called after things are created.

Share this post


Link to post
Share on other sites
  • 0

Ok, well, with your help, I managed to accomplish that task. Implemented a bit differently, but if you are interested, its in the Cloud Altitude Script. I was trying to make a Developer Tool for displaying the Variables that the Script was messing with.

 

On to my next Idiot Question. Zeriab's Caterpillar. Im trying to manipulate screen_z for the Cat Actor Sprites. They stack wrong. I appear to be able to read "actor.screen_z" (for loop iteration) and $game_player.screen_z but cant directly modify it. I thought maybe fix that with an "attr_accessor :", but the Script isnt part of the same Class, it is its own class. Since everything is by reference, I tried to put in the attr_accessor for screen_z anyway, but came up with wrong number of arguments error. Thinking that is caused by the class being reinitialized and I wasnt sending any arguments to it. Ok, what args does it expect? I found this: which expects @ch self.z = @character.screen_z(@ch). So @ch is Character Height: @ch = bitmap.height / 4, so it wants a number divisible by 4 I guess. Go back, try to run "actor.screen_z(16)" (arbitrary number divisible by 4), but now come up with NoMethodError for screen_z.

 

Script:

#==============================================================================
# ** Zeriab's Caterpillar Script
#------------------------------------------------------------------------------
# Zeriab
# 1.0
# 2008-08-16
#------------------------------------------------------------------------------
# This script creates a caterpillar of the party members by using events.
#------------------------------------------------------------------------------
# Paste this script just above main.
#
# Put \cat_actor[3] in the name of an event and it will be considered the event
# for the actor with id 3. The name could for example be "Cyrus\cat_actor[3]"
#
# The switch number specified with CATERPILLAR_ACTIVE_SWITCH (default is 23) is
# used to determine whether the events should be positioned in the caterpillar
# or not. Then the switch is off they are just like any other event.
#
# Heretic:  I added a CATERPILLAR_PAUSE_SWITCH (default is 22) to be a Temporary
# way to stop the Characters Movements during Cutscenes.  While this switch is
# set to ON, Characters in the Caterpillar will not move, unless specified by
# another Event, such as a Cutscene Event.  Any of the Main Actors Movements
# will NOT be Recorded, so when the Pause Switch is turned off, the other
# Caterpillar Actors will resume any new Movements of the Main Actor (including
# those in Events.  The reason that this was added is that while the Active
# switch is ON, the other Characters continue to follow the Main Actor, however
# turning the Active Switch OFF, then ON again causes everyone in the
# Caterpillar Train to stack on top of the Main Character.
#
# If you use the PAUSE_SWITCH, it ON and OFF in the same place, or use either
# $game_system.caterpillar.clear_moves (and fake the caterpillar for 3 moves)
# or $game_system.caterpillar.del_last_move to erase the last recorded move
# event.  More on those commands later.
# The REMOVE_VISIBLE_ACTORS (default is true) is used to determine whether
# actor event not in the party should be erased or not.
# If it is set to an integer rather than true or false the switch with the
# corresponding id is used. For example REMOVE_VISIBLE_ACTORS = 21 will allow
# you to determine whether the events should be erased or not depending whether
# switch 21 is OFF or ON.
#
# The MAX_ACTORS (default is 4) is used to determine how many player moves
# should be remembered. Only change this if you can have a party with more than
# 4 actors.
#
# Heretic:  I also added two additional Commands that need to be called
# by running a SCRIPT in an EVENT.  The two Commands are:
#
# clear_moves
# del_last_move
#
# Call these Commands by running:
# $game_system.caterpillar.clear_moves
# $game_system.caterpillar.del_last_move
#
# clear_moves erases all of the characters movements.  I found this to be
# semi useful at the end of cutscenes while trying to get any following
# characters back into a Caterpillar position when returning control of
# the Players Character to the Player.
#
# del_last_move is useful for allowing the Player to move the Main Character
# on to a Tile that the rest of the Caterpillar Characters should NOT go
# for example, a bridge that falls away just as the Player steps on it, then
# steps back off of it.  In this situation, it would appear pretty strange
# to allow the rest of the Caterpillar to walk over a place where the
# Bridge had just fallen away and preventing future Player Movement
# across that Tile.
#
# ---  NOTES ---
#
#  I've found it to be useful when creating new maps to create ONE Placeholder
#  Event, followed by ALL of your games characters, whether they are going
#  to be in your party on the new mapscreen or not.  This has less to do with
#  the way Zeriab's script works, and more to do with the way that the
#  Multiple Message Windows script works.  Zeriab's script works by getting
#  the Events by Event Name, hence the requirement for "Name\cat_actor[3]" of
#  each event expected for the Caterpillar.  Unfortunately, the MMW Script
#  does NOT do quite as excellent of a job of identifying events by Name, but
#  instead, by Event ID.  Event ID's are created in ORDER.  Thus, the first event
#  that you creat will be EV001, and the next will be EV002, followed by EV003, so
#  on and so forth.  However, if you delete EV002 and have FIVE events, the NEXT
#  Event to be created will be the LOWEST POSSIBLE EVENT ID NUMBER.  Thus, if you
#  deleted EV002, then create a New Event, that New Event will take that lowest
#  number, making the New Event EV0002.  This is important because the MMW Script
#  calls by Event ID.  So during a Cutscene with your Characters, you have to
#  refer to them by \P[0] for the Main Character, and it skips EV0001 for some
#  reason, then goes to EV0002 as the 2nd Character.  Again, this is NOT for
#  move events, only Dialogue Events (MMW).  I've found it much easier once
#  I have set up all the Characters to have the Same Event ID on EVERY MAP.  Also
#  since the Character Events will be the most frequently moved events, it is
#  easier to do without having to hunt through the entire list, when they are
#  all organized nicely at the top of your list.  Otherwise, you'll end up trying
#  to remember that on This Map, your 2nd Character is EV043 and on That Map, your
#  2nd Character is EV036.
#
#==============================================================================
class Game_Caterpillar
 CATERPILLAR_PAUSE_SWITCH = 22
 CATERPILLAR_ACTIVE_SWITCH = 23
 REMOVE_VISIBLE_ACTORS = false
 MAX_ACTORS = 4
 ##
 # Initialize the caterpillar
 #
 def initialize
@actors = []
@actor_id_to_event = {}
@move_list = []
 end
 ##
 # Clear the caterpillar data
 #
 def clear
@actors.clear
@actor_id_to_event.clear
@move_list.clear
 end
 ##
 # Clear the Move data
 #
 def clear_moves
@move_list.clear
 end
 ##
 # Add an actor event to the caterpillar
 #
 def add_actor(event, actor_id)
@actor_id_to_event[actor_id] = event
event.move_list.clear
added = false
for actor in $game_party.actors
  if actor.id == actor_id
	@actors << event
	if !$game_switches[CATERPILLAR_PAUSE_SWITCH]
	  event.moveto($game_player.x, $game_player.y)
	  added = true
	end
  end
end
if remove_visible_actors? && !added && $game_switches[CATERPILLAR_ACTIVE_SWITCH]
  event.erase
end
 end
 ##
 # Check if visible actors should be removed
 #
 def remove_visible_actors?
if REMOVE_VISIBLE_ACTORS.is_a?(Integer)
  return $game_switches[REMOVE_VISIBLE_ACTORS]
else
  return REMOVE_VISIBLE_ACTORS
end
 end
 ##
 # If the game player has been center. I.e. teleported somewhere.
 #
 def center
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH]
# Clear the move_llist
@move_list.clear
# Refresh the caterpillar
update
# Move the actors to the new place
for event in @actors
  event.moveto($game_player.x, $game_player.y)
  event.move_list.clear
end
 end
 ##
 # Refresh the caterpillar. (Use sparingly)
 #
 def refresh
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH] && !$game_switches[CATERPILLAR_PAUSE_SWITCH]
# Clear the data
clear
# Check each event
for event in $game_map.events.values
  if event.is_a?(Game_Event)
	event.check_caterpillar
  end
end
# Center the events around the player
center
# Update the caterpillar
update
 end
 ##
 # Register a player move
 #
 def register_player_move(move_speed, *args)
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH] && !$game_switches[CATERPILLAR_PAUSE_SWITCH]
# Add the new command
@move_list.unshift([move_speed, args])
# Append the new moves to the caterpillar events
update_actor_movement
# Check if the last command should be removed
if @move_list.size > MAX_ACTORS + 1
  # Remove the last move command
  @move_list.pop
end
 end
 ##
 # Updates the actors movement.
 #
 def update_actor_movement
for i in [email="0...@actors.size"]0...@actors.size[/email]
  if i + 1 < @move_list.size
	command = @move_list[i + 1]
	actor = @actors[i]
	actor.move_list.unshift(command[1])
	actor.move_speed = command[0]
  end
end
 end
 ##
 # Update the caterpillar.
 #
 def update
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH]
old_actors = @actors
@actors = []
# Create a copy of the party actors
caterpillar = $game_party.actors.dup
# Remove the first element
caterpillar.shift
# Go through each actor that's possible present in the caterpillar
for actor in caterpillar
  event = @actor_id_to_event[actor.id]
  unless event.nil?
	@actors << event
	event.unerase if remove_visible_actors?
	event.character_name = actor.character_name
  end
end
if remove_visible_actors?
  # Go through the old actors to see if any should be erased
  for actor in old_actors
	unless @actors.include?(actor)
	  actor.erase
	end
  end
end
 end
 ##
 # Delete Last Characters Movement
 # (Call with $game_system.caterpillar.del_last_move)
 #
 def del_last_move
@move_list.delete_at(0)
 end
 ##
 # Unerase all erased actor events
 #
 def unerase_all
for event in @actor_id_to_event.values
  event.unerase
end
 end
 ##
 # Erase actor events not in the party
 #
 def erase_non_party_events
for event in @actor_id_to_event.values
  event.erase unless @actors.include?(event)
end
 end
end
class Game_Player < Game_Character
 unless self.method_defined?('zeriab_caterpillar_game_player_center')
alias_method(:zeriab_caterpillar_game_player_center, :center)
 end
 ##
 # When the player is centered (i.e. teleported somewhere)
 #
 def center(*args)
zeriab_caterpillar_game_player_center(*args)
$game_system.caterpillar.center
 end

 ##
 # Generate registration of player moves to the caterpillar code
 #
 MOVE_METHODS = ['move_down', 'move_left', 'move_right', 'move_up',
			  'move_lower_left', 'move_lower_right', 'move_upper_left',
			  'move_upper_right', 'jump']

 # Go through each method
 for method in MOVE_METHODS
# Create the script for the specific method
PROG = <<_END_
 def #{method}(*args)
x,y = self.x, self.y
super(*args)
unless self.x == x && self.y == y
  $game_system.caterpillar.register_player_move(@move_speed, '#{method}', args, [self.x, self.y])
end
 end
_END_
# Run the script
eval(PROG)
 end
end
class Module
 # Prevent adding the method again should it already be present.
 unless self.method_defined?('attr_sec_accessor')
def attr_sec_accessor(sym, default = 0)
  attr_writer sym
  attr_sec_reader sym, default
end

def attr_sec_reader(sym, default = 0)
  sym = sym.id2name
  string = "def #{sym};" +
		   "  @#{sym} = #{default}  if @#{sym}.nil?;" +
		   "  @#{sym};" +
		   "end;"
  module_eval(string)
end
 end
end
class Game_System
 attr_sec_accessor :caterpillar, 'Game_Caterpillar.new'
end
class Game_Event < Game_Character
 ##
 # Attributes
 #
 attr_sec_accessor :move_list, '[]'
 attr_accessor	 :move_speed
 attr_writer	   :character_name
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_event_passable?')
alias zeriab_caterpillar_game_event_initialize :initialize
alias zeriab_caterpillar_game_event_passable?  :passable?
if Module.constants.include?('SDK')
  alias zeriab_caterpillar_game_event_update_movement  :update_movement
else
  alias zeriab_caterpillar_game_event_update  :update
end
 end
 ##
 # Object Initialization
 #
 def initialize(map_id, event, *args)
# Default update
zeriab_caterpillar_game_event_initialize(map_id, event, *args)
# Check if the caterpillar is active
return unless $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
# Check for caterpillar actor denomination
check_caterpillar
 end
 ##
 # Check for caterpillar actor denomination
 #
 def check_caterpillar
# Check for caterpillar actor denomination (Last is used if more present)
@event.name.gsub(/\\cat_actor\[([0-9]+)\]/i) [email="{@caterpillar_actor"]{@caterpillar_actor[/email] = $1 }
# Check if an valid denomination is found.
if @caterpillar_actor.is_a?(String)
  @caterpillar_actor = @caterpillar_actor.to_i
  if $data_actors[@caterpillar_actor].nil?
	@caterpillar_actor = nil
  else
	$game_system.caterpillar.add_actor(self, @caterpillar_actor)
  end
end
 end
 ##
 # Check passability
 #
 def passable?(*args)
if @caterpillar_actor.nil? || move_list.empty? ||
   !$game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
  return zeriab_caterpillar_game_event_passable?(*args)
else
  return true
end
 end
 ##
 # SDK and Non-SDK stuff
 #
 if Module.constants.include?('SDK')
##
# Update Movement
#
def update_movement
  if @caterpillar_actor.nil? || move_list.empty? ||
	 !$game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
	return zeriab_caterpillar_game_event_update_movement
  end
  # Interrupt if not stopping
  if jumping? or moving?
	return
  end
  # Retrive the command
  command = move_list[0]
  # Call the command
  method(command[0]).call(*command[1])
  # Make sure the x and y are right in the end
  @x, @y = *command[2]
  # Remove the command
  move_list.pop
end
 else # Non-SDK version
##
# Update Movement
#
def update
  # Interrupt if not stopping
  no_move = jumping? or moving?
  # Update
  zeriab_caterpillar_game_event_update
  # Check if it should return
  if $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH] &&
	 @caterpillar_actor != nil && !move_list.empty? && !no_move
	# Retrive the command
	command = move_list[0]
	# Call the command
	method(command[0]).call(*command[1])
	# Make sure the x and y are right in the end
	@x, @y = *command[2]
	# Remove the command
	move_list.pop
  end
end
 end
 ##
 # Bring back an erased event
 #
 def unerase
@erased = false
refresh
 end
end
class Game_Map
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_map_setup')
alias zeriab_caterpillar_game_map_setup :setup
 end
 ##
 # Transfer Player
 #
 def setup(*args)
$game_system.caterpillar.clear
zeriab_caterpillar_game_map_setup(*args)
 end
end
class Game_Switches
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_switches_setter')
alias zeriab_caterpillar_game_switches_setter :[]=
 end
 ##
 # Setter
 #
 def []=(switch_id, value, *args)
zeriab_caterpillar_game_switches_setter(switch_id, value, *args)
if switch_id == Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH
  $game_system.caterpillar.refresh
elsif switch_id == Game_Caterpillar::REMOVE_VISIBLE_ACTORS
  if value
	$game_system.caterpillar.erase_non_party_events
  else
	$game_system.caterpillar.unerase_all
  end
end
 end
end
class Interpreter
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_interpreter_command_129')
alias zeriab_caterpillar_interpreter_command_129 :command_129
alias zeriab_caterpillar_interpreter_command_322 :command_322
 end
 ##
 # Change Party Member
 #
 def command_129
result = zeriab_caterpillar_interpreter_command_129
$game_system.caterpillar.refresh
return result
 end
 ##
 # Change Actor Graphic
 #
 def command_322
result = zeriab_caterpillar_interpreter_command_322
$game_system.caterpillar.update
return result
 end
end

 

 

Code is Slightly Modified (heavy commenting by me), this version is functional.

 

I think I need to modify "def add_actor" (around line 130 or so) and fix the Z-Index problem inside there, where I can read actor.screen_z (for loop iteration), but cant modify the value.

 

Can anyone explain what I am doing wrong this time?

 

/bangs head against wall

Share this post


Link to post
Share on other sites
  • 0

Actors and characters a not the same. screen_z is a Game_Character method, and you are calling it on a Game_Actor object. Game_Character is used mainly for map objects like the events, player, etc. It holds data that is used to construct the respective sprite in the Sprite_Character class. Game_Actor on the other hand is more for the statistics, equipment, etc, and has no real ties to sprites and screen objects other than the name of their battler graphic.

 

I personally think that Enterbrain didn't do a very good job structuring this particular portion of their scripts. They made it harder than it should have to be to tie these classes together for scripters, although in your case it shouldn't pose a problem. Just reference the correct object.

Share this post


Link to post
Share on other sites
  • 0

I know I am struggling to understand the syntax, and that is holding me back a lot.

 

Rethinking. Take two events and stack them on top of each other. Neither are flagged "always on top". Is there a way to change which event is on top of the other one? The more I look at screen_z, the more it seems to not want to work for me...

Share this post


Link to post
Share on other sites
  • 0

Firstly I'd like to state this:

screen_z is not a property. It is a method that calculates and returns the Game_Character object's 'Z' index (draw depth)

 

Next, this may be confusing but, Game_Actor does have a similar screen_z method that acts similar to Game_Character's screen_z . However, THAT screen_z is meant for positioning the actor's battler NOT their walking sprite.

 

All game sprites (on map) are either a Game_Event or Game_Player ($game_player is a Game_Player), both of which are subclasses of Game_Character. hence why you need to look at Game_Character#screen_z

 

I think you are beginning to realize this, I figured I'd point it out.

So, in order to mess with the z-index of things, we need to figure out how it works:

  #--------------------------------------------------------------------------
 # * Get Screen Z-Coordinates
 #	 height : character height
 #--------------------------------------------------------------------------
 def screen_z(height = 0)
# If display flag on closest surface is ON
if @always_on_top
  # 999, unconditional
  return 999
end
# Get screen coordinates from real coordinates and map display position
z = (@real_y - $game_map.display_y + 3) / 4 + 32
# If tile
if @tile_id > 0
  # Add tile priority * 32
  return z + $game_map.priorities[@tile_id] * 32
# If character
else
  # If height exceeds 32, then add 31
  return z + ((height > 32) ? 31 : 0)
end
 end

 

So, here we go.

if the Event has the always on top option set (@always_on_top), Z will always be 999.

 

Since we know, in your case, that is false we can ignore that.

z = (@real_y - $game_map.display_y + 3) / 4 + 32

First, the 'Z' is calculated from Character's Y coordinate (@real_y), this creates the effect that as things move down the screen, they get closer or as the move up the appear farther away (this is how you can stand behind an event, as well as stand in front of them).

 

So, first thing: The greater Y (lower down), the greater the Z value will be (closer to the screen) and vice versa. (Also note: if two sprites set the same Z value, the first sprite will be drawn before the second sprite)

 

Next, if the character is a tile (by setting the event graphic to a tile rather than a character set) some more calculations are done, but you are working with character sprites, so we can ignore that.

 

Finally, if the character is taller than 32 pixels (i.e. taller than a tile) they receive a greater z-index.

 

So, how can we fix this? Well, we just need to redefine the calculations that provide the scripts with the z-index.

If self is in the caterpillar
 use a different calculation.
else
 use original calculations

or something.

Conveniently, Zeriab's caterpillar script already does half the work for this:

=> event class has been altered to add the @caterpillar_actor instance variable -- we can test to see if the event is in the caterpillar

 

So, let add alias the screen_z method and play with it:

NOTE: this can be done directly INSIDE the Game_Event class, but this way of messing with it, will give us more room to experiment without damaging the original script

class Game_Event

 # alias the screen_z method, then redefine the old version
 unless method_defined?(:old_screen_z)
   alias :old_screen_z :screen_z
 end

 def screen_z
   # if @caterpillar is not nil
   if @caterpillar_actor
      # return new calculations.
      # this is just an example, but it will order the
      # caterpillar actors based on their index in the party
      # 0 - on top, 3-on bottom
      actor_index = $game_actors[@caterpillar_actor].index
      if actor_index # actor_index is nil if actor is NOT in the party
        return old_screen_z - actor_index
      end
   end
   # @caterpillar is nil, self is not in caterpillar
   # return the original calculations, unaltered:
   return old_screen_z
 end
end

 

unless method_defined?(:old_screen_z)

 

this will prevent RPG maker re-aliasing a method (which would mean the new method will reference itself, and thus infinitely call itself. This is recursion, which rpg maker doesn't play well with...and even worse it's broken--it is an infinite loop. When you f12 reset an rpg maker xp game, any open aliases will re-execute, and thus when the new definition calls itself, you get a stack level too deep error.)

 

if @actor_caterpillar

 

the @actor_caterpillar in zeriab's script stores the actor_id of the actor the event represents in the caterpillar, which is nil if they are not in the caterpillar.

in the context of < if (expression) > expression will be considered "true" if it is anything except nil or false and vice versa. So, when @actor_caterpillar is anything other than nil or false, the if clause will be executed.

 

My little example here simply orders the caterpillar's z-index based on the game_party's index order.

 

Hope this helps.

Share this post


Link to post
Share on other sites
  • 0

Gah! Wrote out a big thanking post, but the forum just ate it! Apparently I was still struggling with aliases!

 

One question, on alias :old_screen_z :screen_z

 

can you explain what the : character is for?

Share this post


Link to post
Share on other sites
  • 0

The : is the marker for symbols. Symbols are sort of hybrids between integers and strings: they are commonly used to designate something internal with a name rather than a number (typically variables or methods), but they're not meant to be displayed. You see them used with attr_reader and attr_accessor statements, to designate the instance variable with the same name. In the case of method aliasing, you can write method name either as is or as symbols, so both those syntaxes work:

alias old_method method
alias :old_method :method

Edited by Moonpearl

Share this post


Link to post
Share on other sites
  • 0

It is probably wiser not to use symbol syntax, more to avoid creating a bad habit than being wrong. Ruby symbols are basically the name of an object, whether it be a method, instance variable, string, or constant. The context of what these objects actually are is ignored, so if you had a a method labeled :mySymbol and a class named :mySymbol, they will both have the same object ID, which COULD lead to possible problems in extremely rare cases.

 

For example:

 

class SymbolTest
 SymbolTest = 4
end

def SymbolTest
end

 

All three of these objects have the same object_id, even though one is a class, another is a method, and the other is a constant in a class with the same name.

Share this post


Link to post
Share on other sites
  • 0

When should I use the : character? Trying to have good habits...

 

Still practicing. I came up with the following earlier...

 

 

 def dead_walk_anim
   if @caterpillar_actor
  actor_index = $game_actors[@caterpillar_actor].index
  if actor_index # actor_index is nil if actor is NOT in the party
    @walk_anime = $game_party.actors[actor_index].dead? ? false : true
  end
   end
 end

 

 

Now I am back to fighting with the Z-Index again. I got something working, but it is a little buggy. For example, setting the screen_z - 1 seems to render beneath any Events with Graphics. Now I am thinking of increasing the Z by $game_party.actors.size, then each previous cat_actor gets one less than the main actor. How would I reference the Players sprite? It looks like it is in its own class of "class Game_Player < Game_Character", so going after it by Game_Character seems the logical step. Player has no screen_z method.

 

Next question is about the Lag and Graphics. Forever said earlier that drawing a bitmap every frame is a poor way to do it. Say like a HP bar. Is it better to do it like this?

 

if @hp != $game_player.actor[x].hp

draw_thing

end

Share this post


Link to post
Share on other sites
  • 0

Yes, thats perfect. Any type of graphical related operation is usually the most costly on performance, so you should always only do it when its necessary. The example you have above is the way to do it. First check if the value has changed, then redraw the Bitmap only if it has, otherwise do nothing.

 

This same method of first checking for inequality and then performing the required action can also be extended into other non-graphical things like iterations, etc. A simple check of equality of two objects, especially basic ones like integers, has much less overhead than performing actions every frame when its not needed.

 

As for your other question, the character sprites are a pain in the ass to reference, hence my remark about the poor structure earlier. They are all privately contained in Spriteset_Map, which is also a private object if Scene_Map. Its kinda against convention to reference the objects through the $scene variable, but a quick and dirty way to get to them is something like this:

 

 


class Scene_Map
 attr_accessor :spriteset
end

class Spriteset_Map
 attr_accessor :character_sprites
end

p $scene.spriteset.character_sprites[iNDEX_OF_SPRITE].z

Share this post


Link to post
Share on other sites
  • 0

If that is the case, there is a bunch of code I have to clean up. Not my code, it was written poorly, and redraws every frame.

 

Next question, you gave me an example of how to do a global (which I am trying to avoid), but I find a need for a rare instance of one. Code is actually coming out pretty well. Hell, I think some of you might even wanna use it, well, maybe. Is there a difference of accessing different classes using globals depending on if they are subclasses or not?

 

IE, does "class Game_Event < Game_Character" access different than "class Game_Event"? Im also guessing you are getting the names by going to that Class, and finding ".new", and I see variations in capitalizations. Would I call a Game_Character method using $Character_Sprites.new_method?

 

Having a hard time figuring out how to run a def I set in Game_Event < Game_Character by using a global and attr_writer...

Edited by Heretic86

Share this post


Link to post
Share on other sites
  • 0

Ok what is the difference between

 

class Sprite_Character < RPG::Sprite

 

and

 

class Game_Event < Game_Character ?

Share this post


Link to post
Share on other sites
  • 0

They define the parent of the class. Any child of a class inherits all of its parent functionality, but since it is not the exact class, you are free to modify its methods, etc. See if this helps you understand a bit better in a very basic example

 


class Creature

 attr_reader :name

 def initialize(name)
   @name = name
 end
end

class Dog < Creature

 attr_reader :breed

 def initialize(name, breed)
   super(name) # Calls the parents initialize method, setting the name
   # We don't need to re-define @name since it is in the parent class

   # Since "breed" doesn't apply to all creatures, the Dog class alone uses it
   @breed = breed
 end
end

class Labrador < Dog

 def initialize(name)
   super(name, "Labrador")
   print_some_stuff
 end

 def print_some_stuff
   # Even though we never explicitely set these variables in this class, they
   # were set in the super class, so they are valid for this class
   p @name
   p @breed
 end
end

Share this post


Link to post
Share on other sites
  • 0

Is it just me or are there a couple of "Bugs" in the default scripts?

 

Naming two (I think), Battle Eventing, and Repeat + Wait Until Move Complete. Are those bugs, or is it just me?

Share this post


Link to post
Share on other sites
  • 0

What do you mean bugs.

I know there is a bug in the default battle system that refreshes a window every frame, but I am unaware of any other actual bugs in the scripts. Kinda depends what you mean.

Share this post


Link to post
Share on other sites
  • 0

Okay, I'll try to explain real quick.

 

Battle System - Now this could just be my understanding of the way it works, but I've been playing with a Battle System Mod, that itself had a couple of bugs, so I am now more familiar with it than I previously was.

 

The Bug. In the Database Window, under Troops, there is a spot where you can enter Battle Events. In here, setting the Condition to run during certain conditions. Checking the Turn box, setting which turn number, and I assume that the + Int X means to run that script X number of additional times. Setting the SPAN to Turn, I would think it would only run on that particular Turn. It doesnt. It seems to run every other round, regardless of the X setting. Setting it to Span BATTLE, the Events run only ONCE, regardless of the X count.

 

Next "Bug" happens just with Events and the Move Conditions. Using an Event to say turn right 90 degrees with Repeat causes a Game Lockup (Infinite Loop) using the "Wait for Move's Completion". Try to explain better. Make an Event, like a Townsperson, set Move Route to Custom, and check Repeat there. No crash. If you hit another Player Touch Event for something like a Cutscene, then try to alter the Townsperson Event to have a different move route, (from Event Editor, Page 2, "Set Move Route..." and checking "Repeat Action"), it seems that any other time that "Wait for Move's Completion" causes the game to wait for a Repeating Event, thus, locking up.

 

Does that make sense? And since XP has been out for a while, are there any already made fixes for these Bugs? I can work around them. Just thinking that there needs to be like two lines of code ("if event.move_route.include? "Repeat" Next)

Share this post


Link to post
Share on other sites
  • 0

Okay, back on what I was doing with the Caterpillar script.

 

Trying to add a new feature for Dead Actors Dont Walk. Basically, if the character is dead, that Actor in the Caterpillar has the @walk_anime flag turned off so they just slide around. I find this to be useful if the characters are Poisoned, so like if they die, just from walking around, it is a visual indication of a Dead Character without the need to go into the Player Menu.

 

Does anyone find a Dead Dont Walk feature to be useful?

 

Script:

 

#==============================================================================
# ** Zeriab's Caterpillar Script
#------------------------------------------------------------------------------
# Zeriab
# 1.0
# 2008-08-16
#------------------------------------------------------------------------------
# This script creates a caterpillar of the party members by using events.
#------------------------------------------------------------------------------
# Paste this script just above main.
#
# Put \cat_actor[3] in the name of an event and it will be considered the event
# for the actor with id 3. The name could for example be "Cyrus\cat_actor[3]"
#
# The switch number specified with CATERPILLAR_ACTIVE_SWITCH (default is 23) is
# used to determine whether the events should be positioned in the caterpillar
# or not. Then the switch is off they are just like any other event.
#==============================================================================
class Game_Caterpillar

 CATERPILLAR_PAUSE_SWITCH = 22
 CATERPILLAR_ACTIVE_SWITCH = 23
 DEAD_ACTORS_DONT_WALK = 24
 FORCE_WALK_ANIMATION = 25
 REMOVE_VISIBLE_ACTORS = false
 MAX_ACTORS = 4

end
class Game_Character


end

class Game_Caterpillar
 ##
 # Initialize the caterpillar
 #
 def initialize
@actors = []
@actor_id_to_event = {}
@move_list = []
 end
 ##
 # Clear the caterpillar data
 #
 def clear
@actors.clear
@actor_id_to_event.clear
@move_list.clear
 end
 ##
 # Clear the Move data, leave the Actors
 #
 def clear_moves
@move_list.clear
 end
 ##
 # Resets the Actors Walk Flag to their original Event Flags
 #
 def walk_reset
$game_player.walk_anime = true
$walk_has_been_reset = true
$walk_has_been_set = false  

for event in @actors
  event.walk_anime = event.last_walk_anime
end
 end
 ##
 # Sets all actors to Walk Animation, regardless of Sprite or Dead
 #
 def force_walk
$game_player.walk_anime = true
$force_walk_has_been_set = true

for event in @actors
  event.walk_anime = true
end
 end

 def event_mod(actor,event)
self.hp = actor.hp
self.actor_id = event.id

 end

 def dead_walk_anim

if $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH] and
   $game_switches[Game_Caterpillar::DEAD_ACTORS_DONT_WALK] and
   !$game_switches[Game_Caterpillar::CATERPILLAR_PAUSE_SWITCH]

  # Create a copy of the party actors
  caterpillar = $game_party.actors.dup
  # Remove the first element
  caterpillar.shift
  # Go through each actor that's possible present in the caterpillar
  for actor in caterpillar
	event = @actor_id_to_event[actor.id]
	# Unless Event for that Cat Actor Exists
	if not event.nil?
	  # Actor doesnt have a Walk Animation if Dead
	  event.walk_anime = actor.dead? ? false : true

	  if $walk_reset_array.include? actor.id and $walk_reset_array.size == ($game_party.actors.size - 1)
		$game_player.walk_anime = $game_party.actors[0].dead? ? false : true
		$walk_has_been_reset = false
		$walk_has_been_set = true
	  else
		if not $walk_reset_array.include? actor.id
		  $walk_reset_array.push(actor.id)
		end
	  end	
	else
	  if @print_error != true
		if $DEBUG == true
		  print "DEBUG: Missing a Cat Actor Event for Actor ", actor.id, " on this Map"
		  print "DEBUG: To fix, create an event and name it \"Char_Name\\cat_actor[",actor.id, "]\" on\n this Map.  Need Actor Events on EVERY MAP."
		end

		@print_error == true
		$walk_has_been_reset = false
		$walk_has_been_set = true
	  end
	end
  end
end
 end
 ##
 # Add an actor event to the caterpillar
 #
 def add_actor(event, actor_id)
@actor_id_to_event[actor_id] = event
event.move_list.clear
added = false
for actor in $game_party.actors
  if actor.id == actor_id
	@actors << event

	if !$game_switches[CATERPILLAR_PAUSE_SWITCH]
	  event.moveto($game_player.x, $game_player.y)
	end
	event.last_walk_anime = event.walk_anime
	added = true
  end
end
if remove_visible_actors? && !added && $game_switches[CATERPILLAR_ACTIVE_SWITCH]
  event.erase
end
 end

 ##
 # Check if visible actors should be removed
 #
 def remove_visible_actors?
if REMOVE_VISIBLE_ACTORS.is_a?(Integer)
  return $game_switches[REMOVE_VISIBLE_ACTORS]
else
  return REMOVE_VISIBLE_ACTORS
end
 end
 ##
 # If the game player has been center. I.e. teleported somewhere.
 #
 def center
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH]
# Clear the move_llist
@move_list.clear
# Refresh the caterpillar
update
# Move the actors to the new place
for event in @actors
  event.moveto($game_player.x, $game_player.y)
  event.move_list.clear
end
 end
 ##
 # Refresh the caterpillar. (Use sparingly)
 #
 def refresh
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH] && !$game_switches[CATERPILLAR_PAUSE_SWITCH]
# Clear the data
clear
# Check each event
for event in $game_map.events.values
  if event.is_a?(Game_Event)
	event.check_caterpillar
  end
end
# Center the events around the player
center
# Update the caterpillar
update
 end

 ##
 # Register a player move
 #
 def register_player_move(move_speed, *args)
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH] && !$game_switches[CATERPILLAR_PAUSE_SWITCH]
# Array holds Actors that have their Animations Set for that Step
$walk_reset_array.clear
# Causes Check for Dead Animation to occur
if !$game_switches[FORCE_WALK_ANIMATION]
  $walk_has_been_set = false
end

# Add the new command
@move_list.unshift([move_speed, args])
# Append the new moves to the caterpillar events
update_actor_movement
# Check if the last command should be removed
if @move_list.size > MAX_ACTORS + 1
  # Remove the last move command
  @move_list.pop
end
 end

 ##
 # Updates the actors movement.
 #
 def update_actor_movement
for i in [email="0...@actors.size"]0...@actors.size[/email]
  if i + 1 < @move_list.size
	command = @move_list[i + 1]
	actor = @actors[i]
	actor.move_list.unshift(command[1])
	actor.move_speed = command[0]
  end
end
 end
 ##
 # Update the caterpillar.
 #
 def update
# Check if the caterpillar is active
return unless $game_switches[CATERPILLAR_ACTIVE_SWITCH]
old_actors = @actors
@actors = []
# Create a copy of the party actors
caterpillar = $game_party.actors.dup
# Remove the first element
caterpillar.shift
# Go through each actor that's possible present in the caterpillar
for actor in caterpillar
  event = @actor_id_to_event[actor.id]
  unless event.nil?
	@actors << event
	event.unerase if remove_visible_actors?
	event.character_name = actor.character_name
  end
end
if remove_visible_actors?
  # Go through the old actors to see if any should be erased
  for actor in old_actors
	unless @actors.include?(actor)
	  actor.erase
	end
  end
end
 end
 ##
 # Delete Last Characters Movement
 # (Call with $game_system.caterpillar.del_last_move)
 #
 def del_last_move
@move_list.delete_at(0)
 end
 ##
 # Unerase all erased actor events
 #
 def unerase_all
for event in @actor_id_to_event.values
  event.unerase
end
 end
 ##
 # Erase actor events not in the party
 #
 def erase_non_party_events
for event in @actor_id_to_event.values
  event.erase unless @actors.include?(event)
end
 end
end
class Game_Player < Game_Character

 attr_accessor	  :walk_anime		# Walking Animation Bool

 unless self.method_defined?('zeriab_caterpillar_game_player_center')
alias_method(:zeriab_caterpillar_game_player_center, :center)
 end
 ##
 # When the player is centered (i.e. teleported somewhere)
 #
 def center(*args)
zeriab_caterpillar_game_player_center(*args)
$game_system.caterpillar.center
 end

 ##
 # Generate registration of player moves to the caterpillar code
 #
 MOVE_METHODS = ['move_down', 'move_left', 'move_right', 'move_up',
			  'move_lower_left', 'move_lower_right', 'move_upper_left',
			  'move_upper_right', 'jump']

 # Go through each method
 for method in MOVE_METHODS
# Create the script for the specific method
PROG = <<_END_
 def #{method}(*args)
x,y = self.x, self.y
super(*args)
unless self.x == x && self.y == y
  $game_system.caterpillar.register_player_move(@move_speed, '#{method}', args, [self.x, self.y])
end
 end
_END_
# Run the script
eval(PROG)
 end
end
class Module
 # Prevent adding the method again should it already be present.
 unless self.method_defined?('attr_sec_accessor')
def attr_sec_accessor(sym, default = 0)
  attr_writer sym
  attr_sec_reader sym, default
end

def attr_sec_reader(sym, default = 0)
  sym = sym.id2name
  string = "def #{sym};" +
		   "  @#{sym} = #{default}  if @#{sym}.nil?;" +
		   "  @#{sym};" +
		   "end;"
  module_eval(string)
end
 end
end
class Game_System
 attr_sec_accessor :caterpillar, 'Game_Caterpillar.new'
end
class Game_Event < Game_Character
 ##
 # Attributes
 #
 attr_sec_accessor :move_list, '[]'  # Cat Actors Move List
 attr_accessor	 :move_speed	   # Player Move Speed
 attr_accessor	 :walk_anime	   # Walking Animation Bool
 attr_accessor	 :last_walk_anime  # Last Walking Animation Bool
 attr_writer	   :character_name


 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_event_passable?')
alias zeriab_caterpillar_game_event_initialize :initialize
alias zeriab_caterpillar_game_event_passable?  :passable?
if Module.constants.include?('SDK')
  alias zeriab_caterpillar_game_event_update_movement  :update_movement
else
  alias zeriab_caterpillar_game_event_update  :update
end
 end
 ##
 # Object Initialization
 #
 def initialize(map_id, event, *args)
# Used with Party Members that need to have Walk Animation Reset to Event Original Settings
$walk_reset_array = []
# Default update
zeriab_caterpillar_game_event_initialize(map_id, event, *args)
# Check if the caterpillar is active
return unless $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
# Check for caterpillar actor denomination
check_caterpillar
 end

=begin
 def dead_walk_anim
if $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH] and
   $game_switches[Game_Caterpillar::DEAD_ACTORS_DONT_WALK] and
   !$game_switches[Game_Caterpillar::CATERPILLAR_PAUSE_SWITCH]
  if @caterpillar_actor
	actor_index = $game_actors[@caterpillar_actor].index
	if actor_index
	  # Actor doesnt have a Walk Animation if Dead
	  @walk_anime = $game_party.actors[actor_index].dead? ? false : true

	  if $walk_reset_array.include? actor_index and $walk_reset_array.size == ($game_party.actors.size - 1)
		$game_player.walk_anime = $game_party.actors[0].dead? ? false : true
		$walk_has_been_reset = false
		$walk_has_been_set = true
	  else
		if not $walk_reset_array.include? actor_index
		  $walk_reset_array.push(actor_index)
		end

		# This array holds the Cat Actors that have had their Walk Animations checked
		# When it is equal to the Party Size - 1 (for the Player), set the $walk_has_been_set (global) flag
		#  to True, in order to prevent doing this constantly.
		# When the Player moves, it should return a True once per step, which is more
		#  efficient than continuing to put extra work on the screen_z method, which
		#  I borrowed to run this part of the script.
	  end	
	end
  end
end
 end
=end

 def set_dead_animation
# Resets Caterpillar Actor Walk Animation to Default of Event

if $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
  if $walk_has_been_reset != true and
	$game_switches[Game_Caterpillar::CATERPILLAR_PAUSE_SWITCH] and
	$game_switches[Game_Caterpillar::DEAD_ACTORS_DONT_WALK] and
	!$game_switches[Game_Caterpillar::FORCE_WALK_ANIMATION]
	  # Resets the Player and Caterpillar Actors to Default Walk Flags
	  $game_system.caterpillar.walk_reset
	  #print "reset"
  elsif $walk_has_been_set != true and
	!$game_switches[Game_Caterpillar::CATERPILLAR_PAUSE_SWITCH] and
	!$game_switches[Game_Caterpillar::FORCE_WALK_ANIMATION] and
	$game_switches[Game_Caterpillar::DEAD_ACTORS_DONT_WALK]
	  # Checks for Dead Actors once for each Player Step
	  #dead_walk_anim
	  $game_system.caterpillar.dead_walk_anim
	  #print "Set"
  elsif $game_switches[Game_Caterpillar::FORCE_WALK_ANIMATION] and
	$force_walk_has_been_set != true
	  $game_system.caterpillar.force_walk
	  #print "force"
  end
end
 end

 # Redefine screen_z for Caterpillar
 unless method_defined?(:orig_screen_z)
alias :orig_screen_z :screen_z
 end  
 def screen_z (height = 0)
if @always_on_top
  if @caterpillar_actor
	# Caterpillar Actors based on their Index in the Party
	# 0 - on top, 3-on bottom
	actor_index = $game_actors[@caterpillar_actor].index
	if actor_index # actor_index is nil if actor is NOT in the party
	  # Allows Objects to be On Top If Characters
	  return 998 - actor_index
	end
  else
	# 999, unconditional
	return 999
  end
end

set_dead_animation

# if @caterpillar is not nil
if @caterpillar_actor
  # Caterpillar Actors based on their Index in the Party
  # 0 - on top, 3-on bottom
  actor_index = $game_actors[@caterpillar_actor].index
  if actor_index # actor_index is nil if actor is NOT in the party
	# If height exceeds 32, then add 31 minus Actor Index
	return orig_screen_z + ((height > 32) ? 31 : $game_party.actors.size) - actor_index
  end
end

# In case anything was not handled.  This happens with Non Caterpillar Sprites, or Cat is Paused or OFF.
return orig_screen_z
 end

 ##
 # Check for caterpillar actor denomination
 #
 def check_caterpillar
# Check for caterpillar actor denomination (Last is used if more present)
@event.name.gsub(/\\cat_actor\[([0-9]+)\]/i) [email="{@caterpillar_actor"]{@caterpillar_actor[/email] = $1 }
# Check if an valid denomination is found.
if @caterpillar_actor.is_a?(String)
  @caterpillar_actor = @caterpillar_actor.to_i
  if $data_actors[@caterpillar_actor].nil?
	@caterpillar_actor = nil
  else
	$game_system.caterpillar.add_actor(self, @caterpillar_actor)
  end
end
 end


 ##
 # Check passability
 #
 def passable?(*args)
if @caterpillar_actor.nil? || move_list.empty? ||
   !$game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
  return zeriab_caterpillar_game_event_passable?(*args)
else
  return true
end
 end
 ##
 # SDK and Non-SDK stuff
 #
 if Module.constants.include?('SDK')
##
# Update Movement
#
def update_movement
  if @caterpillar_actor.nil? || move_list.empty? ||
	 !$game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH]
	return zeriab_caterpillar_game_event_update_movement
  end
  # Interrupt if not stopping
  if jumping? or moving?
	return
  end
  # Retrive the command
  command = move_list[0]
  # Call the command
  method(command[0]).call(*command[1])
  # Make sure the x and y are right in the end
  @x, @y = *command[2]
  # Remove the command
  move_list.pop
end
 else # Non-SDK version
##
# Update Movement
#
def update
  # Interrupt if not stopping
  no_move = jumping? or moving?
  # Update
  zeriab_caterpillar_game_event_update
  # Check if it should return
  if $game_switches[Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH] &&
	 @caterpillar_actor != nil && !move_list.empty? && !no_move
	# Retrive the command
	command = move_list[0]
	# Call the command
	method(command[0]).call(*command[1])
	# Make sure the x and y are right in the end
	@x, @y = *command[2]
	# Remove the command
	move_list.pop
  end
end
 end
 ##
 # Bring back an erased event
 #
 def unerase
@erased = false
refresh
 end
end
class Game_Map
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_map_setup')
alias zeriab_caterpillar_game_map_setup :setup
 end
 ##
 # Transfer Player
 #
 def setup(*args)
$game_system.caterpillar.clear
zeriab_caterpillar_game_map_setup(*args)
 end
end
class Game_Switches
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_game_switches_setter')
alias zeriab_caterpillar_game_switches_setter :[]=
 end
 ##
 # Setter
 #
 def []=(switch_id, value, *args)
zeriab_caterpillar_game_switches_setter(switch_id, value, *args)
if switch_id == Game_Caterpillar::CATERPILLAR_ACTIVE_SWITCH
  $game_system.caterpillar.refresh
elsif switch_id == Game_Caterpillar::REMOVE_VISIBLE_ACTORS
  if value
	$game_system.caterpillar.erase_non_party_events
  else
	$game_system.caterpillar.unerase_all
  end
end
 end
end
class Interpreter
 ##
 # Aliases
 #
 unless self.method_defined?('zeriab_caterpillar_interpreter_command_129')
alias zeriab_caterpillar_interpreter_command_129 :command_129
alias zeriab_caterpillar_interpreter_command_322 :command_322
 end
 ##
 # Change Party Member
 #
 def command_129
result = zeriab_caterpillar_interpreter_command_129
$game_system.caterpillar.refresh
return result
 end
 ##
 # Change Actor Graphic
 #
 def command_322
result = zeriab_caterpillar_interpreter_command_322
$game_system.caterpillar.update
return result
 end
end

 

(note: This code will NOT work without MMW and SDK, it was rewritten to be compatible, and that was the only version)

 

Still have a few bugs to work out, I'll work on those. Question on this script (not ready for Public), is there a better more efficient way to do this? I ended up borrowing existing code to do this, but it appears the way it works is to iterate for every event on the map, instead of just iterating thru an array, which I think would be much faster.

Share this post


Link to post
Share on other sites
  • 0

Ok, next idiot question.

 

Im wondering if there is a way to check for an ID (that does exist) in $game_party.actors without Iteration of the Array? Such as $game_party.actors.include? (actor_id_to_check_arg)?

 

This does work

 

for i in 1...$game_party.actors.size

return true if $game_party.actors.actor_id == actor_id_to_check_arg

end

 

Just wondering if there is a different way to do it on one line...

Share this post


Link to post
Share on other sites
  • 0

Game_Party#actors contains Game_Actor objects, so you have to check for the presence of $game_actors[<id you want to check>].

$game_party.actors.include?($game_actors[<id you want to check>])

Share this post


Link to post
Share on other sites
  • 0

Perfect!

 

  def cat_actor_in_party?(cat_actor_id)
   # Used with passable? if cat_actor_id is in the current $game_party
   return $game_party.actors.include?($game_actors[@actor_id_to_event[cat_actor_id].id])
 end 

 

Almost seems pointless to write a def for one line of code, but I think I will anyway because the def says what it does better.

Share this post


Link to post
Share on other sites
  • 0

Next question is about XP vs VX

 

I'll take it that the two engines handle Event Movements completely differently.

 

Im trying to borrow some of the features Modern Algebra put in Zeraibs Caterpillar and effectively port them over to XP. Feature I got working (mostly) and trying to convert has to do with Actor Passability. Mine sucks. His Rox. When I do a movement in XP, some other actors can still pass thru the caterpillar, as if they've left the spot and the next actor hasnt stepped into that spot yet. Doesnt seem to be a problem at all in VX.

 

Is this just because of the difference in the engines, or something more specific with the script? If it is more script specific, I'll post what I got so far...

Share this post


Link to post
Share on other sites
  • 0

Got an idea...

 

How do I check if TWO elements are in an array?

 

I want to check X and Y positions in an array

@move_list = [ [1,2], [1,3], [2,3], [2,4] ]

 

I dont think I can just do "if @move_list.include? [X,Y]

 

How do I do that?

Share this post


Link to post
Share on other sites
  • 0
array = [[4, 5], [6, 7], [8, 9]]
p array[2]

"[8, 9]"

p array[1][1]

"7"

Edited by ForeverZer0

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...