Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Night_Runner's State Dependant Characters, Requested by: Penguin
Night_Runner
post Oct 28 2011, 04:21 AM
Post #1


Level 50
Group Icon

Group: +Gold Member
Posts: 1,519
Type: Scripter
RM Skill: Undisclosed




Night_Runner's State Dependant Characters

Version 1.01
Author Night_Runner
Release Date 28/Oct/2011


Exclusive Script at RPG RPG Revolution


Introduction
This script allows the developer the ability to change the map graphic of actors depending on whether or not they have a specific state inflicted.
This can be useful for battle systems that occur on the map, to give visual feedback to the player to remind them that they are poisoned, for example, or to let the player know that they need to see a hospital soon..


Script
code
CODE
#==============================================================================
# ** VX: Night_Runner's State Dependant Characters
#------------------------------------------------------------------------------
# History:
#  Date Created: 28/Oct/2011
#  Created for: Penguin
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=53619
#
# Description:
#  This script allows the developer the ability to change the map graphic
#  of actors depending on whether or not they have a specific state
#  inflicted.
#
# How to Install:
#  Copy this entire script. In your game's editor, select Tools >>
#  Script Editor. Along the left hand side scroll all the way to the
#  bottom, right click on the square after ( Insert here ), and select
#  "Insert". Paste the code on the right.
#
# Customisation:
#  See below on line 41 for an example of how to setup the state differences,
#  but an example is:
#   [["Actor2", 0], 1] => ["ActorDown", 2]
#  where Actor2 is the filename for the graphic that has the actors
#  original graphic, the 0 means that it is the 1st spriteset in the file,
#  1 means state #1 is inflicted, ActorDown is the filename of the new
#  charater graphic, and 2 means that it will use the 3rd graphic in
#  that file.
#  
#==============================================================================



#==============================================================================
# ** Customisation
#==============================================================================

module NR_StateDependantCharacters
  OrigGraphicStateNewGraphic = {
#   [[origGraphic, graphicIndex], stateID] => [newGraphic, graphicIndex]
    [["Actor1", 0], 2] => ["Actor1", 4], # Ralph with poison looks like Lawrence
  }
end



#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  Edited to show a different character while a state is inflicted.
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias nr_stategraphics_initialize    initialize    unless $@
  alias nr_stategraphics_setup         setup         unless $@
  alias nr_stategraphics_set_graphic   set_graphic   unless $@
  alias nr_stategraphics_add_state     add_state     unless $@
  alias nr_stategraphics_remove_state  remove_state  unless $@
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args)
    # Initialise our variables
    @original_character_name = ""
    @original_character_index = ""
    # Run the original initialize
    return nr_stategraphics_initialize(*args)
  end
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(*args)
    # Run the original setup
    ret_val = nr_stategraphics_setup(*args)
    # Get the character graphic and index to return to
    @original_character_name = @character_name.clone
    @original_character_index = @character_index
    return ret_val
  end
  #--------------------------------------------------------------------------
  # * Set Graphic
  #--------------------------------------------------------------------------
  def set_graphic(*args)
    # Run the original set graphic
    ret_val = nr_stategraphics_set_graphic(*args)
    # Get the character graphic and index to return to
    @original_character_name = @character_name.clone
    @original_character_index = @character_index
    return ret_val
  end
  #--------------------------------------------------------------------------
  # * Generate State Graphic
  #     state : Array of state ID's
  #--------------------------------------------------------------------------
  def generate_state_graphic(states)
    # Get the starting graphic (checks for changes before refreshing later)
    starting = [@character_name.to_s.clone, @character_index]
    # Loop through every state
    for state_id in states.to_a
      # Get the key associated with this state & actor
      key = [[@original_character_name, @original_character_index], state_id]
      # Get the new graphic
      new_graphic = NR_StateDependantCharacters::OrigGraphicStateNewGraphic[key]
      # Skip if the new graphic does not exist
      next if new_graphic == nil
      # Set the character to the new graphic
      @character_name = new_graphic[0]
      @character_index = new_graphic[1]
      # If this is a change, then refresh the player
      if [@character_name, @character_index] != starting
        $game_player.refresh
      end
      return
    end
    @character_name = @original_character_name
    @character_index = @original_character_index
    if [@character_name, @character_index] != starting
      $game_player.refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Add State
  #     state_id : state ID
  #--------------------------------------------------------------------------
  def add_state(*args)
    # Run the original add_state
    ret_val = nr_stategraphics_add_state(*args)
    # Update the states
    generate_state_graphic(@states)
    return ret_val
  end
  #--------------------------------------------------------------------------
  # * Remove State
  #     state_id : state ID
  #--------------------------------------------------------------------------
  def remove_state(*args)
    # Run the original remove_state
    ret_val = nr_stategraphics_remove_state(*args)
    # Update the states
    generate_state_graphic(@states)
    return ret_val
  end
end



#==============================================================================
# ** End of Script.
#==============================================================================


Customization
CODE
#  See below on line 41 for an example of how to setup the state differences,
#  but an example is:
#   [["Actor2", 0], 1] => ["ActorDown", 2]
#  where Actor2 is the filename for the graphic that has the actors
#  original graphic, the 0 means that it is the 1st spriteset in the file,
#  1 means state #1 is inflicted, ActorDown is the filename of the new
#  charater graphic, and 2 means that it will use the 3rd graphic in
#  that file.


Compatibility
The only forseeable issue may be with my horrible naming convention for the variables @original_character_name and @original_character_index, which may be used in other scripts, otherwise it only aliases methods, so it should play nice with everything.

Screenshot
Screenshots

The event that causes the state:


The code:


Before state:


After state:



DEMO
Not applicable


Installation
CODE
#  Copy this entire script. In your game's editor, select Tools >>
#  Script Editor. Along the left hand side scroll all the way to the
#  bottom, right click on the square after ( Insert here ), and select
#  "Insert". Paste the code on the right.



FAQ
Ask away


Terms and Conditions
Use however you want.


Credits
Penguin for requesting
Night_Runner for creating.


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
SlimmeTurq
post Oct 28 2011, 05:38 AM
Post #2


Level 1
Group Icon

Group: Member
Posts: 6
Type: Scripter
RM Skill: Intermediate




Meh, I guess this is just eventable:

New Event > New Event Command > Second Tab > Set move route > Change Graphic, select the graphic you want to replace with the original one.


__________________________

Support Me:



'

CODE
[url="http://www.rpgmakervx.net/index.php?showtopic=49968"][img]http://img546.imageshack.us/img546/2496/scriptingshopbar.png[/img][/url]



My Scripts:

Go to the top of the page
 
+Quote Post
   
Night_Runner
post Oct 28 2011, 06:57 AM
Post #3


Level 50
Group Icon

Group: +Gold Member
Posts: 1,519
Type: Scripter
RM Skill: Undisclosed




You can get something similar with eventing, but it's not as versatile.
A lot of developers use some form of character generation, so you ask the player "what colour is your hair", and so on, which spits out the player. My code will remember that character, will find a unique state affected spriteset for it, and will simply return it once it's done. Imagine having to go through all those @> Conditional Branch: Variable [0001: Hair Colour] == 0 for every layer until you finally get the character you're after, just to get the unique character. And then you have to loop through every state for every character.
Another example of where you may want to use my code; battle systems. If you're in a battle and you get poisoned, by default you can't call a common event when a state is inflicted/removed, so you would need to have a common event on the map, running every single frame, checking to see if the state has been added/removed from every single character.
Thank you for your feedback, I am aware of the Change Graphic command, but this is just a tool that can be used by developers to make their lives easier happy.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
SlimmeTurq
post Oct 28 2011, 07:06 AM
Post #4


Level 1
Group Icon

Group: Member
Posts: 6
Type: Scripter
RM Skill: Intermediate




@Night_Runner, Oh I see. I didn't look it from that perspective. Anyways, Good Work!


__________________________

Support Me:



'

CODE
[url="http://www.rpgmakervx.net/index.php?showtopic=49968"][img]http://img546.imageshack.us/img546/2496/scriptingshopbar.png[/img][/url]



My Scripts:

Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th May 2013 - 12:39 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker