SGS Stats - Additional stats for Actors and Enemies

Given the huge amount of plugins already made i thought i wouldn't need to write my own plugins for the game i'm making. But it seems for one thing no plugin existed, that i could use.


What does this plugin do?


This plugin enables you to add additional stats to your actors and enemies. You define the stats by configuring a list of names in the plugin parameters. Afterwards you can use notetags to set these stats to values and even use simple property-acess to use these in damage formulas.


There is also a default-parameter, so you don't have to use notetags on every actor or enemy.


Usage


Assuming you have the names-parameter of the plugin set to "strength, willpower" - Note that these names are case-sensitive and must be full words (no spaces)


Now you will have two additional stats, strength and willpower. Actors, classes, states, weapons, armor and enemies can now hold values for these stats using a simple notetag:

Code:
<SGS Stat: strength=10>
<SGS Stat: willpower=5>

This would set the strength to 10 and the willpower to 5.


To use these stats you can use a simple JavaScript function:


a.sgsStat('strength')


For enemies their stat (what gets returned by the property) is modified by their own notetag and the stat of all affecting states.


For Actors the stat is in addition to that also influenced by his class and his current equipment.


To change the stat of an actor or enemy you can use a javascript function:


a.incSGSStat('strength', 20);


This would increase the strength of actor/enemy 'a' by 20. Usage of negative values allow decreasing the stat.


The exact way to calculate the stat can now be configured in the plugin-parameters. There is now also a notetag to set a simple static stat-increase when an actor levels up.


These stats are also already part of the save-game.


Current Limitation:


As this plugin is a work in progress not everything you would like to do is possible. What is mentioned under usage is everything that is currently implemented. That means in particular the following features aren't implemented (but might be in the future):

  • Setting a level-based stat-increase via class-notetag. Included in v0.3.
  • Changing the stat-value of a class, weapon or armor. Won't be added, as these are static database-objects. If required this can be achieved using the advanced notetags
  • Easily changing the stat via skill or item with notetags. (Currently only possible with other plugins that allow custom javascript execution for skills and item-effect)
  • There is also no display of these stats anywhere in the menu.
  • There is no upper or lower limit on these stats



Still i think it is already useable. If you find any bugs or have suggestions for future features, please let me know.


Known Bugs:


  • Changing the equipment on an actor will crash the game (Reason)



Plans for v1.0

  • Notetag to change Stat via Item/Skill
  • Level based increase on class (v0.3)
  • Parameter formula to calculate stat (v0.3)
  • Rate-Notetag for every State, Skill, Item, Equipment, Class
  •  Advanced (JavaScript) Notetag for every basic notetag (v0.4)
  • Upper and lower limit for stats
  • Change stats on classes and equipment like currently for battlers



Changelog:


v0.4

  • Added advanced notetag for base value
  • Added advanced notetag for per level value
  • Added a javascript method to set the plus-value of a stat (to reset all incStat-calls f.ex.)
  • Refactored under the hood, to make extensions easier

v0.3

  • Removed the property-access way. This should also remove the 'can not redefine property'-error
  • Renamed the getter-Function to something smaller and simpler
  • Added a notetag to increase stats when leveling up an actor
  • Added parameters to define the actual formula used to calculate a stat

    It is possible to use a different formula for enemies


v0.2.1

  • Fixed an error when defining several stats with spaces around the stat.

v0.2

  • Initial release



License:


Free for all games in MV (free and commercial). Credit to MagicMagor must be given inside the game or a credits-file. Modification to the script is allowed, but the modified script can not be distributed. Distributing the script via the game, that uses it is the only exception for this.


As the script is WIP no guarentee is made against errors this plugin might produce or that it will stay compatible to future versions.


Download (v0.4):
Dropbox
Found a bug I think...When using just one stat (I.E. Prowess) I can input this.Prowess and it works perfectly in Yanfly's Base Parameter Control and shows the changes to the stat in all menus. However, when I add a second (or more) it creates an error. For example, if I enter "Prowess, Alacrity" it gives an undefined error, if I list them like this "Prowess,Alacrity" (no space) it doesn't give an error, but, it also doesn't work (the stat, in this case, ATK, stays the same and does not add the bonus from Prowess (I haven't input Alacrity into the formulas yet)
Thanks for finding these bugs. The error when having a space around the name was easily fixed, but it seems the property-definition isn't working like i thought, which breaks everything when more than one stat is defined (it will always return the last defined stat for all properties). That might take some time to fix.


Instead try the javascript function:


actor.getSGSStat(name);
// For example (if you have strength defined):
this.getSGSStat('strength');


That shoud still work until i can fix the property-definition.
Cool, thanks. The above works well for me, however getting a random error message that doesn't always happen (probably based on the definition problem you mentioned).  It randomly (as in sometimes it works and doesn't show the error, and sometimes it doesn't and shows the following error) shows TypeError Cannot redefine property: (whatever is the first property). 

TypeError: Cannot redefine property: Health
    at Function.defineProperty (native)
    at Object.SGS.Stats.defineStats (file:///J:/Game/True%20Power/js/plugins/SGS_Stats.js:89:10)
    at Function.DataManager.isDatabaseLoaded (file:///J:/Game/True%20Power/js/plugins/SGS_Stats.js:172:16)
    at Scene_Boot.isReady (file:///J:/Game/True%20Power/js/rpg_scenes.js:183:28)
    at Function.SceneManager.updateScene (file:///J:/Game/True%20Power/js/rpg_managers.js:1667:48)
    at Function.SceneManager.updateMain (file:///J:/Game/True%20Power/js/rpg_managers.js:1641:10)
    at Function.SceneManager.update (file:///J:/Game/True%20Power/js/rpg_managers.js:1576:14)

Thanks for looking into this for me, can't wait until this plugin is up and running (its exactly what I need)! Haven't really been able to actual start my game without getting a system to run, and this even in its pre-release has provided me with enough tools to actually, finally, progress 😀  

Update: Actually, this error gets even weirder. I just realized that the error is not random like I originally thought. Instead, if I save the project, it works twice before showing the error again. Then, the error repeats indefinitely until I save the project again. Rinse and Repeat. 
Just updated to version 0.3.


After some googeling i found out, that the simple property-way i envisioned isn't possible with the javascript-version used by RPG-Maker MV. I thought i could define dynamic properties, but apparently that is not possible in ES5. Therefore i have removed the whole property-stuff, now the getter-function has to be used. But the function has a smaller more simpler name.


I also added some new features:

  • A notetag to define stat-increases when leveling up
  • Formula-Parameter to define how the stats are calculated. Can be seperate for actor/enemy

Information on how to use these new features can be found in the plugin-help.
Awesome!
I reworked the plugin internally quite a bit. Nothing that is visible to the user, but makes maintaining it a lot easier.


For the end-user i've added two advanced notetags. The base-value and the per-level value can now also be defined dynamicly with javascript.


// Base value
<SGS Stat: strenght>
value = item.level * 5;
</SGS Stat>

// Per Level value
<SGS Stat Level: strength>
value = item.level;
</SGS Stat Level>


The variable value is the one that has to be changed. The normal-notetags can still be used in conjunction with the advanced tags. The normal tag then defines the initial value of value, before the advanced notetag is evaluated. The variable item is a reference to the database-object (Game_Actor, Game_Enemy etc..), depending on where the advanced notetag is placed.


Also there is a set-method for the stat-value.


battler.setSGSStat(name, value);


This will set the plus-value of the stat. This changes the same internal value as the incSGSStat-method. It does not change the base-value. It's mainly meant to reset a stat that was changed via incSGSStat-calls.


Also i've cut some planned features from the v1.0-goal. Mainly the skill/item-notetag as i currently have no idea how these objects work internally and so i have no idea which method to override. Also these effects are currently possible when using additional plugins that allow executing custom javascript for an item- or skill-effect.


I want to continue working on my own game, so i want to finish this plugin soon.
Super awesome, works like a charm!
Just found a serious bug. Trying to change the equipment of an actor will crash the game. (Reason) I will fix this and add some other minor stuff and then the plugin goes v1.0. The full release will be a new topic in the completed-plugin forum.

Original thread: https://forums.rpgmakerweb.com/threads/sgs-stats-additional-stats-for-actors-and-enemies.59493/