RMMV Function within a plugin which performs at the start of every battle turn

Status
Not open for further replies.

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
First Language
English
Primarily Uses
RMMV
Currently trying to resolve a bug with a plugin, and I've had the idea to circumvent the issue by making the plugin do some comparisons and make some calls at the start of each combat turn.

I want it to run this function exactly once at every turn, as soon as a turn "ends", and the player regains control in the battle menu (technically before the turn starts).
Simply put, what would be the code necessary to perform this?
I imagine it's something quite simple such as utilising a function in the basic MV code, but I'm not very knowledgeable with the basic MV functions or with JS in general.

For further information, I essentially want it to check each enemy for a condition, then apply an effect to them based on the result.

Thanks!
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,257
Reaction score
4,730
First Language
EN
Primarily Uses
RMMZ
Currently trying to resolve a bug with a plugin, and I've had the idea to circumvent the issue by making the plugin do some comparisons and make some calls at the start of each combat turn.
This timing (start of input phase) sounds like the troop event condition "Turn End" with span "Turn". Could you just use a troop event for this?

Circumventing a problem only hides it, and hidden problems can make future debugging much more difficult than necessary. :kaoswt2: However, no-one can offer a better alternative without more information on the original problem, preferably a thorough description of the undesired behaviour and steps to reproduce it in a new project.

Without plugins:
  1. The input phase starts via BattleManager.startInput
  2. The turn phase starts via BattleManager.startTurn (this also increments the troop turn)
I assume you want option 1. To insert extra code in there, you could try something like this in a plugin:
JavaScript:
(function(alias) {
  BattleManager.startInput = function() {
    // your code here
    alias.apply(this, arguments);  // invoke original code
  };
})(BattleManager.startInput);
If you are using any plugins that change the battle flow, hooking into this specific method might not produce the desired results.

For further information, I essentially want it to check each enemy for a condition, then apply an effect to them based on the result.
Interpreting that as "apply state 456 to all enemies affected by state 123":
JavaScript:
$gameTroop.members().forEach(function(m) {
  if (m.isStateAffected(123)) m.addState(456);
});
Remember to save your project to apply Plugin Manager changes before testing. :kaohi:
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
First Language
English
Primarily Uses
RMMV
Interpreting that as "apply state 456 to all enemies affected by state 123":
I had intended "condition" as in a conditional statement, now realising that can get confusing with RPGM.

Anyhow, this seems to do exactly as I needed.

If you want specifics for consideration, I'm using the MV Dragonbones integration (yanfly friendly) and ran into a bug where the plugin somehow never calls for new motions outside of attack and receive damage (which it has specific functions to replace), so I'm slotting this in there to ensure the enemies are performing the correct motion every turn, and if not, play the correct motion.

So far, I believe I'm able to do that perfectly fine with the info you've provided, thank you very much!

I certainly would prefer to solve the central issue but I've been trying for a couple of days now with no luck. Theoretically, this should resolve all issues since it only overwrites the motion when the motion is incorrect.

Edit: Actually, now trying to figure out how to assess what motion the enemy is currently performing. Is that stored anywhere that's easily accessible?
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,257
Reaction score
4,730
First Language
EN
Primarily Uses
RMMZ
I'm not really familiar with KELYEP Dragonbones Integration but I checked its code and it seems to be a completely separate animation system that plays "on top" of the default sprites and runs on an independent update loop/ticker. Looks like battlers should automatically start the walk motion if/when their current motion completes, unless they're affected by state 1.

Without plugins, for an instance of Game_Actor stored as actor, here are some valid motion calls:
  • Check: actor.motionType() (returns a string, e.g. "dead")
  • Set: actor.requestMotion("walk");
  • Refresh: actor.requestMotionRefresh();
If you're also using YEP Animated Sideview Enemies then these calls might work for enemies too.

In case it helps, here's a couple of things I found in the DragonBones integration plugin:
  • Check motion? battler.lastMotionType === "dead"
  • Set motion? dragonBonesIntegration.PlayAnimationOnBattler(battler, "walk");
battler is a Game_Battler instance (i.e. actor or enemy).
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
First Language
English
Primarily Uses
RMMV
I'm not really familiar with KELYEP Dragonbones Integration but I checked its code and it seems to be a completely separate animation system that plays "on top" of the default sprites and runs on an independent update loop/ticker. Looks like battlers should automatically start the walk motion if/when their current motion completes, unless they're affected by state 1.
See, I did notice this, and I've edited that piece of code to transition to an appropriate motion instead of walk every time. Which is weird because I couldn't find where in the code it updates the motion normally (for things such as abnormal, dying, etc). As far as I can see, it has code for handling attacks, receiving damage, and death which all function fine. The documentation for the code, however, implies that other motions such as abnormal should be functional.

On to your advice,
motionType() is always returning null, and lastMotionType is always returning undefined when I check them within the function.
The set motion function dragonBonesIntegration.PlayAnimationOnBattler() does indeed work, and that's what I've been using thus far.

The only issue now is that the animations restart from frame 1 when the turn starts which is, at most, just a graphical inconvenience. But if I'm able to check whether the enemy is already performing the animation it should be, I can avoid restarting its animation with a simple statement. Neither of the two checks you mentioned work as far as I can tell unfortunately, and neither does anything I've tried.
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
First Language
English
Primarily Uses
RMMV
Solved it I think. It doesn't currently define lastMotionType anywhere in the enemy code, so I've added a this.lastMotionType = line to every instance of success in the PlayAnimationOnBattler() function.

Currently, it *looks* like everything works as intended, and enemies will only be issued a PlayAnimationOnBattler() command on a new turn when the motion is not equal value or type to the previous motion.

It's a little messy and maybe a bit inefficient but as far as I know, it shouldn't break anything.
If anything seems off or wrong about that approach, please let me know so I can catch it sooner rather than later. I'll include my edited function here:

JavaScript:
(function(alias) {
  BattleManager.startInput = function() {
    $gameTroop.members().forEach(function(m) {
        var result = false;
    
    if (m.isDying() === true) {
        if (m.hasDragonBone === true) {
            console.log("current motion: " + m.lastMotionType);
            //check for new motion
            if (m.lastMotionType !== "hurt") {
            result = dragonBonesIntegration.PlayAnimationOnBattler(m, "dying");
            console.log("new motion. play dying motion");
            } else {
                console.log("same motion. dont play");
            }
        }
    } else {
        if (m.hasDragonBone === true) {
            console.log("current motion: " + m.lastMotionType);
            //check for new motion
            if (m.lastMotionType !== "idle") {
            result = dragonBonesIntegration.PlayAnimationOnBattler(m, "walk");
            console.log("new motion. play walk motion");
            } else {
                console.log("same motion. dont play");
            }
        }
    };
        
    if(result === false) {
        console.log("attempted dying or idle motion, armature invalid or motion identical");
    }
    });
    
    alias.apply(this, arguments);  // invoke original code
  };
})(BattleManager.startInput);
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,257
Reaction score
4,730
First Language
EN
Primarily Uses
RMMZ
Looks OK as far as I can tell! Good to hear you found something that works~ :kaojoy:
 

SuzuPazuzu

Villager
Member
Joined
Apr 19, 2012
Messages
20
Reaction score
4
First Language
English
Primarily Uses
RMMV
Your help was much appreciated, thank you very much!
(Not sure how to mark this as solved, but it's solved)
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,257
Reaction score
4,730
First Language
EN
Primarily Uses
RMMZ
You can report the first post of the thread with a reason like "Solved". This brings it to the attention of the moderators, who can close the thread.
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
46,153
Reaction score
16,971
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I've made a big emphasis on visually representing things to make the game as accessible as possible.

MP.png

Grimoires will consist of 5 - 10 pages of skills (still finalizing that max number)

Since each actor is able to take multiple actions per turn, each skill will cost 1-5 pages
This prevents more powerful skills from being uber spammed during an actors turn.
Cats are so easy. I noticed the gray one would never nap in the office while I worked, so I put a blanket on the spare chair in here and now she won't leave.
1701793108356.png
still work in progress, had not much time at the weekend^^
Oh deer! Have you checked my calendar today already? ;3
1701790624587.png
Whenever the site tells me this, I feel like it's being intentionally antagonistic. Like, just freaking round down!

1701784620294.png

Forum statistics

Threads
136,764
Messages
1,269,680
Members
180,509
Latest member
grayskye00
Top