Lunatic mode tags are just writing javascript code that's run at specific times, like using the Script command in the event editor, or a damage formula.
this will always be available, but it will mean different things depending on where its called. During skill execution, it's the "action" currently being executed. On a state, it might be the target of the state. I'd suggest avoiding using it most of the time.
undefined is a feature of Javascript as a language, and is the value that anything will have before an actual value is assigned to it.
Yanfly's lunatic tags will pretty much always have
user/
a and
target/
b available, just like the damage formulas. Lunatic tags on states will have
origin, which is the character who applied the state, but the
origin can be
undefined if the state was added via troop event, some script calls, or is passive, so you should always double check it first.
value only exists for lunatic tags that return or modify a value, which all specify that in the documentation- generally, it's things related to the damage formula, or that let you define custom values, like the price of an item in a shop or MP cost of a skill.
There's no shorthand to refer to characters outside of the user, target, and origin- you'd need to use the full javascript for that, like $gameTroop.members()[3] to get enemy number 3. Which might be the forth enemy, since it starts with enemy ID 0.
Getting the caster's attack stat during a spell's casting is easy- it's just a.atk, the same way you'd do it in the damage formula. Getting the attack stat of the caster for use with, say, a status effect, would be origin.atk (as you can see from one of yanfly's
Tips & Tricks videos).
The values you're referring to, aside from
this and
undefined aren't "global", they're just useful data yanfly's plugins fetch ahead of time to make formulas easier. I'd suggest going through the tips and tricks videos and seeing if there's something similar to what you want to do, and looking at how that works, first.