Class change when equip weapon type.

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
264
First Language
English
WeaponClassChange.js v1.0
Jeremy Cannady

Introduction
Changes your class when you equip a different weapon. Your exp is saved so when you reequip you go back to your old level. The class must be-able to equip the weapon.

Download

http://pastebin.com/uah4Ek1i


Screenshots
 This does not apply to all scripts, specially to those which don't have any visual effect.

How to Use
Give instructions on how to install and use the script. Also, make sure that you include the instructions in the script header(together with the version number and your name) so that the user can consult it when needed).

Demo
Don't have a demo at the moment.

Script
Make sure that you place your script using the code feature, do not use quotes. Again, if spoiler tag is available in the future then use the spoiler tag together with the code tag.

//=============================================================================// WeaponClassChange.js//=============================================================================/*: * @plugindesc Changes class when actor equips a different weapon type. * @author Jeremy Cannady * * @param Weapon Types * @desc List the weapon types. * @default 1,2,3,4,5,6,7,8,9,10 * * @param Classes * @desc List the classes. * @default 1,2,3,4,5,6,7,8,9,10 * * @param Unequipped Class * @desc The is the class you want to be when you dont have a weapon equipped. * @default 1 * Example one: * Weapon Type : 1,2,3,4,5,6,7,8,9,10 * | | | | | | | | | | * Class: 1,2,3,4,5,6,7,8,9,10 * When you equip weapon type one your class changes to class #1 in your database. * When you equip weapon type 5 your class changes to class #5 in your database. * * Example two: * Weapon Type: 1,2,3,4,5,6,7,8,9,10 * | | | | | | | | | | * Class: 1,2,8,4,5,6,7,8,9,10 * When you equip weapon type three or eight your class changes to class #8 in your database. * * @help The parameter order determines the class change.Classes 1,2,3,4,5,6,7,8,9,10 *For example when you equip weapon type 1 then your class changes to class 1.Classes 2,2,3,4,5,6,7,8,9,10 *In this example when you equip weapon type 1 then your class changes to class 2. *Please see script text for a simple graphic. * * **/(function() {//Retrieve the parametersvar parameters = PluginManager.parameters('WeaponClassChange');var weaponType = parameters['Weapon Types']; var classes = parameters['Classes'];var defaultClass = Number(parameters['Unequipped Class']);//Store the parameters into an string array and get rid of the commasvar weaponTypeArray = weaponType.split(',');var classesArray = classes.split(',');//Convert the parameters into number arrayfor(var i=0; i<weaponTypeArray.length; i++) { weaponTypeArray = parseInt(weaponTypeArray, 10); } for(var i=0; i<classesArray.length; i++) { classesArray = parseInt(classesArray, 10); } //Lets make a copy of Game_Actor.prototype.setup so we can add to itvar Game_Actor_setup = Game_Actor.prototype.setup;Game_Actor.prototype.setup = function(actorId) {Game_Actor_setup.call(this,actorId);this._classExp = [];var length = $dataClasses.lengthfor(var i = 0; i<length;i++){//Sets the default value for each class starting exp to 0this._classExp.push(0); };}//This function compares which weapon type you have equipped and gives you the class that corresponds to it.Game_Actor.prototype.getNewClassId = function(){var wtypeId = this.weapons()[0] ? this.weapons()[0].wtypeId : 0;//Takes the position of the weapon parameter and makes newClassId equal to the the parameter that is in the same position as the weapon type.var newClassId = classesArray[weaponTypeArray.indexOf(wtypeId)];//If the actor has unequipped a weapon then make the newClassId into the 'Unequipped Class' in the parameters.if($gameActors.actor(this.actor().id).hasNoWeapons()){newClassId = defaultClass;};//When we call this function then return what our class should be based upon which wepaon we have equippedreturn newClassId;}; //Make a copy of changeEquip so we can edit itvar copyOfChangeEquip = Game_Actor.prototype.changeEquip;//Overide Game_Actor.prototype.changeEquipGame_Actor.prototype.changeEquip = function(slotId, item) {//When we change our equipment then do what we used to do in the origial Game_Actor.prototype.changeEquipcopyOfChangeEquip.call(this,slotId,item);//but also do thisthis.changeToNewClass(this.actor().id);};Game_Actor.prototype.changeToNewClass = function(currentActor){//When we call the function changeToNewClass then do these things.//Current Actor IDvar actor = $gameActors.actor(currentActor);//Current Class Idvar currentClassId = actor.currentClass().id;var newClassId = actor.getNewClassId();//Current Expvar currentExp = actor.currentExp();//Put the curent exp back in to the arrayactor._classExp[currentClassId] = currentExp;//Change the classactor.changeClass(newClassId, false);//Change the exp to the correct valuevar newExp = actor._classExp[newClassId];actor.changeExp(newExp,false)//Forget old skillsactor._skills.forEach(function(skill){ var index = actor._skills.indexOf(skill); if (index >= 0) { actor._skills.splice(index, 1);};}, actor);//Learn new skillsactor.currentClass().learnings.forEach(function(learning) { if (learning.level <= actor._level) { actor.learnSkill(learning.skillId); } }, actor);}; })();/*:CreditsArcherBanish ---> http://forums.rpgmakerweb.com/index.php?/topic/47747-custom-class-change-v100/?hl=classchange//I used his code for forgetting and learning new skillsYoji Ojima//I used the plugin TitleCommand Position to learn how to operate the parameters*/ 


Credit and Thanks
- Jeremy Cannady
ArcherBanish ---> http://forums.rpgmakerweb.com/index.php?/topic/47747-custom-class-change-v100/?hl=classchange
I used his code for forgetting and learning new skills

Yoji Ojima
I used the plugin TitleCommand Position to learn how to operate the parameters

Author's Notes
This is optional
 
Last edited by a moderator:

kranasAngel

Wanderer
Veteran
Joined
May 9, 2014
Messages
128
Reaction score
47
First Language
English
Primarily Uses
RMMV
Great script, and exactly what I wanted. Quick question though, is there any way to make this work based off of shields rather than weapons?
 

kranasAngel

Wanderer
Veteran
Joined
May 9, 2014
Messages
128
Reaction score
47
First Language
English
Primarily Uses
RMMV
Just the shield.

Thanks for the help.
 

xein

A stranger in a strange world
Veteran
Joined
Mar 17, 2012
Messages
306
Reaction score
15
Primarily Uses
Thanks. I was just going to request this.
 

John41617

Warper
Member
Joined
Oct 30, 2015
Messages
3
Reaction score
0
First Language
English
Is there anything that needs to be changed on this (aside from adjusting the values in the plugin section of RMMV to allow the weapon types to know which class to switch to) at the script level? It seems like it should be just plug and play, but it isn't working for me. When I have my characters equip a different weapon type (any and all weapon types), their class doesn't change. I'm using Yanfly's core engine script, so perhaps it's conflicting with that? Any advice would be extremely helpful. Thanks.
 

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
264
First Language
English
Ok so the initial set up is a little bit complicated. The weapon types in your game need to be listed out in order that they are in your game , then your list of classes need to be the same length. There should be nothing at the script level. Make sure all classes can use any weapon type or you wont be able to switch back. For example your mage classs needs a staff equipped then, well if the mage class can't equip staffs then you will lose the weapon and revert back. If you press F8 during test play it will bring up a console, If there are any errors it will pop up there.
 

xein

A stranger in a strange world
Veteran
Joined
Mar 17, 2012
Messages
306
Reaction score
15
Primarily Uses
Basically, to change to any class the class needs to be able to equip any weapon.

Example:

Let's say a warrior can change to a mage or archer.

The class warrior must have the weapon type staff (mage) and bow (archer) and sword (warrior).

Whenever the player equips a weapon type staff (short staff,long staff, horn staff, etc) the actor changes to a mage.

To change back to a warrior, the class mage must have the weapon type sword.

Is this right?

Haven't tested yet.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Humans are fallible creatures, we all know that. It's when we're forced to look at ourselves that we start to disagree. :p
Expectation: Working on boss battle.
Reality: "Look at how awful are these code and database organization. Let me clean this mess", *yet, casually adding more modules that I have no idea if I would use it later*
Trying to learn to read Japanese so I read my manga. I like to buy them without all the edits made during translation.
The only thing getting me through today so far is coffee. And lots of it.
Amazing. I had seen it more than 10 years ago, but seeing Monster this year was an incredible experience. It was certainly one of the best endings I've ever seen in anime.

Forum statistics

Threads
97,851
Messages
947,380
Members
129,078
Latest member
onpeex
Top