TSR_SpriteEnemy

● ARCHIVED · READ-ONLY
Started by TSR 18 posts View original ↗

  1. spriteEnemyTitle.png
    download:
    TSR_SpriteEnemy
    Author:
    TSR
    Features:
    • Add 4 basic motions to enemy battlers (idle, attack, skill and damage)
    • Revamp the battle effects of enemy sprites
    • Add the option to use State Animated Overlays on enemies
    Code:
     * ====================================================================
     * == About this Plugin ===============================================
     * ====================================================================
     * The plugin provide 4 battle motions for enemies:
     *
     *        Idle motion: When the enemy battler is in 'wait' mode.
     *
     *      Attack motion: When the enemy battler make a regular attack.
     *
     *       Skill motion: When the enemy battler execute a skill
     *
     *      Damage motion: When the enemy battler receive damages.
     *
     *
     * In addition, the plugin revamp some of the battle effects for enemy
     * battlers behaviors:
     *
     *     Attack and skill: the enemy battler will step forward, tilt a bit
     *                       while executing the action, and step back. This
     *                       replace the default 'whiten' effect.
     *
     *               Damage: the enemy battler will step back, tilt a bit
     *                       with a red flashing effect, and move back to
     *                       its position. This replace the default 'blink'
     *                       effect.
     *
     *                Evade: the enemy battler will step back as it evades an
     *                       attack, then move back to its position.
     *
     *               States: the plugin provide the option of using the state
     *                       overlays animation over enemy battlers when they
     *                       are affected by a state. You can choose to show
     *                       either the default state icons or the animated
     *                       overlays, or both. Overlays requires to be set
     *                       with enemies notetags (see bellow).
     *
     *          Restriction: the animated enemy battlers will freeze whenever
     *                       they are affected by a state that have the 'cannot
     *                       move' restriction.
     *
     *             *step forward and backward directions depends on wether
     *              side or front view is in use.
     *
     *
     * HOW TO USE:
     *
     *    The motions frames must be arranged in a sprite sheet with 4 rows.
     *    Each row represent one of the 4 battle motions, 'Idle', 'Attack',
     *    'Skill' and 'Damage', in that order.
     *
     *    The motions animations can have any number of frames, down to a
     *    minimum of 3. Each motion on a sprite sheet must have the same
     *    number of frames.
     *
     *    The 'Idle' motion is a back and forth loop. The other motions
     *    stops once the last frame is reached.
     *
     *    Use the following Enemy Notetag to assign a sprite sheet to an
     *    enemy in the database.
     *
     *      ENEMY NOTETAG:
     *                      <ENEMY IMAGE: filename, frames>
     *
     *              filename: the file name of the sprite sheet without
     *                        extension. The sprite sheet must be stored
     *                        in /img/sv_enemies (if using side-view) or
     *                        /img/enemies (if using front-view).
     *
     *                frames: the number of frame per motions of the
     *                        sprite sheet.
     *
     *     
     *                   EXAMPLE:  <ENEMY IMAGE: GobelinSheet, 3>
     *
     *
     *                   The enemy battler having this notetag will be
     *                   assigned with the sprite sheet 'GobelinSheet'
     *                   which have 4 rows of 3 frames motions.
     *
     *         
     *          Use this notetag to assign a specific animation to the
     *          normal attack of an enemy.
     *
     *                          <ATTACK ANIMATION: Id>
     *
     *                    Id: the id of the animation that will play when
     *                        the enemy execute a normal attack.
     *
     *
     *
     *      NOTES:
     * 
     *         *The sprite sheets are splitted by the plugin into 4 rows and
     *          a number of columns defined by the notetag 'frames' argument.
     *          This mean you can use sprite sheets of any size. The enemy
     *          images will appear at their actual size on the battlefield.
     *
     *         *Enemies without the notetag will be treated as the default
     *          static enemies.
     *
     *         *You can use a mix of animated enemies and static enemies.
     *
     *         *Static enemies will still behave according to the battle
     *          effects provided by the plugin.
     *
     *         *It is suggested to assign a static enemy image to enemies
     *          in the database even if they have a sprite sheet notetag.
     *          You can use the same image for all animated enemies, it
     *          will serve as a placeholder for building the troops.
     *
     *         *Be sure your sprite sheets are stored in the correct folder
     *          wether you're using side-view or front-view battles.
     *
     *
     * ENEMIES STATE OVERLAYS
     *
     *      Plugin parameters:
     *
     *           -Enable State Icons:
     *                  Display or not the default state icons above enemy
     *                  battlers head.
     *
     *           -Enable State Overlays:
     *                  Display or not the animated state overlays over enemy
     *                  battlers.
     *
     *      Animated state overlays are binded to the state affected battler,
     *      and appears at the center of the battler sprite, similar to the
     *      Actor battlers animated state overlays.
     *
     *      While actor battlers are all the same size, enemy battlers can
     *      have various size and forms. This means that the state overlays
     *      might not appears correctly over the enemy battlers without proper
     *      settings.
     *
     *      Example: the 'Sleep' animated state overlay should be displayed
     *               above the battler's head, while the 'Blind' overlay should
     *               cover the battler's eyes. The 'Paralysis' state, on the
     *               other hand, should encompass the whole battler's sprite.
     *
     *
     *      To achieve specific settings for each enemies, another Enemy Notetag
     *      is provided:
     *
     *          ENEMY NOTETAG:
     *                        <STATE OVERLAY DATA>
     *                            overlay INDEX: x, y, scale
     *                            overlay INDEX: x, y, scale
     *                            overlay INDEX: x, y, scale
     *                        </STATE OVERLAY DATA>
     *
     *              INDEX: the overlay index, starting at 1 for 'Poison'.
     *                  x: the horizontal offset of the overlay.
     *                  y: the vertical offset of the overlay.
     *              scale: the scaling of the overlay.
     *
     *
     *           EXAMPLE:     <STATE OVERLAY DATA>
     *                            overlay 2: 0, -48, 1
     *                            overlay 7: 12, -36, 0.8
     *                            overlay 8: -24, 0, 1.5
     *                        </STATE OVERLAY DATA>
     *
     *           An enemy battler having the above notetag will have specific
     *           state animated overlay settings for the 'Blind' (overlay 2),
     *           the 'Sleep' (overlay 7) and the 'Paralysis' (overlay 8) states.
     *           Note that the 'Blind' overlay is slightly downscaled so it just
     *           cover the enemy eyes; while the 'Paralysis' overlay is enlarged
     *           so it cover the whole enemy sprite.
     *
     *

    Terms
    Code:
     * ==========================================================================
     * == Term of Usage =========================================================
     * ==========================================================================
     *
     * Use in any independant RPG Maker MZ and MV projects, including commercials.
     *
     * Credit is required for using this Plugin.
     * For crediting, use 'TSR' along with one of
     * the following terms:
     *      'The Northern Frog' or 'A frog from the north'
     *
     * Do not change the Header or the Terms of usage.
     *
     * Do not change the main Object name.
     *
     * Editing of the script is allowed for your personal use for your project.
     * If you wish to upgrade the plugin and share it with the RPG Maker
     * community, contact me on discord to ask permission. I'll be glad
     * to provide some guidance with the script too, if needed.
     *
     * DO NOT REDISTRIBUTE!
     * If you want to share it, share the link to my itch.io account:
     * https://the-northern-frog.itch.io/
     *
    *Battlers in the screen shot are from Redshrike from OpenGameArt.org

    Regards,
    TSR :rock-right:
  2. Hi! What a great plugin! :kaoluv:
    Is there any possibility that you could introduce an optional notetag that would change the idle animation to 1-2-3-1-2-3 instead of the 1-2-3-2-1, or is this something you are not interested in?
  3. Hello @Shashmurin,
    thank you for your comments.
    Shashmurin said:
    Is there any possibility that you could introduce an optional notetag that would change the idle animation to 1-2-3-1-2-3 instead of the 1-2-3-2-1, or is this something you are not interested in?
    Very possible, but why an 'optional notetag'? Does enemies in your game can have idle animations that loop from start to end AND others that loop back and forth??
    If you just want to make the idle animation to loop 1-2-3-1-2-3 for all the enemies in your game, you can simply edit the plugin file like bellow:

    First, find this method in the file:
    Code:
    Sprite_Enemy.prototype.setMotionFrame = function(motion, rate) {
        let frame = motion.frame;
        const maxIndex = motion.maxFrame - 1;
        if (frame === maxIndex && !motion.loop) return frame;
        if (this._animationCount % rate === 0) {
            if (!this._goesLeft) {
                if (frame < maxIndex) { 
                    frame++;
                } else {
                    frame--;
                    this._goesLeft = true;
                }       
            } else {
                if (frame > 0) { 
                    frame--;
                } else {
                    frame++;
                    this._goesLeft = false;
                } 
            }
        }
        motion.frame = frame; 
    };

    And replace it by:
    Code:
    Sprite_Enemy.prototype.setMotionFrame = function(motion, rate) {
        let frame = motion.frame;
        const maxIndex = motion.maxFrame - 1;
        if (frame === maxIndex && !motion.loop) return frame;
        if (this._animationCount % rate === 0) {
            if (frame < maxIndex) { 
                frame++;
            } else {
                frame = 0;
            }       
        }
        motion.frame = frame; 
    };

    Should do the trick ;)
    Regards,
    TSR
  4. Thanks for the fast answer! Well you hit the nail on the head; for most enemies I've done the 1-2-3-2-1 is great, but for instance I have a galloping horse/rider and there the 1-2-3-2-1 just doesn't fit at all. Now I'm sure someone could animate that loop just fine, but it would make my life easier if that could be just a notetag command! That way there would be no need to reanimate everything else to fit the 1-2-3-1-2-3! :kaojoy:

    Thanks again for your time!
  5. Hi! Just the plugin I was looking for! I keep running into two problems though:

    1. My game keeps crashing when the enemy evades/the actor misses their attack. Is there any way to disable the evade motion?

    2. When an enemy has the boss collapse death animation the whole sprite sheet is shown rather than a singular frame.

    If I could get help with these two issues it would be greatly appreciated.
  6. Hello all!

    New update:
    • Add the option to loop the idle animation in a 'start to end' manner instead of the default 'back and forth' by adding an argument to the notetag (see instructions) @Shashmurin
    • Fix a bug with the Boss collapse effect. Thanks to @NonexistentRPG for reporting that.
    NonexistentRPG said:
    My game keeps crashing when the enemy evades/the actor misses their attack. Is there any way to disable the evade motion?
    You can 'comment out' the updateEvade() at line 811 in the plugin to disable the effect. But crashing on evasion is not normal. You should dig further to find the cause of the crash rather than disabling wha't trigger it.

    Regards,
    TSR
  7. Thank's for the speedy update! :kaoluv:
  8. Thank you for the speedy update!

    Sadly both my issues still remain.

    Regarding the collapse bug: The updated code crashes my game instantly as I run it and I receive the error code TypeError Cannot set property "trim" of undefined. I managed to overcome this error by replacing the code with the old one from version. 1.0.3. so the issue still remains.

    Regarding the evasion bug: Even though I commented out the code on line 811 the issue still remains. When the enemy evades/the actor misses with their attack the game crashes and displays the error code TypeError Cannot set property "frame" of undefined.

    As said, the first issue was easy to locate as "trim" was easy to locate and remove from the coding, but knowing which "frame" line is causing the problem is much harder to locate. I'm using some other plugins that alter the evade-code, but when I switch of TSR_SpriteEnemy the enemy is able to evade/miss without any issue. If the plugin in turned on but the enemy just has a static image (without any note tags) they can evade/miss without any issue as well, so it's definitly something in the code that is causing problems.

    I should add that I am using frontfacing sprites, if that matters. I noticed that in Sprite_Enemy.prototype.updateEvade = function() { there is no
    if ($gameSystem.isSideView()) so maybe that could be part of the problem?

    Let it be known that I have no coding experience so I'm just going off intuition.

    I hope this might clear up the issue I'm having.

    I am also interested in a version of the script with a fifth sprite option for "evade" that allows me to create a unique animation for the enemy when evading, but that could be discussed as a form of commision. (If there is time and interest for you in that)
  9. There does seem to be some sort of error in the script. I tested it with a new project to avoid any conflicts, and if I use the old note <ENEMY IMAGE: sheetname, 3> I get the error of 'trim' being undefined (line 312), whereas if I use <ENEMY IMAGE: sheetname, 3, TRUE> (you can insert anything other than blank at the last spot, even <ENEMY IMAGE: sheetname, 3, ffff>) no such error is given and the original loop works. Also the the start-to-end loop doesn't seem to work, it only uses the original loop. I guess this has something to do with how the script interpretates and trims that notetag?

    Thank you for the hard work you put on this! :kaojoy:
  10. if your sprite is 3 frames, than sheetname, 3 = 4th index being undefined.
    so you need to set 2 there.

    index are always 0 index for being 1, (same for actors) if your enemy sheet
    consist of 4 frames, the 3 should work.

    in that case, make a screenshot of the notetag + image you use to find the
    issue where you use it and where to pinpoint it.

    TSR is a very advance coder and knows what he is doing :)
  11. Aah, I got the start-to-end loop working by putting <ENEMY IMAGE: enemy_goblin1, 3,2> there, though it seems to work with any number used. Even 100 seems to work.
  12. Hello!

    @Shashmurin the goal was to use the same notetag without breaking previous settings. But apparently, I didn't retested without the third arguments. It's an overlook that I just fixed (check the new version on my itch).
    And yes, when using number, any value above 0 is considered true.
    For the default 'back and forth' you can use:
    <enemy image: filename, frame>
    or
    <enemy image: filename, frame, 0> *anything above 0 will turn the anim to 'start to end'
    or
    <enemy image: filename, frames, false> *actually, anything but 'true' is false

    NonexistentRPG said:
    Regarding the collapse bug: The updated code crashes my game instantly as I run it and I receive the error code TypeError Cannot set property "trim" of undefined.
    This was because of the above. The new version should work.

    NonexistentRPG said:
    I'm using some other plugins that alter the evade-code, but when I switch of TSR_SpriteEnemy the enemy is able to evade/miss without any issue.
    Yes, and if you turn those plugins off (or test my plugin in a blank project), you'll see that the evade effect works just fine. It's probably a matter of compatibility with those 'others plugins that alter evade', and since I have no info about them, I can't help further.

    NonexistentRPG said:
    I should add that I am using frontfacing sprites, if that matters. I noticed that in Sprite_Enemy.prototype.updateEvade = function() { there is no
    if ($gameSystem.isSideView()) so maybe that could be part of the problem?
    That's certainly not the problem. Beside you said the problem persist even after you disabled that method... That being said, it's indeed an overlook for the front view I will fix, but as it is now, it would only result in your sprite side stepping when evading instead of stepping back (which we would expect for front view).

    ***
    ShadowDragon said:
    f your sprite is 3 frames, than sheetname, 3 = 4th index being undefined.
    so you need to set 2 there.
    You're right about indexes, but the notetag check the number of frames per sprite sheet, so it's truly 3 for a 3 frames anim :p


    Hope that help.
    Regards
    TSR
  13. Ahh, that makes sense! Tested and everything seems to work as inteded! :kaojoy:
  14. TSR said:
    Yes, and if you turn those plugins off (or test my plugin in a blank project), you'll see that the evade effect works just fine. It's probably a matter of compatibility with those 'others plugins that alter evade', and since I have no info about them, I can't help further.
    Welp, then I'm at a loss. I put it in a blank project and as you said it worked. I systematically added different plugins but couldn't figure out which one has the compatebility issue.

    The only plugin that I use that should affect evasion is SuperFrontViewMZ by Awaya_Matana which also enables the sprites to move forward/evade. However when I put the two of them together in a blank project they don't seem to clash.

    My biggest fear is that it is some VisuStella plugin that is causing the issue, as I've heard they encrypt all their code, which makes it impossible for me to alter it.

    The quick-fix "commenting out" doesn't seem to work either. As stated before, Evasion works on enemies with no notetags related to your script even when the script is enabled, so there is something with that goes awry when an enemy has an animated sprite. Funnily enough commenting out line 811 works in the blank project...

    For now I've done the really rudimentary solution to ad -100 evasion rate on all my enemies (which is fine since the game is more about surviving patterns than using chance), but hopefully I can find a solution somehow in the future.

    If there's any interest, here is a list of all plugins I'm currently using:
    PluginsUsed.png

    Regardless, Thank you for the help you've given thus far!
  15. Hello again @NonexistentRPG
    I see... I can't really tell where the incompatibility come from out of this bunch of plugins...
    That said, the line 811 simply disabled the evasion visual effect itself (the sprite stepping backward) and not the 'enemy effect' per se (that's why it still work after removing the line).
    Since I didn't had any details on the bug I target the most downstream method of the process. Obviously the incompatibility comes from upstream.
    If you comment out the 'this.requestEffect("evade")' on line 414 in the performEvasion method of Game_Enemy, that would completely remove any effect of my plugin on evasion. That should make a better fix than setting the evasion to -100 for all enemies.

    Regards
  16. Any chance of making compatability with VisuMZ_Battle Core? BattleCore does something to spritesheet, that ruins function on SpriteEnemy, and I wonder, if this can be fixed (I found nothing in debug of BattleCore which could fix it on it's own)

    Also I wonder, if it possible to make additional enemy graphics (them shaking on hit and stepping forward to do a hit) a config function, because I like how simple plugin is to use, but I don't like additional animations. This also makes me think, if it's possible, to expand skill row, to include different animations for different skills?

    (Goblin sprite was just to test how it works, since I couldn't managed to make it work with my own sprites, but I need to figure out how to make it work with VisuMS_BattleCore first)
  17. Hello @Jobhob
    I guess VS have their own animated enemy battler plugin, and it's probably why their battle core is conflicting with my plugin. I heard they obfuscate their code so there's little I can do.

    Jobhob said:
    Also I wonder, if it possible to make additional enemy graphics (them shaking on hit and stepping forward to do a hit) a config function, because I like how simple plugin is to use, but I don't like additional animations. This also makes me think, if it's possible, to expand skill row, to include different animations for different skills?
    Possible. By adding more code. That's why the code is open and edits are permitted.
    I personnaly don't have time to add more feature to this plugin at the moment.

    Regards,
    TSR
  18. Hello there,

    First, thanks to @TSR for this incredible plugin. I've been fooling around with it and found that my main boss (which had "bossColapse" enabled) when killed the game enter a loop.
    The issue has to do with the dimensions of the sprite.

    It can be solved by adjusting the startBossCollapse function like:

    JavaScript:
    Sprite_Enemy.prototype.startBossCollapse = function() {
        if (this.bitmap.height && this._motionLenght) {
            this._effectDuration = this._enemy._animated ?
                    Math.round(this.bitmap.height / this._motionLenght) : this.bitmap.height;
        } else {
            this._effectDuration = 0;
        }
        this._appeared = false;
    };