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,857
Reaction score
5,435
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

I found a book about game localization. It costs R$708,00 on Amazon. ;_;
I really wish my game was far enough along for it to be actually playable beyond certain aspects. I think I've crafted a really fun battle system thanks to ATB, fighting game, and Boost point mechanics.
Play test of my current progress on Happy Camper
Cutscene Contest Winners have been announced!

I'm heading back to Orlando tomorrow! My dad and I have forgiven each other, so we're planning to spend Spring Break together. We'll probably go to SeaWorld and Aquatica one day, and maybe even use my air fryer to make something to go with Dad's grilled steak. The train leaves tomorrow, and I'll be working on my game on board!

Forum statistics

Threads
109,110
Messages
1,042,177
Members
141,608
Latest member
Sinthea
Top