Hi, I was undecided on where to post my request but in the end I preferred to write here.
I'm trying to modify the LadyBaskerville script to implement the ability to change the faces of heroes for the MOG_BattleCommands script.
Unfortunately I can't get it to work and I don't understand where I'm going wrong, can someone take a look at it please?
For testing I'm using this plugin command:
I put the script under spoilers:
Edit.
I managed to find a solution, I just posted the complete script in the original topic.
I'm trying to modify the LadyBaskerville script to implement the ability to change the faces of heroes for the MOG_BattleCommands script.
Unfortunately I can't get it to work and I don't understand where I'm going wrong, can someone take a look at it please?
For testing I'm using this plugin command:
Code:
change_bcom_face ACTOR_ID FILENAME
I put the script under spoilers:
JavaScript:
var LB = LB || {};
LB.MogHudExt = LB.MogHudExt || {};
(function() {
// ------------------
// Plugin Commands
// ------------------
LB.MogHudExt.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
LB.MogHudExt.Game_Interpreter_pluginCommand.call(this, command, args);
// Change Face
if (command == 'change_ahud_face') {
var actorId = Number(args[0]);
var faceFile = args[1].trim();
$gameActors.actor(actorId).changeAhudFace(faceFile);
}
if (command == 'change_bhud_face') {
var actorId = Number(args[0]);
var faceFile = args[1].trim();
$gameActors.actor(actorId).changeBhudFace(faceFile);
}
if (command == 'change_phud_face') {
var actorId = Number(args[0]);
var faceFile = args[1].trim();
$gameActors.actor(actorId).changePhudFace(faceFile);
}
if (command == 'change_bcom_face') {
var actorId = Number(args[0]);
var faceFile = args[1].trim();
$gameActors.actor(actorId).changeBcomFace(faceFile);
}
// Set Face
if (command == 'set_ahud_face') { // set_ahud_face [actorId] [stateId] [face]
var actorId = Number(args[0]);
var stateId = Number(args[1]);
var faceFile = args[2].trim();
$gameActors.actor(actorId).setAhudFace(stateId, faceFile);
}
if (command == 'set_bhud_face') { // set_bhud_face [actorId] [stateId] [face]
var actorId = Number(args[0]);
var stateId = Number(args[1]);
var faceFile = args[2].trim();
$gameActors.actor(actorId).setBhudFace(stateId, faceFile);
}
if (command == 'set_phud_face') { // set_phud_face [actorId] [stateId] [face]
var actorId = Number(args[0]);
var stateId = Number(args[1]);
var faceFile = args[2].trim();
$gameActors.actor(actorId).setPhudFace(stateId, faceFile);
}
if (command == 'set_bcom_face') { // set_bcom_face [actorId] [stateId] [face]
var actorId = Number(args[0]);
var stateId = Number(args[1]);
var faceFile = args[2].trim();
$gameActors.actor(actorId).setBcomFace(stateId, faceFile);
}
// Clear Face
if (command == 'clear_ahud_face') { // clear_ahud_face [actorId] [stateId]
var actorId = Number(args[0]);
var stateId = Number(args[1]);
$gameActors.actor(actorId).clearAhudFace(stateId);
}
if (command == 'clear_bhud_face') {
var actorId = Number(args[0]);
var stateId = Number(args[1]);
$gameActors.actor(actorId).clearBhudFace(stateId);
}
if (command == 'clear_phud_face') {
var actorId = Number(args[0]);
var stateId = Number(args[1]);
$gameActors.actor(actorId).clearPhudFace(stateId);
}
if (command == 'clear_bcom_face') {
var actorId = Number(args[0]);
var stateId = Number(args[1]);
$gameActors.actor(actorId).clearBcomFace(stateId);
}
};
// ------------------
// Game Actor
// ------------------
Game_Actor.prototype.parseMogHudExtNotetags = function(actorId) {
// default faces
this._ahudFaces = [];
if ($dataActors[actorId].meta.AHudFace) {
this._ahudFaces[0] = $dataActors[actorId].meta.AHudFace.trim();
} else {
this._ahudFaces[0] = "Face_" + actorId;
}
this._bhudFaces = [];
if ($dataActors[actorId].meta.BHudFace) {
this._bhudFaces[0] = $dataActors[actorId].meta.BHudFace.trim();
} else {
this._bhudFaces[0] = "Face_" + actorId;
}
this._phudFaces = [];
if ($dataActors[actorId].meta.PHudFace) {
this._phudFaces[0] = $dataActors[actorId].meta.PHudFace.trim();
} else {
this._phudFaces[0] = "Face_" + actorId;
}
this._bcomFaces = [];
if ($dataActors[actorId].meta.BComFace) {
this._bcomFaces[0] = $dataActors[actorId].meta.BComFace.trim();
} else {
this._bcomFaces[0] = "Face_" + actorId;
}
// state faces
var notes = $dataActors[actorId].note.split("\n");
var aStatesRegexp = /<AHudFace State (\d+) *: *([^ ]+) *>/;
var bStatesRegexp = /<BHudFace State (\d+) *: *([^ ]+) *>/;
var pStatesRegexp = /<PHudFace State (\d+) *: *([^ ]+) *>/;
var cStatesRegexp = /<BComFace State (\d+) *: *([^ ]+) *>/;
for (var i = 0; i < notes.length; i++) {
var match = notes[i].match(aStatesRegexp);
if (match) {
this._ahudFaces[Number(match[1])] = match[2];
}
match = notes[i].match(bStatesRegexp);
if (match) {
this._bhudFaces[Number(match[1])] = match[2];
}
var match = notes[i].match(pStatesRegexp);
if (match) {
this._phudFaces[Number(match[1])] = match[2];
}
var match = notes[i].match(cStatesRegexp);
if (match) {
this._bcomFaces[Number(match[1])] = match[2];
}
}
};
LB.MogHudExt.Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function(actorId) {
LB.MogHudExt.Game_Actor_setup.call(this, actorId);
this.parseMogHudExtNotetags(actorId);
this._ahud_face_file = this._ahudFaces[0];
this._bhud_face_file = this._bhudFaces[0];
this._phud_face_file = this._phudFaces[0];
this._bcom_face_file = this._bcomFaces[0];
};
Game_Actor.prototype.setAhudFace = function(stateId, faceFile) {
this._ahudFaces[stateId] = faceFile;
this.updateAhudFace();
};
Game_Actor.prototype.clearAhudFace = function(stateId) {
if (stateId !== 0) {
this._ahudFaces[stateId] = null;
this.updateAhudFace();
}
};
Game_Actor.prototype.setBhudFace = function(stateId, faceFile) {
this._bhudFaces[stateId] = faceFile;
this.updateBhudFace();
};
Game_Actor.prototype.clearBhudFace = function(stateId) {
if (stateId !== 0) {
this._bhudFaces[stateId] = null;
this.updateBhudFace();
}
};
Game_Actor.prototype.setPhudFace = function(stateId, faceFile) {
this._phudFaces[stateId] = faceFile;
this.updatePhudFace();
};
Game_Actor.prototype.clearPhudFace = function(stateId) {
if (stateId !== 0) {
this._phudFaces[stateId] = null;
this.updatePhudFace();
}
};
Game_Actor.prototype.setBcomFace = function(stateId, faceFile) {
this._bcomFaces[stateId] = faceFile;
this.updateBcomFace();
};
Game_Actor.prototype.clearBcomFace = function(stateId) {
if (stateId !== 0) {
this._bcomFaces[stateId] = null;
this.updateBcomFace();
}
};
Game_Actor.prototype.changeAhudFace = function(faceFile, noSetDefault) {
if (noSetDefault === undefined) {
this.setAhudFace(0, faceFile);
}
if (this._ahud_face_file != faceFile) {
this._ahud_face_file = faceFile;
if (Imported.MOG_ActorHud && SceneManager._scene.constructor == Scene_Map) {
//SceneManager._scene._actorHud.refresh_bhud();
var actorHud = SceneManager._scene._actorHud;
actorHud._face.bitmap = ImageManager.loadAHud(this._ahud_face_file);
}
}
};
Game_Actor.prototype.changeBhudFace = function(faceFile, noSetDefault) {
if (noSetDefault === undefined) {
this.setBhudFace(0, faceFile);
}
if (this._bhud_face_file != faceFile) {
this._bhud_face_file = faceFile;
if (Imported.MOG_BattleHud && SceneManager._scene.constructor == Scene_Battle) {
//SceneManager._scene.refreshBattleHud();
var battleHud = SceneManager._scene._battle_hud;
battleHud.forEach(function(bhud) {
if (bhud._battler && bhud._battler._actorId === this._actorId) {
bhud.refresh_bhud();
}
}, this);
}
}
};
Game_Actor.prototype.changePhudFace = function(faceFile, noSetDefault) {
if (noSetDefault === undefined) {
this.setPhudFace(0, faceFile);
}
if (this._phud_face_file != faceFile) {
this._phud_face_file = faceFile;
if (Imported.MOG_PartyHud && SceneManager._scene.constructor == Scene_Map) {
//SceneManager._scene.refreshPartyHud();
var partyHud = SceneManager._scene._partyHud;
partyHud.forEach(function(phud) {
if (phud._actor && phud._actor._actorId === this._actorId) {
phud.refreshFace();
}
}, this);
}
}
};
Game_Actor.prototype.changeBcomFace = function(faceFile, noSetDefault) {
if (noSetDefault === undefined) {
this.setBcomFace(0, faceFile);
}
if (this._bcom_face_file != faceFile) {
this._bcom_face_file = faceFile;
if (Imported.MOG_BattleCommands && SceneManager._scene.constructor == Scene_Battle) {
//SceneManager._scene.refreshBattleHud();
var battleCommands = SceneManager._scene._face;
battleCommands.forEach(function(bcom) {
if (bcom._battler && bcom._battler._actorId === this._actorId) {
bcom.refresh_bcom();
}
}, this);
}
}
};
Game_Actor.prototype.updateMogExtFaces = function() {
if (this._ahud_face_file) this.updateAhudFace();
if (this._bhud_face_file) this.updateBhudFace();
if (this._phud_face_file) this.updatePhudFace();
if (this._bcom_face_file) this.updateBcomFace();
};
Game_Actor.prototype.updateAhudFace = function(stateId, faceFile) {
var states = this._states;
for (var i = 0; i < states.length; i++) {
if (this._ahudFaces[states[i]]) {
this.changeAhudFace(this._ahudFaces[states[i]], true);
return;
}
}
this.changeAhudFace(this._ahudFaces[0], true);
};
Game_Actor.prototype.updateBhudFace = function(stateId, faceFile) {
var states = this._states;
for (var i = 0; i < states.length; i++) {
if (this._bhudFaces[states[i]]) {
this.changeBhudFace(this._bhudFaces[states[i]], true);
return;
}
}
this.changeBhudFace(this._bhudFaces[0], true);
};
Game_Actor.prototype.updatePhudFace = function(stateId, faceFile) {
var states = this._states;
for (var i = 0; i < states.length; i++) {
if (this._phudFaces[states[i]]) {
this.changePhudFace(this._phudFaces[states[i]], true);
return;
}
}
this.changePhudFace(this._phudFaces[0], true);
};
Game_Actor.prototype.updateBcomFace = function(stateId, faceFile) {
var states = this._states;
for (var i = 0; i < states.length; i++) {
if (this._bcomFaces[states[i]]) {
this.changeBcomFace(this._BcomFaces[states[i]], true);
return;
}
}
this.changeBcomFace(this._bcomFaces[0], true);
};
LB.MogHudExt.Game_Actor_addNewState = Game_Actor.prototype.addNewState;
Game_Actor.prototype.addNewState = function(stateId) {
LB.MogHudExt.Game_Actor_addNewState.call(this, stateId);
this.updateMogExtFaces();
};
LB.MogHudExt.Game_Actor_eraseState = Game_Actor.prototype.eraseState;
Game_Actor.prototype.eraseState = function(stateId) {
LB.MogHudExt.Game_Actor_eraseState.call(this, stateId);
this.updateMogExtFaces();
};
// ------------------
// Battle Hud
// ------------------
if (Imported.MOG_BattleHud) {
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(this._battler._bhud_face_file));
this._face.anchor.x = 0.5;
this._face.anchor.y = 0.5;
this._face_data = [0, 0, false, false, false, -1];
this._face.ph = 0; //add
this._face.animation = [-1, 0, 0, 0, 0, 0, 0, 0, 0]; //add
this._face.breathEffect = this._battler._bhud.faceBreath; //add
this._face.scaleY = 0; //add
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);
};
}
// ------------------
// Party Hud
// ------------------
if (Imported.MOG_PartyHud) {
PartyHud.prototype.createFace = function() {
var fileName = "Face_" + this._actor._actorId;
this._face = new Sprite(ImageManager.loadPartyHud(this._actor._phud_face_file));
this._face.x = this._layout.x + Number(Moghunter.partyHud_FaceX);
this._face.y = this._layout.y + Number(Moghunter.partyHud_FaceY);
this.refreshFace();
this.addChild(this._face);
};
PartyHud.prototype.refreshFace = function() {
this._face.bitmap = ImageManager.loadPartyHud(this._actor._phud_face_file);
};
}
// ------------------
// Actor Hud
// ------------------
if (Imported.MOG_ActorHud) {
Actor_Hud.prototype.create_face = function() {
if (String(Moghunter.ahud_face_visible) != "true") {return};
this.removeChild(this._face);
if (!this._battler) {return};
this._face = new Sprite(ImageManager.loadAHud(this._battler._ahud_face_file));
this._face.anchor.x = 0.5;
this._face.anchor.y = 0.5;
this._face_data = [0,0,false,false,false,-1];
if (String(Moghunter.ahud_face_shake) === "true") {this._face_data[2] = true}
if (String(Moghunter.ahud_face_animated) === "true") {this._face_data[4] = true}
this._battler._ahud_face_data = [0,0,0,0]
this.addChild(this._face);
};
}
// ------------------
// Battle Commands
// ------------------
if (Imported.MOG_BattleCommands) {
Window_ActorCommand.prototype.create_face = function () {
if (this._face) {this.removeChild(this._face)};
var fname = String("Face_" + this._actor._actorId)
var face_img = ImageManager.loadBcom(fname);
this._face = new Sprite(ImageManager.loadBcom(this._battler._bcom_face_file));
this._face.x = Moghunter.bcom_face_x;
this._face.y = Moghunter.bcom_face_y;
this.addChild(this._face);
};
}
})();
Edit.
I managed to find a solution, I just posted the complete script in the original topic.