Asking for (or how to make) a tag for damage formula

Hi, so I'm working on a battle system - that involves changing/checking states frequently to alter character sprites, and since I have no idea how to plan out or arrange the states - they're constantly changing.

The problem with this is that it makes it kind of a pain to keep going though my attack skills and have to re-type the states to match the changes. So I feel like that maybe instead of having to keep doing that it would be easier if I had that bit of damage formula in a script - and I could just call it with a tag instead.

That way if states keep changing, I just edit the script - and it affects everything with the tag.

The problem with that is I don't exactly know how tags work - and I don't think I've seen any scripts that use a damage formula thing (unless I'm googling wrong or the results are being pushed super down by things google thinks I'm really asking for).

So if anyone wants to give it a shot - or give me advice on how to even attempt that, I'm all ears.

edit: Oh crud, I miss clicked the wrong forum - can you please move or delete this!
I meant to put this in
RGSS3 Script Requests
Moderator note: Moving to RGSS3 Script Requests
Can you give me a more detailed example of what you're currently having to do so I can have a better idea of what it is you're after?
Thanks for moving the script Kes!

Can you give me a more detailed example of what you're currently having to do so I can have a better idea of what it is you're after?

Ok, so every skill involves adding a state that changes a battlers sprites.
For a normal attack - it looks like this:
Spoiler
##########################
a.add_state(27)
if a.state?(40);a.add_state(41);end;
b.add_state(28)
if b.state?(40);a.add_state(42);end;
##########################
*damage formula here*
A run down of what everything is doing:
Spoiler
a.add_state(27) - sets the battler to do a normal attack pose.

if a.state?(40);a.add_state(41);end; - Checks to see if the actor is under a state, 40 is "Toad", so instead of doing the normal attack pose, it does a frog attack pose (as it'd be weird if he kept flip-flopping to normal and frog forms)

b.add_state(28) - sets the hit pose
if b.state?(40);a.add_state(42);end; - sets the hit pose after checking for Toad status

So this code in particular is something that gets copy-pasted to every attack skill - magic skills work the same except the attack state is different.

So really the problem here is that I keep thinking up new states and I constantly have to reorganize everything - meaning I have to keep going through the attack skills to keep things up to date.

So what I'm hoping to get out of this is turn that "add state" stuff into a script that I can call with a tag during the damage formula. So that if I do end up changing state order - I can just change the script.
What would you want the tag to be, exactly?
Putting something like <State Attack> in a note box, and then it would add that state changing bit of the formula to any skill that's marked with it.

Though I'm still really fuzzy to how exactly tags work (aside from they go in a note box). Though I feel it might be a stretch to have the damage formula use it since it looks like its something scripts check for rather than the main stuff.
I'll see what I can come up with.
Thanks! And Good luck.
So this code in particular is something that gets copy-pasted to every attack skill - magic skills work the same except the attack state is different.

So really the problem here is that I keep thinking up new states and I constantly have to reorganize everything - meaning I have to keep going through the attack skills to keep things up to date.

So what I'm hoping to get out of this is turn that "add state" stuff into a script that I can call with a tag during the damage formula. So that if I do end up changing state order - I can just change the script.
You can just use the formula itself combined with script. Like, putting this script new script in your script editor
Code:
def attack_states(a,b)
  a.add_state(27)
  if a.state?(40);a.add_state(41);end;
  b.add_state(28)
  if b.state?(40);a.add_state(42);end;
end
Then in your damage formula, it would be simply to write
Code:
attack_states(a,b); a.atk - b.def
If you decide to change the state ID, you just need to edit the script and all skills with "attack_states(a,b)" in their formula would be affected
Ok, that works perfectly! I didn't actually think it would be that simple.
So i'm guessing anything under the def "x" gets stored as code. And then you can call it up in the damage formula by just typing it in there?
Yep, it's called a "method" or "function" 🙂 go try to have fun with it
Ok, functions are really great. Though something I've been trying to do is use a function to create a damage formula and a damage formula multiplier. Though I've been having a bit of trouble whenever I try to add variables in the mix - which causes attacks to always return no damage, even though they'd work in the formula box, though I guess I'd be better off asking somewhere else than here since the problems pretty much solved now.
when it returns no damage, it means it has error somewhere in your script. it's somewhat hard to debug since RM just handle the error by returning zero damage, and can't tell what was wrong with it
I definitely narrowed it down to the variables though. When def multiplier is just a number, it works fine.

But when I try to call a variable, or check if an actor has a state I have trouble, though maybe I've just been trying to call them wrong?

Been trying to call states with:
if a.state?(x);0.5;end;
and
variables (mainly weather for now):
if v[3] = 1;0.5;end;

Then they get added like this:
physdam(a,b)*(1+water+rain)

when water and rain, are just a single number the damage works fine. So it has to be the way I'm checking for variables/states.
For variable, you either need to use the global name, or pass it through the function arguments. Because the name 'v' is not known

1. For using global one, type $game_variables[id] instead of v[id]
2. For passing through the function argument, try to add v inside the bracket in attack formula like
Code:
attack_states(a,b,v)
then edit your script to
Code:
def attack_states(a,b,v)
   .....
end
So, the variable name 'v' will be known inside your function

Tip: You can even try to use switches by using $game_switches[id] as well
Okay, game variables worked - weather checks are good to go.

Though I remember seeing somewhere around here (I think in the useful script calls thread) that said v[x] was okay to use instead - but looking at it now my weather common event is using game_variables[x] too so I don't know why I didn't try that sooner.

And I also managed to get the state check working - so the damage formula is working really good now.

Though something I've noticed now, is that weather checks seem to trigger weather instead of checking for it. Which is really strange, since it wasn't happening before.
That might be because you used = instead of ==.

= sets the variable.
== compares the variable with another.
Okay, that worked - but I'm now back to returning no damage. But honestly, I think that has something to do with the functions I've been testing - since I've noticed damage was only happening in the rain, which was pretty much constantly happening during test runs.

So I think it's something to do with the functions I've been testing out, and I don't know if trying to simplify what I have to put in the damage formula box is just making things even more complicated. Though I do know it works fine, when I don't bring up the variable checks, with = or == and it just reduces formula boxes to three variables and two function calls.

edit:
Honestly, at this point I do feel like it would be better to just make a new thread - since I simplified things a bit and found the "real" problem with the code.

Though it feels kind of weird to make a new one with this thread right here and all - though I do feel like it's probably Ok to close this, didn't really figure out how to use tags, but my problem got solved just fine, and functions have been a real game changer for me.

One last edit in case anyone was interested:
But I managed to fix the problem, which was really stupid on my part that I'm not even going to say what the problem was - though the whole "clean up" thing did get me to simplify things up quite a bit - so its not too big of a loss.

But yeah, formula's all good now. I'm sure there's a way to optimize it further, but I'm happy with it right now and I don't want to tempt fate.

Original thread: https://forums.rpgmakerweb.com/threads/asking-for-or-how-to-make-a-tag-for-damage-formula.89999/