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,855
Reaction score
5,429
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 Profile Posts

I just lost an hour plus of time to trying to modify the _battlefield sprite... when in reality MZ calls it _battleField ;_;

Even when debugging for the "undefined value", it looked exactly the same to my 20/60 eyesight.

I really prefer this_naming_convention rather than thisNamingConvention !!
hmm... I just solved one of the more annoying sideview battler problems in MV.. Passive States and Visual States can make it so when your character is in crisis HP, they don't go back to normal walk/wait when it's their turn. they stay in the crisis motion... neat.
Apparently all of LGBT reddit hates me. I posted a simple question and only got hate mail. What's the deal? The doompost was literally 6 months ago and I've changed my views since then and apologized.
MOD NOTE: See second response before replying to this. - Wavelength
Amazing. Simply amazing...

JRPG Browser - Playlist:

Forum statistics

Threads
109,100
Messages
1,042,037
Members
141,585
Latest member
CiderV
Top