Working on adding my own special skills for a game in RPG Maker, and I thought it may be good to add what ive done for the EXP/Level of special skills (such as mining, woodcutting and smithing; which is also the default). This just stores EXP, as levels are not really needed to be stored and just need a function to properly convert them (later will be updated with the levels functions; so that levels can be calculated and with similar difficulty options as RPG Maker). I am no genius, nor master, at Javascript- so please point out any error or problems.
First thing required in order to run the skills is to initialize it. I left this freely open so that they can be reinitialized at will (clear and reset). Simply call the plugin command
, and it sets it up for you. Skills themselves are setup manually in the Plugins Manager, which are held in a list of a struct. Skills hold only Name, EXP, Level, and LevelRate. level/rate are not used yet, but soon to be. I left the "$gameSystem.playerSkills[]" list to be keyed by the skill's 'name.toLowerCase()" for being easier to grab and hard to mess up (Example:
All the base functions are added straight to $gameSystem with a simple numonic of [action][PlayerSkills][Extra], so it will be hard to clash with anything and is simpler to remember. And example is [get][PlayerSkills][EXP], which specifically will return the numerical value of the desired skill- if possible. I don't know if people prefer alerts over console.log or simple gameMessage; but my error reporting is sticking with console.log for now and in the future will return default skill object with the name "error" and "-1" for numerical values. I tried to create a method to grab event id to make it easier to debug, but the attempts failed (still on my first 2 weeks of RPG Maker MV).
update v0.1.3:
levels are VERY linear. I am not the best at math and could not figure out how to turn the information I gathered into recreated the method that RP Maker uses in Parameter Curves. If you have a suggestion on a change for that, please tell.
First thing required in order to run the skills is to initialize it. I left this freely open so that they can be reinitialized at will (clear and reset). Simply call the plugin command
Code:
"playerSkills initialize"
Code:
$gameSystem.playerSkills["mining"] == String("MiNinG").toLowerCase()
All the base functions are added straight to $gameSystem with a simple numonic of [action][PlayerSkills][Extra], so it will be hard to clash with anything and is simpler to remember. And example is [get][PlayerSkills][EXP], which specifically will return the numerical value of the desired skill- if possible. I don't know if people prefer alerts over console.log or simple gameMessage; but my error reporting is sticking with console.log for now and in the future will return default skill object with the name "error" and "-1" for numerical values. I tried to create a method to grab event id to make it easier to debug, but the attempts failed (still on my first 2 weeks of RPG Maker MV).
update v0.1.3:
- Added levels and recalculating levels
- Levels are simple calculations of [baseEXP] x ([level ^ levelRate)]
- levelRate is added to Skills. This defines how hard of a change there is in required exp per level.
- levelRate represents how much exp is available for said skill. More abundant resource of exp for said skill should require a much higher levelRate to make skills advance at a more similar or difficult rate. levelRate is suggested, but not required, to be between 1.00 and 2.00
- added cheap square root function at bottom to make things slightly more easier to read.
- baseEXP defines the base level of how much exp is required and there is. higher number equals more exp required per level.
PHP:
//=============================================================================
// Extra Player Skills v0.1.3
//=============================================================================
/*~struct~Skill:
* @param name
* @type text
* @default mining
*
* @param level
* @type number
* @default 1
*
* @param exp
* @type number
* @default 1
*
* @param levelRate
* @type number
* @default 1
*
* @param baseEXP
* @type number
* @default 1000
*/
/*:
* @plugindesc Background Skill Data
* @author GrimOfDoom
* @help Provides extra skill information for any use
*
* @param playerSkills
* @type struct<Skill>[]
* @desc Player Skills are located here :D
*/
(function() {
var params = PluginManager.parameters("Skills");
//====================================================Script Commands, need to be redone to support more features
var PlayerSkills_interpreter = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
PlayerSkills_interpreter.call(this, command, args);
if(command === "playerSkills"){
switch(args[0]){
case 'add':
$gameSystem.addPlayerSkillEXP(args[1], args[2]);
break;
case 'get':
$gameMessage.getPlayerSkillEXP(args[1]);
break;
case 'read':
$gameSystem.readPlayerSkillEXP(args[1]);
break;
case 'readLevel':
$gameSystem.readPlayerSkillLevel(args[1]);
break;
case 'initialize':
$gameSystem.initializePlayerSkills();
break;
case 'recalc':
$gameSystem.recalcPlayerSkillLevel(args[1]);
break;
default:
console.log(args[1] + " is not a playerSkill command")
break;
}
}
};
//=================================================================Functions used by Commands
Game_System.prototype.addPlayerSkillEXP = function (skill, exp){
skill = prepareString(skill);
exp = Number(exp);
if (this.playerSkills[skill] === undefined){
console.log( skill + " cannot be found");
} else {
this.playerSkills[skill].exp += exp;
this.recalcPlayerSkillLevel(skill);
}
}
Game_System.prototype.getPlayerSkill = function(skill){
skill = prepareString(skill);
if (this.playerSkills[skill] === undefined){
console.log( skill + " cannot be found");
} else {
return this.playerSkills[skill];
}
}
Game_System.prototype.readPlayerSkillEXP = function(skill){
$gameMessage.add(skill + " has " + this.getPlayerSkill(skill).exp + " exp");
}
Game_System.prototype.getPlayerSkillEXP = function(skill){
skill = prepareString(skill);
var fSkill = this.getPlayerSkill(skill);
return fSkill.exp;
}
Game_System.prototype.addPlayerSkillLevel = function(skill, level){
skill = prepareString(skill);
level = Number(level);
if (this.playerSkills[skill] === undefined){
console.log(skill + " does not exist in playerSkills");
} else {
this.playerSkills[skill].level += level;
}
}
Game_System.prototype.getPlayerSkillLevel = function(skill){
skill = prepareString(skill);
if (this.playerSkills[skill] === undefined){
console.log(skill + " does not exist in playerSkills");
} else {
return this.playerSkills[skill].level;
}
}
Game_System.prototype.setPlayerSkillLevel = function(skill, level){
skill = prepareString(skill);
if (this.playerSkills[skill] === undefined){
console.log(skill + " does not exist in playerSkills");
} else {
this.playerSkills[skill].level = level;
}
}
Game_System.prototype.readPlayerSkillLevel = function (skill){
skill = prepareString(skill);
if (this.playerSkills[skill] === undefined){
console.log(skill + " does not exist in playerSkills");
} else {
$gameMessage.add(skill + " is at level " + this.playerSkills[skill].level);
}
}
Game_System.prototype.initializePlayerSkills = function(){
this.playerSkills = {};
var skillList = JSON.parse(params["playerSkills"]);
for (skill in skillList){
newSkill = JSON.parse(skillList[skill]);
newSkill.name = prepareString(newSkill.name);
newSkill.exp = Number(newSkill.exp);
newSkill.level = Number(newSkill.level);
newSkill.levelRate = Number(newSkill.levelRate);
newSkill.baseEXP = Number(newSkill.baseEXP);
this.playerSkills[newSkill.name] = newSkill;
}
}
Game_System.prototype.recalcPlayerSkillLevel = function (skill){
var fSkill = this.getPlayerSkill(skill);
this.setPlayerSkillLevel(skill,Math.round(squirt((fSkill.exp / fSkill.baseEXP), fSkill.levelRate)));
}
//====================================================================Side helpful functions
prepareString = function(message){
message = String(message)
message = message.toLowerCase();
return message;
}
squirt = function(g, n) {
return Math.pow(g, 1/n );
}
})();
levels are VERY linear. I am not the best at math and could not figure out how to turn the information I gathered into recreated the method that RP Maker uses in Parameter Curves. If you have a suggestion on a change for that, please tell.