iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> Class Change Graphics, Change graphic when you change class.
Rating 5 V
Mithran
post Jun 21 2009, 08:49 AM
Post #1


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Class Change Graphics v 1.0
by Mithran


Introduction
Some people like it when each class has their own set of walking and /or face graphics. While this can be easily accomplished with events for an evented class change system, it becomes much more of a pain in a scripted class change system (especially since you can't idependently change face and character sprites, the amount of conditional branches becomes staggering). This script allows you to set up automatic actor character/face changes when they change class. After racking my brain for ideas on how to make this as easy as possible, I decided to just make it customizable with Ruby code using simple case structure. Don't worry, everything is explained in the script...

Features
- change character graphics when they change class

How to Use
Install on its own script page in the materials section of the script editor above main and below default scripts. Read the instructions to configure the setup section in the script (found just after the examples section).

Script
Spoiler:
CODE
# Class Change Graphics
# By Mithran
# Install - Insert below any script that changes class or alters class properties.

# Auto-swaps the 'character' (walking) graphic and /or 'face' graphic of an
# actor when he changes class.
# Edit the methods in the module.  Script gets the class id and actor id of an
# actor right after class change.  Use case statements to check the class_id
# and actor id of the actor and return a file name and index.  Script then
# switches the graphic.  

module Mithran
  module ClassGraphics
    # You will be customizing this script with actual Ruby /RGSS2 code!
    
# = = = = = = = = = = = = = = = = EXAMPLE METHODS = = = = = = = = = = = = = = =
# These are simply examples showing how to set up the script to have it return
# the data that you want.
# Neither of these methods are used in game.  Scroll down for actual setup.
# You should leave these alone for reference, but copying them into
# the other methods wouldnt be a bad idea either

# Script automatically feeds in the class_id and actor_id of anyone who makes
# a class change.  We are going to use this data to determine which graphic
# gets swapped.

# The script will use these methods to look up which new file name and index to
# use for either face or character graphic swaps right after a class change.

# Filename is simply the filename of the new graphic file you want to use.
# index is the index within the file.  Starting from the upper left, indexes
# count one to the right, with row 2 starting at index 4 and lower right being
# index 7.
# For single character sheets, the index is always 0!  Make sure you also include
# the $ in front of the name.  For example, the default character sheet for Ralph
# using Tankentai would be ["$ralph", 0]

# Example 1 is highly recommended for RGSS2 beginners

    def formatting_example(class_id, actor_id)
      # The method is given class_id and actor_id
      case class_id
# Case statment - checks each 'when' line in turn for a match until one is found.
# Once a match is found, no others are checked.  
# This particular statement, checks if class_id matches any of the when lines.
      when 1
        return ["Actor1", 0]
# We are using return lines to pass back a file name and index.  This file name
# and index becomes the new character /face graphic / index for the actor.
      when 2, 3 # multiple can be specified, seperate with commas
        return ["Actor1", 4]
      when 4..6 # four through six, equivolent to 4, 5, 6
        return ["Actor1", 5]
      when 7, 8
        # nested case statment
        case actor_id # checking actor id.  check will only occur if the class id
        # was 7 or 8
        when 1 # Ralph
          return ["Actor1", 6]
        when 2..7
          return ["Actor1", 7]
        else
          return nil
        end
      else
        return nil # returning nil from the method tells the script to not change
        # the graphic from its current graphic
      end # ends the main case statement
      return nil # if an else was missed somewhere, this ensures that nil is
      # returned (no graphic change)
    end
    
# Example 2 - using math
    
    def formatting_example2(class_id, actor_id)
      case class_id
      when 1..8
        return ["Actor1", class_id - 1]
        # If you are using a predictable pattern, you can dramatically narrow
        # down the lines with some math.
        # this particular case statement checks if class id is one through 8
        # if it is, we use the graphic file "Actor1"
        # The index used is the class_id minus 1. In other words
        # Paladin would use Ralph's graphic (index 0)
        # Warrior would use Ulrika's graphic (index 1)
        # Priest would use Bennett's graphic (index 2)
        # and so on, and so forth
      else
        return nil
      end
      return nil
    end

# Example 3 - the if and elsif statements

    def formatting_example3(class_id, actor_id)
      # using if statements and double equals to check equality can be useful
      # If using only a few swaps.  If using more, case is recommended
      if class_id == 4 and actor_id == 1 # if Ralph is changing into a Magician
        return ["Actor1", class_id - 1]
      elsif class_id == 8 and actor_id == 4 # if Ylva is changing to a thief
        # if the 'if' line wasnt true, each 'elsif' is then checked in turn
        return ["Actor1", class_id - 1]        
      elsif class_id <= 8 && actor_id <= 8 # if anyone with an id of 8 or below
        # is changing to a class 8 or below (any of the rtp characters/classes)
        # Remember, this is only checked if the above if and elsif were not true
        return ["Actor1", actor_id - 1] # Default RTP graphics for actors 1-8
      else #if none of the elsif lines were true, use this
        return nil
      end # as always, dont forget to end the statment
      return nil # obligitory nil return to be absolutely sure nothing was missed
    end

    
# = = = = = = = = = = = = = = = = SETUP START = = = = = = = = = = = = = = = = =
    SWAP_AT_START = false
    # If this option is true, graphics will be matched to their respective
    # class change graphics at game start. If false, they will only change when
    # class changes.

    def self.character_swaps(class_id, actor_id) # do not alter this line
    # Define character swaps here.  This is the 'walking graphic' of the actor.
    # For character swaps, the filename must be in the Graphics\Characters folder
# Tankentai -
# For single character sheets, Make sure you also include the $ in front of the
# name.  For example, the default character sheet for Ralph using Tankentai would
# be ["$ralph", 0].  Battler changes are automaticaly bound to character changes.
      case class_id
      when 1 # Paladin
        return ["Actor1", 0]
      when 2 # Warrior
        return ["Actor1", 1]
      when 3 # Priest
        return ["Actor1", 2]
      when 4 # Magician
        return ["Actor1", 3]
      when 5, 6 # Knight, Dark Knight
        case actor_id # nested case statement
        # this checks actor_id if class_id was found to be 5 already
        when 1 # Ralph
          return ["Actor2", 3] # uses the index 3 in "Actor2" if Ralph is
        else
          return ["Actor2", 4] # otherwise, uses index 4
        end # dont forget to end your nested case statement!
      # if you wanted to add more 'when', this would be the spot to do it
      else # otherwise
        return nil # returning nil out of this method will prevent the graphic from changing
      end # end to case class_id
      return nil # if you didnt account for a case or missed an else, returns nil      
    end # end of method - character_swaps - do not alter this line

    def self.face_swaps(class_id, actor_id) # do not alter this line
      # Define face swaps here.  This is the 'face' of the actor for the status screen.
      # For face swaps, the filename must be in the Graphics\Faces folder
      case class_id
      when 1 # Paladin
        return ["Actor1", 0]
      when 2 # Warrior
        return ["Actor1", 1]
      when 3 # Priest
        return ["Actor1", 2]
      when 4 # Magician
        return ["Actor1", 3]
      when 5..8 # Knight, Dark Knight, Grappler OR Thief
        case actor_id # nested case statement
        # this checks actor_id if class_id was found to be 5 already
        when 1 # Ralph
          return ["Actor2", 3]
        # if you wanted to add more 'when' (for actor_id), this would be the spot to do it
        else
          return ["Actor2", 4]
        end # dont forget to end your case statement!
      # if you wanted to add more 'when' (for class_id), this would be the spot to do it
      else # else - used in a case statement, this means 'if it wasnt matched yet'
        return nil # returning nil out of this method will prevent a face change
      end # end to case class_id
      return nil # if you didnt account for a case or missed an else, returns nil      
    end # end of method - face_swaps - do not alter this line

# = = = = = = = = = = = = = = = = SETUP END = = = = = = = = = = = = = = = = = =
# Do not alter anything below here!

  end # end of module ClassGraphics
end # end of module Mithran

class Game_Actor
  
  alias setup_ClassGraphics setup
  def setup(*args)
    setup_ClassGraphics(*args)
    class_graphic_swap(self.class_id, self.id, true) if Mithran::ClassGraphics::SWAP_AT_START
  end
  
  alias class_id_ClassGraphics= class_id=
  def class_id=(new_class_id)
    self.class_id_ClassGraphics = new_class_id
    class_graphic_swap(self.class_id, self.id)
    # method hook, checks for graphical swaps after every class change
  end
  
  def class_graphic_swap(class_id, actor_id, from_setup = false)
    new_char = Mithran::ClassGraphics.character_swaps(class_id, actor_id)
    new_face = Mithran::ClassGraphics.face_swaps(class_id, actor_id)
    # gets the swap data from the module
    if new_char != nil # checks for nil, if nil was returned, no change occurs
      @character_name = new_char[0]
      @character_index = new_char[1]
      # changes character name and index to the specified
      $game_player.refresh unless from_setup
      # refreshes party leader graphic, unless run from object initialization
    end
    if new_face != nil # checks for nil, if nil was returned, no change occurs
      @face_name = new_face[0]
      @face_index = new_face[1]
    end
  end
  
end


How It Works
The method in the module is called every time a class change occurs, evented or otherwise. This method is given the class and actor ids. The case (or if) statements check the method for a match, and when a return line is found, passes back this data. If the return was not nil, the variables @character_name and @character_index are switched to the filename and index returned. On the every frame update, the base scripts detect if the @character_name or @character_index has been changed, and if so, also change the bitmap displayed on screen. Faces are redrawn usually only if the window they are in refreshes, but dont worry, most windows will.

FAQ
q. Is this Tankentai compatible?
a. Tankentai appears to change battler graphics automatically if when the character (walking) graphic is changed. The filename used would be the same as the 'character' graphics, and is bound to 'character' change. All the instructions on how to import and use graphics for the SBS/ATB are explained in that script, so please don't ask here. This should work exactly like an evented graphic change. Even if you somehow change class mid battler, this should take effect on the next main frame update.

q. My scripted class change system doesnt work with this!
a. First, try putting this script below the class change system. If that doesn't work, the creator has completely circumvented the normal class change method. If you provide a link to the script, I will write a small patch that will make this work.

q. How about just making this work every frame update?
a. You can run a parallel process with the following script command:
CODE
for member in $game_party.members
  member.class_graphic_swap(member.class_id, member.actor_id, true)
end
$game_player.refresh

Although using this method would be pretty much the same as eventing it.. half the point is that this is bound directly to a class change.

q. How about swapping graphic with a state?
a. Check my script development for a temporary class change with state script, which is compatable with this. The SBS/ATB also both have methods for changing battler graphics during an animation, but they wont revert until the battle scene terminates (after battle). If you absolutely need something like this, please let me know.

Credit and Thanks
- Mithran
- everyone who requested something like this (there are several)

Author's Notes
Feedback is welcome. This script is about 90% tutorial, so please let me know if you have any questions.


--------------------
Go to the top of the page
 
+Quote Post
   
Kizuna
post Jun 21 2009, 02:08 PM
Post #2



Group Icon


Type: Designer




Another great and explanative script. laugh.gif Thanks so much for this Mithran, this should give me 100% completion for my transformation system and I can get on with other aspects of my game, heheh. Gonna try it out right now !

EDIT: I did everything you told me to do in the script, and it worked out perfectly! Its exactly as I imagined it, no, better! Thanks alot again! However, one little problem came up that wasn't there before, and I have no clue how it happened. huh.gif

When I'm about to level up, the game stops and I get a script error: "Script 'Level Up Display Window' line 220: NoMethodError occurred. undefined method '<' for nil:NilClass". As you can see, its BigEd781's 'Level Up Display Window' script, and I'm not sure what's causing the error...

If nothing can be done, I can just take out BigEd's script, since your set of scripts are infinitely more important to my game design.

This post has been edited by Kizuna: Jun 21 2009, 03:40 PM


--------------------
My current project is a custom transformation system for a game I'm working on. I've recently finished it! If you're interested, please click the link below!
Demon Form Transformation System
A few facts about the Demon Form Transformation System(in case you're interested or have ideas that can help):
Spoiler:
System 100% Complete!
  • It's being implemented on Tankentai SBS Improved Animated Battlers.(It makes it easier to show a wide range of actions for both Human and Demon Form sprites. Using regular Tankentai at the moment, but once all sprites are set, ready to move over to IAB at any time.)
  • Demon Form is a skill as well as a state.(The state boosts all stats by 150%. Simple, made with using the database.)
  • The state changes the character battler graphic to a different one during an animation. (Gregar from Megaman Battle Network 6 for now >_>;. And yes, I have tried common events; which have ended up only transforming your character's graphic after you've been attacked by the enemy and then reverts your character at the end of my turn. Solved with the use of Mithran's 'Class Change Graphics'!)
  • The state reduces MP by 15% each turn(reverse-regen effect created through editing the configuration script!)
  • The state changes the character's class to a different one. The reason the character's class is changed is because the class Demon has a different move set than Human does. i.e. Let's say your character is Level 70. By Level 70 Human class has all its moves already, but the Demon class has just learned Prism Crash. When the character class changes to Demon when Demon Form is active, I'd like the character to know all the moves they would up to an including Level 70 had their class originally been Demon. A combination of Mithran's 'Swap Class With State' and 'Class Change Unlearn/Inherit' has solved this problem!)
  • When MP reaches 0 and you are still in Demon Form, you revert back to Human Form automatically. Your character's battler graphic returns to normal, your class returns to human, and the state is released.(I've tried doing this with common events, they've all ended horribly, haha. Solved by Mithran's 'Conditional Autostate', 'Swap Class With State', and 'Class Change Graphics'!)
Go to the top of the page
 
+Quote Post
   
Mithran
post Jun 21 2009, 04:06 PM
Post #3


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




I highly doubt the error is in BigEd's script. Whats on line 220? I can't seem to duplicate the crash, and there was no "<" on line 220 in BigEd's script in the version that I looked at. It would help if I knew what is getting nil'd. If you can provide me with a demo link, even better.


--------------------
Go to the top of the page
 
+Quote Post
   
Kizuna
post Jun 21 2009, 04:33 PM
Post #4



Group Icon


Type: Designer




I tried removing BigEd's script(it was one from rpgrevolution, with one from here, which is a bit longer) and the error is still the same, only the line dropped down to 277 now.

here's a demo, several things are incomplete, or are there to serve my messy thinking process, so I can't really say its a demo haha.

http://www.megaupload.com/?d=PLE4P4O2




--------------------
My current project is a custom transformation system for a game I'm working on. I've recently finished it! If you're interested, please click the link below!
Demon Form Transformation System
A few facts about the Demon Form Transformation System(in case you're interested or have ideas that can help):
Spoiler:
System 100% Complete!
  • It's being implemented on Tankentai SBS Improved Animated Battlers.(It makes it easier to show a wide range of actions for both Human and Demon Form sprites. Using regular Tankentai at the moment, but once all sprites are set, ready to move over to IAB at any time.)
  • Demon Form is a skill as well as a state.(The state boosts all stats by 150%. Simple, made with using the database.)
  • The state changes the character battler graphic to a different one during an animation. (Gregar from Megaman Battle Network 6 for now >_>;. And yes, I have tried common events; which have ended up only transforming your character's graphic after you've been attacked by the enemy and then reverts your character at the end of my turn. Solved with the use of Mithran's 'Class Change Graphics'!)
  • The state reduces MP by 15% each turn(reverse-regen effect created through editing the configuration script!)
  • The state changes the character's class to a different one. The reason the character's class is changed is because the class Demon has a different move set than Human does. i.e. Let's say your character is Level 70. By Level 70 Human class has all its moves already, but the Demon class has just learned Prism Crash. When the character class changes to Demon when Demon Form is active, I'd like the character to know all the moves they would up to an including Level 70 had their class originally been Demon. A combination of Mithran's 'Swap Class With State' and 'Class Change Unlearn/Inherit' has solved this problem!)
  • When MP reaches 0 and you are still in Demon Form, you revert back to Human Form automatically. Your character's battler graphic returns to normal, your class returns to human, and the state is released.(I've tried doing this with common events, they've all ended horribly, haha. Solved by Mithran's 'Conditional Autostate', 'Swap Class With State', and 'Class Change Graphics'!)
Go to the top of the page
 
+Quote Post
   
Mithran
post Jun 21 2009, 06:34 PM
Post #5


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




An encrypted archive doesnt really help. I'll need an unencrypted version, just zip up the whole project folder and upload that. If you dont want to share your database stuff or resources (you can PM the link if you want it private), just copy the Scripts.rvdata file from the data folder and upload that so I can see your complete script layout. This script doesnt come near anything that has to do with level ups (actual code is like 20 lines long), so I'll need to examine them personally to see what the problem is.


--------------------
Go to the top of the page
 
+Quote Post
   
BigEd781
post Jun 21 2009, 09:52 PM
Post #6


No method: 'stupid_title' found for 'nil:NilClass`
Group Icon


Type: Coder
Alignment: Chaotic Good




QUOTE (Mithran @ Jun 21 2009, 09:06 AM) *
I highly doubt the error is in BigEd's script.


Thanks for the vote of confidence, but I wouldn't be so sure about that smile.gif. That script was one of my first Ruby/rpg maker scripts and I am sure that it could be refactored into something better. I am busy this weekend (GF's birthday), but if there is something I can do let me know.

BTW, nice script wink.gif

EDIT: Looking at your script, I don't immediately see where the problem is coming from either. As long a 'character_name' is never nil it should just work, but I am just guessing really.


--------------------
My blog - It's awesome, I assure you
QUOTE
While sloppy writing does not invariably mean sloppy thinking, we've generally found the correlation to be strong -- and we have no use for sloppy thinkers. If you can't yet write competently, learn to. - Eric Raymond

---
My awards for being so awesome
Spoiler:
Go to the top of the page
 
+Quote Post
   
Mithran
post Jun 22 2009, 12:08 AM
Post #7


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Character_name and face_name would never have a comparison run with the less than symbol, either. To my knolwedge, character_index or face_index never do anywhere in the base scripts and I dont see many scripters running this comparison, either. A nil in character name or face name would likely throw a line 75 in Cache "cannot convert nil into string" when it tries to get the filename + path. A nil in the index would throw a nomethod error probably when it runs the modulus in the Sprite_Character script. A non-nil non-array return would throw a nomethod error [] within the script itself (unless only the string is returned, in which case the Cache will then produce a "cannot coerce fixnum into string" when trying to get the filename and path), and a nil return is anticpated and part of the function of the script. That rules out everything I can think of caused by this specific script (and all those are configuration errors anyway, which would be immediately apparent before the graphic changed). If I had to hazard a guess, I would say that something below the script overwriting the method change_exp, destroying the instance variable assignments in Game_Actor used by the level up display window, and that it simply wasnt noticed because it was never in a situation where it was displayed.

Edit: Yep. Move up KGC_LimitBreak above the other custom scripts (right under or right below the SBS scripts). KGC_LimitBreak is a core system changer, and overwrites nearly everything it changes, including the change_exp method. As a rule of thumb, these kind of scripts get placed high on the list.

This post has been edited by Mithran: Jun 22 2009, 12:20 AM


--------------------
Go to the top of the page
 
+Quote Post
   
zedex
post Jun 25 2009, 06:26 PM
Post #8


Fear me
Group Icon


Type: Coder




so if i am right, this script makes the npc change the class of the player and while doing that..
changes its graphix also?

and umm how many class choice do we get.. or is it just a personne to change job or something like that.


--------------------
Feed my dragons please, by clicking on them.
Spoiler:








Go to the top of the page
 
+Quote Post
   
Mithran
post Jun 25 2009, 07:58 PM
Post #9


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




This is not a class changer script. This is an addon to a class change system (it should work with any system that does not go out of its way to break the default code, and if it does, tell me and I'll write you a patch), be it evented or scripted. Whenever a character changes class, the script checks and see if a new graphic should be assocaited with them, then changes it over. As I explained in the intro and the script itself, when working with evented class change systems, this is relatively simple (just have them change graphcis when you do an evented class change). If you are using a scripted class change system, however, eventing something like this would mean relatively large events filled with conditional branches and constant checking through a parallel process. Plus, this includes detailed explainations on how to set up your case or if structures to get it to change to the right graphic under the right conditions, so it should be simple enough for even a non-scripter to use.


--------------------
Go to the top of the page
 
+Quote Post
   
jackrmesser
post Oct 9 2009, 08:33 PM
Post #10



Group Icon






any chance of a demo?


--------------------
You've changed.
You've missed a few things.
Well I wanna hear it all from the start
Well it all started when I saw this sphere of you.
dramatic music FTW!
Go to the top of the page
 
+Quote Post
   
Scathe
post Oct 9 2009, 09:48 PM
Post #11


Gettin' the hang of chillin' on a pole...
Group Icon


Type: Artist




This is a great script for me, b/c my game has 6 classes to run around with ^^


--------------------

My Shop
Spoiler:


CODE
[url=http://www.rpgmakervx.net/index.php?showtopic=22317][IMG]http://i347.photobucket.com/albums/p466/nightsnipe11/ShopUserbar.png[/IMG][/url]
CODE
[url=http://www.rpgmakervx.net/index.php?showtopic=22317][IMG]http://i588.photobucket.com/albums/ss324/Elaynii/Graphics/ElayniiUserbar.png[/IMG][/url]


My Tutorials


My Random Stuff
Spoiler:


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: 22nd September 2014 - 11:19 AM

RPGMakerVX.net is an Privacy Policy, Legal.