- Joined
- Apr 6, 2016
- Messages
- 278
- Reaction score
- 163
- First Language
- Swedish
- Primarily Uses
- N/A
Hello!
So I am in need of getting the damage formula and the elementId from customEffectEval I have.
So, I was going at this thing some months ago. And I did a little snippet of code, that I felt, even then, was rather messy.
As you can see, it's not a pretty sight. I could do it smoother now. I did a quick little fix for the first one, then I thought. I should ask if there is a better way to this that I am unaware of as of yet. So here I am, a guy, sitting in front of a screen, at a forum, asking for tips and tricks. At any rate here is what I did about 5 minutes ago.
Still not happy with this, but I only spent a few minutes on it to get it working with the plugin revamp.
So my question is, is there an easier way to do this, or is the approach above close to the way it should be done?
I believe the plugin in charge of assigning this specific notetag is YEP_BuffsStatesCore. But, the question should not necessarilybe treated as plugin specific.
Best regards,
Bishiba
Edit: Realizing that I never specific what I'd be looking for -.- So for example, where it says "var damage = ", I'd like to extract the damage formula so that I can calculate it. In terms of the element, I'd just like to extract the number.
Alright, so I am currently using this function:
So I am in need of getting the damage formula and the elementId from customEffectEval I have.
So, I was going at this thing some months ago. And I did a little snippet of code, that I felt, even then, was rather messy.
JavaScript:
BISH.SkillDescription.getEffectFormula = function (i, n) {
if (this.hasStateFormula(i, n) === true) {
textBeforeFormula = "var damage = ";
f = $dataStates[this.getCurState(i, n)].qmeta["Custom Regenerate Effect"];
x = f.indexOf("var damage = "); //First part of formula string;
x += textBeforeFormula.length;
y = f.indexOf(";"); //Formula string ends.
f = f.substring(x,y);
//console.log(f);
f = f.contains("origin.") ? f.replace("origin.", "a.") : ("Error in $dataStates[" + this.getCurState(i, n) + "].qmeta formula. Given string \"" + f + "\" cannot find \"origin.\"");
a = this.getEffectType(i, n) + "${";
a += f;
a += "} ";
a += this.getEffectElement(i, n);
return a;
}
}
BISH.SkillDescription.getEffectElement = function(i) {
//Get the element ID of the formula.
p = $dataStates[this.getCurState(i, n)].qmeta["Custom Regenerate Effect"];
s = "";
if (p.contains("var elementId = ")) {
u = p.indexOf("var elementId = ");
o = p.indexOf(";", u);
u = p.substring(u, o)
o = u.indexOf("=");
u = u.substring(o + 2);
s += $dataSystem.elements[u] + " damage";
s += " ";
}
return s;
}
JavaScript:
Window_SkillHelp.prototype.getEffectFormula = function (customEffectEvalString) {
textBeforeFormula = "var damage = ";
var x = customEffectEvalString.indexOf(textBeforeFormula);
x += textBeforeFormula.length;
var y = customEffectEvalString.indexOf(";");
customEffectEvalString = customEffectEvalString.substring(x,y);
return customEffectEvalString;
};
So my question is, is there an easier way to do this, or is the approach above close to the way it should be done?
I believe the plugin in charge of assigning this specific notetag is YEP_BuffsStatesCore. But, the question should not necessarilybe treated as plugin specific.
Best regards,
Bishiba
Edit: Realizing that I never specific what I'd be looking for -.- So for example, where it says "var damage = ", I'd like to extract the damage formula so that I can calculate it. In terms of the element, I'd just like to extract the number.
Alright, so I am currently using this function:
Code:
BISH.getCustomEvalFormula = function(customEval, string) { //To find a value, it has to end with ";" and have a unique identifier.
formulaStart = customEval.indexOf(string) + string.length;
formulaEnd = customEval.indexOf(";", formulaStart);
formula = customEval.substring(formulaStart, formulaEnd);
return formula;
};
Last edited: