MV Getting the percentage of actors elemental rates in game?

Henlo! I'm trying to visiually showcase actors resistances in game depending on their current rate percentage and also to create some conditions in game based, so I want to set it up like this:

0% - 49% — Super resistant
50% - 99% — Resistant
100% - 109% — Neutral
110% - 149% — Weak
150% - ∞ — Super weak

To test out I setup some different states with different rates
bkyMBPh.png


And then I apply them in game, and use this event to get the actors current value for that element, in this case physical and I'm testing with actor 6.

qZ6jDEO.png


But all I get are single number values, if the state has a % below 100 it gives me 0, if it's above 100% then I get a 1, and above 200% I get a 2, and so on.

I tried using:
Code:
$gameActors._data[6].elementRate(1)
and
Code:
$gameActors.actor(6).elementRate(1)
but I get the same result.

Is there no way to get precise values in game to do multiple levels of resistance?

Thanks for reading 😤
Hey there,

Normally the element rate is stored as a share of 1, so a 50% element rate would equate to an element rate value of 0.5. The game variables will round any number you store in them down, that's why you end up with 0.

The easiest way to get a percentage would probably be to multiply your rate by 100, or use something other than $gameVariables to store your numbers.
Alternatively you could add .toString() to the end of your assignment to return it in string form, which will prevent it from being rounded.
Woah thank you so much for those quick replies! It's working now 😂
It might be a bit overkill, but if you don't like how variables always get rounded down during assignment, you could just disable that behaviour: here's a simple plugin for that.

JavaScript:
Game_Variables.prototype.setValue = function (variableId, value) {
    if (variableId > 0 && variableId < $dataSystem.variables.length) {
        this._data[variableId] = value;
        this.onChange();
    }
};

Original thread: https://forums.rpgmakerweb.com/threads/getting-the-percentage-of-actors-elemental-rates-in-game.154379/