RMMZ Getting a single enemy to shake when hit(Solved)

Heis

Warper
Member
Joined
Jan 20, 2021
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMZ
Hello! I've been trying to get enemies to shake when you hit them in battle. With TheoAllen's blessing I was able to modify a plugin he wrote for screenshake to do just that.

The problem is that ALL enemies shake when you hit them, and they even shake when they hit you!

Can someone help me figure out how to make it so only the enemy who was hit, shakes?

JavaScript:
var Theo = Theo || {}
Theo.Shake = {}
Theo.Shake.gameTemp_init = Game_Temp.prototype.initialize;
Game_Temp.prototype.initialize = function(){
Theo.Shake.gameTemp_init.call(this);
this.shake_maxdur = 0;
this.shake_dur = 0;
this.shake_pow = 0;
}
Game_Temp.prototype.shake_screen = function(power, duration){
this.shake_maxdur = duration;
this.shake_dur = duration;
this.shake_pow = power;
}
Theo.Shake.spritesetEnemy_updatePos = Sprite_Enemy.prototype.updatePosition;
Sprite_Enemy.prototype.updatePosition = function(){
Theo.Shake.spritesetEnemy_updatePos.call(this);
if($gameTemp.shake_dur > 0){
$gameTemp.shake_dur -= 1;
let rate = $gameTemp.shake_dur/$gameTemp.shake_maxdur;
this.x += Math.random() * $gameTemp.shake_pow * rate * (Math.random() >= 0.5 ? 1 : -1);
this.y += Math.random() * $gameTemp.shake_pow * rate * (Math.random() >= 0.5 ? 1 : -1);
}
}

Sprite_Battler.prototype.setupDamagePopup = function() {
if (this._battler.isDamagePopupRequested()) {
if (this._battler.isSpriteVisible()) {
this.createDamageSprite();
$gameTemp.shake_screen(10, 45);
}
this._battler.clearDamagePopup();
this._battler.clearResult();
}
};
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,853
Reaction score
5,424
First Language
English
Primarily Uses
RMVXA
Hey! It sounds like you're probably comfortable with syntax and JS basics, so here's the outline of what you need to do:
1) Alias the initMembers method of Sprite_Enemy to create the property this.shake_dur for Sprite_Enemy, and get rid of it within the Game_Temp alias in the code you've shown; you can also create this.shake_maxdur and this.shake_pow within Sprite_Enemy if you want these to be different for each Enemy Sprite
2) Change all references of $gameTemp.shake_dur (within Sprite_Enemy or Sprite_Battler methods) to this.shake_dur (and do the same for shake_maxdur and shake_pow IF you created them for Sprite_Enemy)
3) Create a copy of the shake_screen method for Sprite_Enemy - it can look exactly the same as the Game_Temp version (except remember to change $gameTemp.shake_dur to this.shake_dur)
4) Change the $gameTemp.shake_screen call to this.shake_screen inside the setupDamagePopup method; you can leave the arguments (10, 45) the same or - if you created the this.shake_maxdur and this.shake_pow properties for Sprite_Enemy you can set them to this.shake_pow and this.shake_maxdur instead!

Let me know with an @ if you have any trouble pulling that off.
 

Heis

Warper
Member
Joined
Jan 20, 2021
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMZ
Thank you Wavelength!
 

Latest Threads

Latest Posts

Latest Profile Posts

After so many hours of debugging, losing data to crashes, and slight adjustments.
BlackJack now deals cards perfectly! Time to adjust the background and implement the game logic so you can actually play it.BlackJack.png
I once thought about a boss gauntled game. I actually did it.
Stream will be live shortly with some Gex 3! Feel free to drop by!
Snippet from a game I'm working on. Not much happening here. Mostly look at atmosphere. May upload a longer version. Still need to make up some enemy arts.

Forum statistics

Threads
109,060
Messages
1,041,715
Members
141,550
Latest member
Leekit
Top