Announcement

Collapse
No announcement yet.

Weapon Skills: A Scripting Guide

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Weapon Skills: A Scripting Guide

    This thread contains the basic setup you need to create Skills that can only be used while a character is holding a certain type of Weapon.

    As I was setting up a "Weapon Skills" system in my own game today, I realized that the Ruby modifications I needed to make were relatively simple, and could actually translate well to anyone's RPG, so I figured I'd share.

    With a "Weapon Skills" system, your characters can slice through monsters with swords, pepper them with arrows, or crush foes with hammers... and you'll never have to worry about your player wondering why a character he just equipped with a sword can use "Hammer Smash"!

    This system will allow any character who equips a weapon of a certain type (or even a specific weapon) to use the Skills that come with it, a la Disgaea or Phantom Brave. If you want to do something more complicated, like make level/skill requirements or have the character learn the skill permanently if she uses it enough (a la FF9), that can be done, but it is beyond the scope of this post.

    If you guys have any questions or can't get it to work, feel free to ask here.


    ===


    Here's how to do it!:

    1) Before you start, open up the Database to the "Actors" tab and remove everyone's starting weapon. (Or, if it's important to you to start some characters with equipment, that's okay - but make sure they also start the game with the skills they should know based on their starting Weapon; you can do this on the "Classes" tab).

    2) Open up the Script Editor and find the "Game_Actor" class.

    3) Find the "Change Equipment" method. It starts with the line: def equip(equip_type, id)

    4) Directly before the first "end" command in this method, add a new line and type weapon_skills or whatever you'd like to name the new Weapon Skills method you're about to create.

    5) Directly before the last "end" command in the entire "Game_Actor" class, add your new method using the following code. If you called your method something besides weapon_skills in step 4, replace the blue method name with whatever you called it.

    def weapon_skills
    forget_skill(200)
    forget_skill(201)
    forget_skill(202)
    forget_skill(203)
    forget_skill(204)
    forget_skill(205)
    if @weapon_id > 0
    if ($data_weapons[@weapon_id].icon_name == '001-Weapon01')
    learn_skill(200)
    learn_skill(201)
    end
    if ($data_weapons[@weapon_id].icon_name == '005-Weapon05')
    learn_skill(202)
    learn_skill(203)
    end
    if ($data_weapons[@weapon_id].icon_name == '008-Weapon08')
    learn_skill(204)
    learn_skill(205)
    end
    end
    end

    6) See those orange numbers and green icon names in the script above? You'll probably need to change those in your own game.
    • Change the green icon names to the name of the icon that the weapon type uses. For instance, above, 001-Weapon01 is the name of RPG Maker XP's default Sword Icon. You can find this information in the Database or Material Base. Make sure you get the name exactly right!
    • Change the orange numbers to the ID of skills that you want to come with a type of weapon. For instance, 200 and 201 are the IDs of Sword skills (represented by the icon 001-Weapon01), whereas 204 and 202 and 203 are bow-and-arrow skills (represented by the icon 005-Weapon05). You can find this in the Database.

    7) Make sure that all weapons of the same type use the same icon. All of your Swords should use the same icon if you want them to teach the same skills (and it should be the one you associated the Sword skills to above). All of your Bows should use the same icon if you want them to teach the same skills. And so on. One of the nice things about this system is that you can have dozens of different swords, and you don't need to do separate coding for each of them - just give them all the same icon and they'll all come with Sword skills!


    You're done! Enjoy the new feature in your game.


    ===



    Making it Your Own:



    If you want to add more than three weapon types, here's how: copy that entire stanza that's in pink, above, and paste it below itself. Choose a different icon name and different skills. Now you have four weapon types! Rinse and repeat. Don't forget to add extra "forget_skill" lines for fourth weapon type's skills. (If you want to add extra skills to a weapon type, just add the appropriate "learn_skill" and "forget_skill" lines in the appropriate places.)


    And finally, if you want to have specific weapons that teach a skill, rather than an entire type of weapon, use code like this:
    if @weapon_id == 154
    learn_skill(202)
    learn_skill(203)
    end
    where the green number is the ID of the weapon that comes with the skills (you can find this in the database), rather than code like this:
    if ($data_weapons[@weapon_id].icon_name == '005-Weapon05')
    learn_skill(202)
    learn_skill(203)
    end
    Everything else about the code should remain the same.
    Last edited by Wavelength; 01-01-2013, 02:20 PM.


    How Badly Do You Want It? (VX Ace) is now available for download! - no outside software necessary.

    "I live and love in God's peculiar light." - Michelangelo

    #2
    Re: Weapon Skills

    I did something like this, Only I used the armor and accessory slots instead.


    "You're dead if you aim only for kids. Adults are only kids grown up, anyway."
    -Walt Disney

    Comment


      #3
      Re: Weapon Skills

      Yup, this could be done with armor/accessories, too, by moving the weapon_skills call line to a different part of the Change Equipment method, and making the "usual suspects" changes, such as @weapon_id and $data_weapons (I haven't checked but it's probably @armor_id and $data_armor).

      And a similar system could even be implemented through Eventing, which is how I'm guessing you did it, Deeth, but there are a few major advantages to coding it (as above) instead:
      • It's highly scalable: add lots of new weapons and you don't need to do any extra work to make them work with this system
      • It's more stable: if you think through the logic correctly, no weird interactions will happen if you try to add/remove skills for other reasons during a battle, and bugs are less likely to occur
      • It's instant: the second you equip a weapon, you have the skill
      • It's simply easier: I imagine you need to create events either in every enemy troop or on every map if you want to do this via Eventing; coding it lets you make the changes in basically one place

      I continue to do some complicated, self-contained events (like minigames) in the Eventing system. With some creativity, no doubt you can do wonderful things with it. I love what Ryner did with it, I love what you did with it... heck, I love what I did with it before I started working with code.

      But for game-wide systems, I really feel it's well worth learning the Ruby syntax and getting comfortable with the way the classes work with each other. Because at best, Eventing something like this will create a cool system that takes you ten times as long and produces occasional bugs.
      Last edited by Wavelength; 11-29-2012, 04:28 PM.


      How Badly Do You Want It? (VX Ace) is now available for download! - no outside software necessary.

      "I live and love in God's peculiar light." - Michelangelo

      Comment


        #4
        Re: Weapon Skills

        I used the Common Events, since those are shared across all maps.

        Furthermore, my system had an additional system for leveling:

        Every time a spell in a certain "class" is cast, a counter is increased for that spell's "class", and when a limit is reached, an additional spell is added to the list every time the armor is equipped.


        "You're dead if you aim only for kids. Adults are only kids grown up, anyway."
        -Walt Disney

        Comment


          #5
          Re: Weapon Skills

          Awesome! I actually HAVE RMXP...I want to start using it soon!

          I definitely want to try to do something like this.

          Comment

          Working...
          X