Battle: Change face sprite if battler is affected by state?

jjleroy

I love bananas
Veteran
Joined
Aug 5, 2017
Messages
184
Reaction score
34
First Language
German, English
Primarily Uses
RMMV
Good morning dear RPG Maker community,

today a rather tricky one:

I would like to change Moghunter's Battle HUD in a way that the battler's face (which are saved as pngs named face_1, face2, face 3,...) is tinted if she is affected by state x, for example asleep, like this:



I tried this:

Code:
if ($gameActors.actor(3).isStateAffected(6) && this._face.spriteId == 513) {
this._face.tint = 200, 200, 1, 0 , 1
};
and it does work, BUT when my actor switches the party members mid-battle, the spriteIds change and it doesn't work anymore.

So what I need is something like...
if ($gameActors.actor(3).isStateAffected(6))
{this._face sprite of actor 3.tint = 200, 200, 1, 0 , 1;}

But how can I do that?

Code:
var _alias_mog_bhud_gbat_initMembers = Game_BattlerBase.prototype.initMembers
Game_BattlerBase.prototype.initMembers = function() {
    _alias_mog_bhud_gbat_initMembers.call(this);
    this.need_refresh_bhud_states = false;
    this._bhud_face_data = [0,0,0,0];
    this._face_pos = [0,0];
};

//=============================================================================
// ** Game Action
//=============================================================================

//==============================
// * Apply
//==============================
var _alias_mog_bhud_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function(target) {
    var oldhp = target.hp
    _alias_mog_bhud_apply.call(this,target);
    if (target.isActor()) {
        if (oldhp > target.hp) {target._bhud_face_data = [30,20,3,30]}
        else if (oldhp < target.hp) {target._bhud_face_data = [0,20,1,30]};
    };
};
//=============================================================================
// ** Game Actor
//=============================================================================

//==============================
// * Gain HP
//==============================
var _alias_mog_bhud_gainHp =Game_Actor.prototype.gainHp;
Game_Actor.prototype.gainHp = function(value) {
    _alias_mog_bhud_gainHp.call(this,value);
    this._bhud_face_data[3] += 1;
};
//=============================================================================
// ** Sprite Actor
//=============================================================================

//==============================
// * Initialize
//==============================
var _alias_bhud_sprt_actor_initialize = Sprite_Actor.prototype.initialize
Sprite_Actor.prototype.initialize = function(battler) {
    _alias_bhud_sprt_actor_initialize.call(this,battler);
    this._sprite_face = false;
    if (String(Moghunter.bhud_face_visible) === "true") {this._sprite_face = true};
};

//==============================
// * Damage Offset X
//==============================
Sprite_Actor.prototype.damageOffsetX = function() {
    if (!$gameSystem.isSideView() && this._sprite_face) {return 0};
    return -32;
};

//==============================
// * update Position
//==============================
var _alias_mog_bhud_sprt_actor_updatePosition = Sprite_Battler.prototype.updatePosition;
Sprite_Battler.prototype.updatePosition = function() {
    if (!$gameSystem.isSideView() && this._sprite_face) {
        if (this._battler && $gameTemp._bhud_position[this._battler.index()]) {
             this.x = $gameTemp._bhud_position[this._battler.index()][0] + Moghunter.bhud_face_pos_x;
           this.y = $gameTemp._bhud_position[this._battler.index()][1] + Moghunter.bhud_face_pos_y;
           return;
        };
    };
    _alias_mog_bhud_sprt_actor_updatePosition.call(this);
};

//==============================
// * Setup Animation
//==============================
var _alias_mog_bhud_sprt_actor_setupAnimation = Sprite_Battler.prototype.setupAnimation;
Sprite_Actor.prototype.setupAnimation = function() {
    if (!$gameSystem.isSideView() && this._sprite_face) {
    while (this._battler.isAnimationRequested()) {
        var data = this._battler.shiftAnimation();
        var animation = $dataAnimations[data.animationId];
        var mirror = data.mirror;
        var delay = animation.position === 3 ? 0 : data.delay;
        this.startAnimation(animation, mirror, delay);
        for (var i = 0; i < this._animationSprites.length; i++) {
            var sprite = this._animationSprites[i];
            sprite.visible = true;
        }
    }
    return;
    };
    _alias_mog_bhud_sprt_actor_setupAnimation.call(this);
};

//==============================
// * Refresh Position
//==============================
Battle_Hud.prototype.refresh_position = function() {
    this.set_hud_position();   
    this.create_sprites();
    this._layout.x = this._pos_x;
    this._layout.y = this._pos_y;
    if (this._face) {
        this._face.x = this._pos_x + Moghunter.bhud_face_pos_x;
         this._face.y = this._pos_y + Moghunter.bhud_face_pos_y;
     };
    if (this._turn) {
        this._turn.x = this._pos_x + (this._turn.width / 2) + Moghunter.bhud_turn_pos_x;
        this._turn.y = this._pos_y + (this._turn.height / 2) + Moghunter.bhud_turn_pos_y;
    };
        if (this._turni) {
        this._turni.x = this._pos_x + (this._turni.width / 2) + Moghunter.bhud_turni_pos_x;
        this._turni.y = this._pos_y + (this._turni.height / 2) + Moghunter.bhud_turni_pos_y;
    };
    if (this._layout2) {
          this._layout2.x = this._pos_x + Moghunter.bhud_layoverlay_x;
         this._layout2.y = this._pos_y + Moghunter.bhud_layoverlay_y;
     };
    if (this._face) {this._battler._face_pos = [this._face.x,this._face.y]};
};

//==============================
// * Create Sprites
//==============================
Battle_Hud.prototype.create_sprites = function() {
    this.create_hp_meter();
    this.create_mp_meter();
    this.create_tp_meter();
    this.create_at_meter();
    if (String(Moghunter.bhud_layoverlay_visible) == "true") {this.create_layoutOverlay()};
    this.create_hp_number();
    this.create_maxhp_number();
    this.create_mp_number();
    this.create_maxmp_number();
    this.create_tp_number();
    this.create_maxtp_number();
    this._stateType = Number(Moghunter.bhud_statesType);
    if (this._stateType === 0) {
        this.create_states();
    } else {
        this.create_states2();
    };
    this.create_name();
};

//==============================
// * Update Sprites
//==============================
Battle_Hud.prototype.update_sprites = function() {
    this.update_active();
    this.update_visible();
    this.update_turn();
    this.update_turni();
    this.update_face();
    this.update_hp();
    this.update_mp();
    this.update_tp();
    this.update_at();
    if (this._state_icon) {
        if (this._stateType === 0) {
             this.update_states();
        } else {
            this.update_states2();
        };
    };
};

//==============================
// * Create Face
//==============================
Battle_Hud.prototype.create_face = function() {
    if (String(Moghunter.bhud_face_visible) != "true") {return};
    this.removeChild(this._face);
    if (!this._battler) {return};
    this._face = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId));
    this._face.anchor.x = 0.5;
    this._face.anchor.y = 0.5;
    this._face_data = [0,0,false,false,false,-1];
    if (String(Moghunter.bhud_face_shake) === "true") {this._face_data[2] = true}
    if (String(Moghunter.bhud_face_animated) === "true") {this._face_data[4] = true}
    this._battler._bhud_face_data = [0,0,0,0]
    this.addChild(this._face);

//==============================
// * Update Face
//==============================
Battle_Hud.prototype.update_face = function() {
    if (!this._face) {return};
    if (!this._face.bitmap.isReady()) {return};
    if (this._face_data[4] && this._face_data[5] != this._battler._bhud_face_data[2]) {this.refresh_face();};
    this.update_face_animation();
    this.update_face_shake();
    this.update_face_zoom();
};

//==============================
// * Refresh Face
//==============================
Battle_Hud.prototype.refresh_face = function() {
    this._face_data[5] = this._battler._bhud_face_data[2];
    var cw = this._face.bitmap.width / 5;
    var ch = this._face.bitmap.height;
    this._face.setFrame(cw * this._face_data[5], 0, cw, ch);
};
 

jjleroy

I love bananas
Veteran
Joined
Aug 5, 2017
Messages
184
Reaction score
34
First Language
German, English
Primarily Uses
RMMV
OK I found the solution.

//==============================
// * Update Face
//==============================
Battle_Hud.prototype.update_face_animation = function() {

if (this._battler.isDead()) {this._face.tint = 86, -85, -68, 0 , 1;}

if (this._battler.isStateAffected(6)) {this._face.tint = 86, -85, -68, 0 , 1;}

But now I am struggling with how to remove the state tint once the state is removed?
 
Last edited:

furan

Villager
Member
Joined
May 10, 2018
Messages
19
Reaction score
0
First Language
English
Primarily Uses
RMMV
OK I found the solution.

//==============================
// * Update Face
//==============================
Battle_Hud.prototype.update_face_animation = function() {

if (this._battler.isDead()) {this._face.tint = 86, -85, -68, 0 , 1;}

if (this._battler.isStateAffected(6)) {this._face.tint = 86, -85, -68, 0 , 1;}

But now I am struggling with how to remove the state tint once the state is removed?
You could do the opposite at the very end.
Like
if (!this._battler.isStateAffected(6) && ... && !this._battler.isDead()) // remove the face tint
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top