Questions about Writing Lunatic

rechronicle

Mystvaldia
Veteran
Joined
Oct 30, 2013
Messages
137
Reaction score
109
First Language
Bahasa
Primarily Uses
RMMV
Are these 'keywords/variable' always available whenever I want to write Lunatic code? (can we call this global variable?)

this, target, user, player, a, b, value, undefined, origin

I tried to create Custom Apply Effect with this.gainHp(100) and it works. But where can I find the list of those predefined 'keywords/variable'? For example, when I want to refer to a certain enemy instead of this one. Or just want to access and get the caster ATK point.

Not sure if it's the right term to describe them. Hm... :|
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
869
Reaction score
554
First Language
English
Primarily Uses
RMMV
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.
 

rechronicle

Mystvaldia
Veteran
Joined
Oct 30, 2013
Messages
137
Reaction score
109
First Language
Bahasa
Primarily Uses
RMMV
Alright, this is a great start.
Some things that I want to do:
- A skill that getting stronger based on each turn passed and then reset count to 0. (IIRC, Rmmv already has that turn counter variable.)
- Showing enemy next turn skill.
- A skill that gets stronger each time it's used in that battle.
- etc


After some testing, I finally able to write this kind of skill with lunatic notetag:
<Pre-Damage Eval>
if (a.hp >= 50) {value = 20}
else
{value = 10}
</Pre-Damage Eval>


Lol, this is kind of fun & fascinating to play around. Thanks!!! :D
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
869
Reaction score
554
First Language
English
Primarily Uses
RMMV
@rechronicle Showing next-turn skill is probably the hardest of those, since enemies don't choose their skills ahead of time. You'd either need a plugin, or some fiddling around with the AI so that there's never a case where it has two possible skills to choose from on a given turn.
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
- A skill that getting stronger based on each turn passed and then reset count to 0. (IIRC, Rmmv already has that turn counter variable.)
- A skill that gets stronger each time it's used in that battle.
Yanfly has a tips & tricks video/example of a skill that gets stronger each time it's used in battle, and one for a weapon that gets stronger each time it's used. I can't remember the names of those particular examples, but if you scroll through his tips and tricks page you'll find them. Once you understand how to use the script calls and lunatic code it's not terribly difficult to modify some of those tips & tricks to fit whatever you need.

Also, just going through those tips & tricks will give you some pretty good ideas of what is possible through his plugins; although, he has since made some plugins that provide shortcuts to a lot of the lunatic coding needed to get some of them working. For example, the extended DoT plugin handles all kinds of DoT effects with simpler note tag comments, rather than having to use longer versions of lunatic code.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

gonna record the beginning of my game if anyone is interested in seeing it message me for the link it's going to be unlisted on youtube
Dev stream today, come on by and ask questions about rpg maker!
Fun fact: If your story introduces a variety of different races, the "human race" will automatically become the most corrupt race in general.
Finally finished my late start entry for the jam. Now. I. Sleep.
Just made 3 easy, simple and small MZ plugins today(12 hours straight), and I never thought I could ever do this.
Now I feel myself being very productive, even though I know I'm just utterly flattering myself lol

Forum statistics

Threads
104,649
Messages
1,007,823
Members
136,134
Latest member
Cashews
Top