Hello, first time posting here (And apologies if this is not the correct location to ask this question)
I'm currently trying to figure out how I could go about making a Skill that only works when certain conditions are made.
Example being: An attack that only works if the target is Poisoned.
Ideally, it does zero damage if the target isn't poisoned, and does a large amount if they are.
So far, the closest thing I have come up with is modifying the poisoned stat, so that people who are poisoned are ALSO vulnerable to a made up 'Poisoned' damage type, and the example attack does that exclusive 'poisoned' damage type.
I can make it cure poison as well easily enough, but I will also want other attacks interacting with status ailments, and trying to create one (Or numerous) type weaknesses back and forth sounds like a hassle
Is there a way to just have a damage formula that is like "If Poisoned [a.mat * 6-bmdf * 2]" or something?
b.isStateAffected(id of poison) ? a.mat * 6 - b.mdf * 2 : 0;
Yes! This is exactly what it was I was wanting!
Coding is FAR from my strong suit, so just making sure that I am understanding this breakdown:
[b.][isStateAffected][(id of poison)][ ? ][a.mat * 6 - b.mdf * 2][ : 0;]
This is just exclusively stating that it is referencing the target. if this was [a.] then it would be checking if the actor was the state.
isStateEffected seems like it is straight forward. Could this be other things, however?
This is just the ID of the State that is being searched for the condition, if I'm reading it right. So, if I wanted a burned target, then it would be whatever the 4 digit ID of poison is, correct?
The nature of this question mark I'm curious about. is it just the barrier between setting up the conditions, and the result of those conditions? Could more than just 1 condition be made as a result? For example, an attack that scales with the number of different status ailemnts upon it? I also assume that the spaces are important to remain before and after.
Standard Damage Formula here. I understand this well enough
While I understand that this is the 'or' in the context of everything before the colon (And after the question mark) is the 'Yes Poisoned' and everything after it is the 'No Poisoned'. However, is the semicolon important in this. Would there be different additions to make here if there was more than the binary yes/no? Or would I, as a whole, be much better off avoiding being more complicated than this?
Okay, so the construct I've given you here is what's known as a ternary if statement. It's basically a method of putting an entire conditional statement in a single line.
condition ? true : false;
In a ternary if, there's always a question mark between the condition and the code to run if the condition is true, and a colon between the true code and the false code. There has to be something on both sides or you'll get an error; you can use "null" as the false code, but this is a practice that's generally frowned upon. There's no harm in doing it, though.
Yes, in the damage formula, "a" references the attacker and "b" the defender. If you'd put a.isStateAffected it could have been checking the user of the skill, you are correct.
Yes, you can absolutely use any other property or function in place of isStateAffected. You could use hasSkill to make it dependent on the user having learned a specific skill, or a.hpRate() >= 0.4 to have it only work if they have greater than or equal to 40% health, for example.
You are correct on the ID thing, but it's not necessarily 4-digit. You don't have to include the leading zeroes.
If you want to include more than one check, you'd just make the "false" part of your ternary if another ternary if. So if you wanted something to happen if the target is poisoned, and something else to happen if they're burned:
b.isStateAffected(id of poison) ? formulaforpoisonhere : b.isStateAffected(id of burn) ? formulaforburnhere : 0;
This helps immensely. Like I said, I'm very new to this as a whole, but I very much appreciate the breakdown on this. Intimidated, but appreciative.
In the example that you gave with multiple Ternary If's, would it trigger the formula for every 'True' or does it only search for the first True, or false?
I.E. would the example that you gave do, hypothetically, 200 damage if they're poisoned AND 200 damage if they're burned, or will it see that it can do the Poisoned damage, and then stop checking
Another question: I'm trying to figure out how to trigger an effect that only happens if you kill the target. I know enemies can have a 'collapse effect' that does something when it dies, but I can't find a way to utilize it as part of a skill (Such as: IF the target dies, heal yourself)
Good to know. If that's the case, I think I'll steer clear from something like that.
Only thing I would wish to know would be what function (if it existed) WOULD work to, for example, trigger damage for the target being poisoned AND burned, rather than Or
Making sure I read this right:
[let damage =] [0;] [if (b.isStateAffected(id of poison)) damage += formulahere;] [if (b.isStateAffected(id of burn)) damage += formulahere;] [damage;]
I'm not sure if this part is code, or just how it is 'supposed to be read'
This is just saying that the base damage is zero, to be modified, yes?
This is the first 'if' in that 'if poisoned, insert damage fomula here. When putting in the formula, would i replace just [formula here], would I include the +=, or would I also replace the word damage?
This is the second if. 'If the target is burned, Damage formula here. More or less same questions. I'm GUESSING the += is the way the coding reads "Add this much" correct? Meaning it would be important to keep there?
And This, as you said, is just where it is actually taking the damage that it has accrued from the previous If statements, right?
So, hypothetically:
0; If (b.isStateAffected(4)) damage +=100; If )b.isStateAffected(5)) Damage += 100; Damage;
now, would I change the word 'damage' to 'heal' if I were to be creating a clutch-heal style spell that heals more the more status effects they have? Or is the word 'damage' not supposed to be there at all?
It was all code. "let" is a keyword in Javascript that defines a variable whose value might change (as opposed to const, which creates a variable with a static value that can't be altered).
let damage = 0;
creates a variable with the identifier "damage" and the initial value 0.
damage += [formula]
You'd replace the [formula] part with your damage calculation. The rest is saying "add the result of the right side of this to the variable called damage".
Same with the second bit.
And the final "damage" is just saying "use the value of the variable called damage as the final value for the formula".
Your hypothetical is almost there, but needs the "let damage = 0" at the beginning to create the variable you're referencing later. And it's case-sensitive, so damage and Damage are not the same variable.
But the identifier is arbitrary; I could have called it "bananas". It's good to name your variables after what they're representing, so if this were for a heal I would recommend calling it "heal" instead, yes.
Alright, so in effect:
You are creating a word that it is defined to understand
You then create a series of If situations, which effective say "Add this amount to the word", and you punctuate the end with the defined word, which has a new value that may be greater than zero (If the previous If's added to it).
So:
Let Damage=0; ['Damage' is equal to zero]
If (b.isStateAffected(4)) damage +=100; [100 has been added to the value of 'Damage']
If (b.isStateAffected(5)) Damage += 100; [Another 100 has been added to the value of 'Damage']
Damage; [As it is no longer a definition or a function, the program simply utilizes the value that it now understands 'Damage' to be, which in this instance is 200]
You are correct, but you're still mixing capitalisation (Damage in most lines but damage in the second one) which would cause an error because you've defined "Damage" but haven't defined "damage". Other than that, spot on!
I edited that post 2 or 3 times in order to try to keep my punctuation and capitalization consistent.
But yes, that is exactly what I need to know.
Thank you so much for your help!
Not a problem. Feel free to fire me a PM if you have any further questions.
OK, two addendums:
there is a pinned topic about damage formula coding somewhere on the forum where questions like yours are supposed to be asked and answered. You might want to read through that because of the many other things you can do there.
NEVER use leading zeroes in any programming language. The ID is always for example 13 and not 0013.
That is because most programming languages read two leading zeroes as an indication for octal numbers (or for example 0x as hexadecimal numbers, you might have seen 0xff as number notations around).
octal 0013 is the same as decimal 11, so using leading zeros will change the ID in a lot of cases, and thse errors are sometimes difficult to pinpoint.