Skip to content

Instantly share code, notes, and snippets.

@Dromarch
Created August 6, 2021 07:16
Show Gist options
  • Save Dromarch/9e8a92174da3957e12e64ca79b8fdb8b to your computer and use it in GitHub Desktop.
Save Dromarch/9e8a92174da3957e12e64ca79b8fdb8b to your computer and use it in GitHub Desktop.
A very simple actor points system plugin for RPG Maker MZ.
/*:
* @target MZ
* @plugindesc Simple actor points system.
* @author Gabe (Gabriel Nascimento)
* @url https://www.patreon.com/gabriel_nfd
*
* @help rmmz-actor-points-system.js
* - A very simple actor points system.
*
* Script Calls:
* $gameActors.actor(actorId).points();
* | actorId : The Actor ID in database
* | This call returns the specified actor current points amount.
*
* $gameActors.actor(actorId).pointsPerLevel();
* | actorId : The Actor ID in database
* | This call returns the specified actor points per level amount.
*
* $gameActors.actor(actorId).maxPoints();
* | actorId : The Actor ID in database
* | This call returns the specified actor max points amount.
*
* Actor Note Tags:
* <maxPoints: amount>
* | amount : The max points amount the actor can have.
* | This tag changes the max points amount the actor can have.
*
* <pointsPerLevel: amount>
* | amount : The amount of points the actor earns on level up.
* | This tag changes the amount of points the actor earns
* | per level.
*
* Plugin Commands:
* Increase Actor Points
* | This command increase the points amount from the specified actor.
*
* Decrease Actor Points
* | This command decrease the points amount from the specified actor.
*
* Change Actor Points
* | This command change the points amount from the specified actor.
*
* Change Actor Max Points
* | This command change the max points amount the specified actor can
* | gain.
*
* Change Actor Points Per Level
* | This command change the amount of points the specified actor earns
* | per level.
*
* @param Default Settings
*
* @param defaultPointsPerLevel
* @text Default Points Per Level
* @desc The default amount of points an actor earns on level up.
* @type number
* @default 5
* @parent Default Settings
*
* @param defaultMaxPoints
* @text Default Max Points
* @desc The default max points amount an actor can have.
* @type number
* @default 99
* @parent Default Settings
*
* @command increasePoints
* @text Increase Actor Points
* @desc Increase the actor points amount.
*
* @arg actor
* @text Actor
* @desc The actor to gain points.
* @type actor
* @default 1
*
* @arg amount
* @text Amount
* @desc The points amount to increase.
* @type number
* @default 0
*
* @command decreasePoints
* @text Decrease Actor Points
* @desc Decrease the actor points amount.
*
* @arg actor
* @text Actor
* @desc The actor to lose points.
* @type actor
* @default 1
*
* @arg amount
* @text Amount
* @desc The points amount to decrease.
* @type number
* @default 0
*
* @command changePoints
* @text Change Actor Points
* @desc Change the actor points amount.
*
* @arg actor
* @text Actor
* @desc The actor to change points.
* @type actor
* @default 1
*
* @arg amount
* @text Amount
* @desc The points amount to change.
* @type number
* @default 0
*
* @command changeMaxPoints
* @text Change Actor Max Points
* @desc Change the max points amount the actor can gain.
*
* @arg actor
* @text Actor
* @desc The actor to change the max points.
* @type actor
* @default 1
*
* @arg amount
* @text Amount
* @desc The max points amount.
* @type number
* @default 0
*
* @command changePointsPerLevel
* @text Change Actor Points Per Level
* @desc Change the amount of points the actor earns per level.
*
* @arg actor
* @text Actor
* @desc The actor to change the points gains per level.
* @type actor
* @default 1
*
* @arg amount
* @text Amount
* @desc The amount of points per level.
* @type number
* @default 0
*/
(() => {
const pluginName = "rmmz-actor-points-system";
const params = PluginManager.parameters(pluginName);
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
PluginManager.registerCommand(pluginName, "increasePoints", args => {
const actorId = parseInt(args.actor);
const amount = parseInt(args.amount);
$gameActors.actor(actorId).gainPoints(amount);
});
PluginManager.registerCommand(pluginName, "decreasePoints", args => {
const actorId = parseInt(args.actor);
const amount = parseInt(args.amount);
$gameActors.actor(actorId).gainPoints(-amount);
});
PluginManager.registerCommand(pluginName, "changePoints", args => {
const actorId = parseInt(args.actor);
const amount = parseInt(args.amount);
$gameActors.actor(actorId).changePoints(amount);
});
PluginManager.registerCommand(pluginName, "changeMaxPoints", args => {
const actorId = parseInt(args.actor);
const amount = parseInt(args.amount);
$gameActors.actor(actorId).changeMaxPoints(amount);
});
PluginManager.registerCommand(pluginName, "changePointsPerLevel", args => {
const actorId = parseInt(args.actor);
const amount = parseInt(args.amount);
$gameActors.actor(actorId).changePointsPerLevel(amount);
});
//-----------------------------------------------------------------------------
// Game_Actor
//
// The game object class for an actor.
const _Game_Actor_initMembers = Game_Actor.prototype.initMembers
Game_Actor.prototype.initMembers = function() {
_Game_Actor_initMembers.call(this);
this._points = 0;
this._maxPoints = 0;
this._pointsPerLevel = 0;
};
const _Game_Actor_setup = Game_Actor.prototype.setup
Game_Actor.prototype.setup = function() {
_Game_Actor_setup.call(this, ...arguments);
this._maxPoints = parseInt(this.actor().meta.maxPoints) || parseInt(params.defaultMaxPoints);
this._pointsPerLevel = parseInt(this.actor().meta.pointsPerLevel) || parseInt(params.defaultPointsPerLevel);
};
Game_Actor.prototype.points = function() {
return this._points;
};
Game_Actor.prototype.maxPoints = function() {
return this._maxPoints;
};
Game_Actor.prototype.pointsPerLevel = function() {
return this._pointsPerLevel;
};
Game_Actor.prototype.gainPoints = function(value) {
this.changePoints(this.points() + value);
};
Game_Actor.prototype.changePoints = function(value) {
this._points = value.clamp(0, this.maxPoints());
};
Game_Actor.prototype.changeMaxPoints = function(value) {
this._maxPoints = value;
};
Game_Actor.prototype.changePointsPerLevel = function(value) {
this._pointsPerLevel = value;
};
const _Game_Actor_levelUp = Game_Actor.prototype.levelUp;
Game_Actor.prototype.levelUp = function() {
_Game_Actor_levelUp.call(this);
this.gainPoints(this.pointsPerLevel());
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment