MV Add skill window on map? Maybe modify Yanfly MapSelectSkill?

Hey all,

So in my current project I have equippable guns that can be reloaded (Is it okay if I share a link to that thread?). A great QoL suggestion came up from a friend of mine when talking about the original Fallout 1 & 2 in that there should be a display on screen showing ammo count and a way to reload the gun easily without diving into the skills menu. The ugly answer I came up with was to make a Common Event Button (another Yanfly plugin) that would bring up the map select skill plugin window. The player can then select the skill.

I'm wonder if I can (and if it's allowed?) to modify the MapSelect Skill to the following. Or how to build such a window without it. I'm still a novice at code and mostly can just piece together pre-existing snippets from online when I do, so go easy on me please.
  1. Only show the window when a gun is equipped (I'll probably use a switch or a state to check for this since it's easier).
  2. Show the shoot and reload skills for the equipped gun and their skill cost info (shoot shows the Limited Use info, Reload is a custom item cost of a gold formula and then total gold).
  3. Make the window non-interactable.
  4. Do not let the window take focus. It's just passively open.
  5. Reduce the size of the window to a small box in the corner.
Doing it this way, I would then just have a Button Common Event to trigger a reload (I think I know how to make this happen).
Since you have several specific requirements, you're probably better off with a custom window than trying to adapt a more generalized plugin.

Your profile says MV, so I assume this is for MV. You can use the following code as a plugin and you'll get a window that looks like this:

mv_mapwindow.png


JavaScript:
//-----------------------------------------------------------------------------
// New: Window_MapSkill
//-----------------------------------------------------------------------------
function Window_MapSkill() {
    this.initialize.apply(this, arguments);
}
Window_MapSkill.prototype = Object.create(Window_SkillList.prototype);
Window_MapSkill.prototype.constructor = Window_MapSkill;
Window_MapSkill.prototype.initialize = function(x, y, width, height) {
    Window_SkillList.prototype.initialize.call(this, x, y, width, height);
    this._stypeId = 0;
    this._data = [];
    this.width = 250;
    this.height = this.fittingHeight(3);
    this.x = Graphics.boxWidth - this.width - this.padding;
    this.y = Graphics.boxHeight - this.height - this.padding;
};
Window_MapSkill.prototype.maxCols = function() {
    return 1;
};
//-----------------------------------------------------------------------------
// Scene_Map
//-----------------------------------------------------------------------------
let MapSkill_Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function() {
    MapSkill_Scene_Map_createAllWindows.call(this);
    this.createMapSkillWindow();
};
Scene_Map.prototype.createMapSkillWindow = function() {
    let actor = $gameActors.actor(1);
    this._mapSkillWindow = new Window_MapSkill();
    this._mapSkillWindow.setActor(actor);
    this._mapSkillWindow.setStypeId(1);
    this.addChild(this._mapSkillWindow);
};
let MapSkill_Scene_Map_CallMenu = Scene_Map.prototype.callMenu;
Scene_Map.prototype.callMenu = function() {
    MapSkill_Scene_Map_CallMenu.call(this);
    this._mapSkillWindow.hide();
};

From there, the window can be refined further to display what kind of skill information you want to handle at different times.

If you can provide some more details, I can probably get the window a bit closer to what you are looking for. For example, hiding or showing the window based on whether or not a certain actor is equipped with a specific weapon or specific equipment type ID.

I'm also not sure how you are associating certain skills with certain weapons, so if you can elaborate on that, that would be helpful.
@Kenen This works beautifully already! Thanks!

Skill types works, because I can categorize all my gun skills as "Reloadable" as a multi-skill, and these just pop up! So this seems to be correct already once I changed the skill id to 8 here.

The only actor who can equip guns is in slot 1 (and this cannot be changed by the player), so that part is already correct.

All of the guns are categorized as weapon type 2, so that's probably the best way to check if a gun is equipped. I was gonna ask where I can stick an "if", but you seem like a pro so let me know :hswt:

EDIT: Oh, I forgot. Is there a way to make this refresh more often? Say, after an event? It didn't seem to increase when I looted some "gold" after hitting a chest.
@woootbm No problem!

I updated the code a bit based on the extra information in your reply and some (very) limited testing on my end. The window will hide if Actor 1 is not equipped with a weapon of type 2, and it should refresh if Actor 1's weapon changes or the party's gold changes. If you think of any other circumstances that should trigger a refresh, let me know!

Also, let me know if you have any issues. I have mostly worked on battle-related things for MZ, so it's very likely there's something I wouldn't have thought to add to this. 😅

JavaScript:
//-----------------------------------------------------------------------------
// New: Window_MapSkill
//-----------------------------------------------------------------------------
function Window_MapSkill() {
    this.initialize.apply(this, arguments);
}
Window_MapSkill.prototype = Object.create(Window_SkillList.prototype);
Window_MapSkill.prototype.constructor = Window_MapSkill;
Window_MapSkill.prototype.initialize = function(x, y, width, height) {
    Window_SkillList.prototype.initialize.call(this, x, y, width, height);
    this._stypeId = 0;
    this._data = [];
    this.width = 250;
    this.height = this.fittingHeight(3);
    this.x = Graphics.boxWidth - this.width - this.padding;
    this.y = Graphics.boxHeight - this.height - this.padding;
    this._visible = true;
    this._gold = $gameParty._gold;
    this._weapon = null;
};
Window_MapSkill.prototype.setActor = function(actor) {
    Window_SkillList.prototype.setActor.call(this, actor);
    this._weapon = actor._equips[0];
}
Window_MapSkill.prototype.maxCols = function() {
    return 1;
};
Window_MapSkill.prototype.weaponType = function() {
    return 2;
}
Window_MapSkill.prototype.shouldShow = function() {
    if (!this._visible || $gameMessage.isBusy()) {
        return false;
    } else {
        return this._actor.isWtypeEquipped(this.weaponType());
    }
}
Window_MapSkill.prototype.show = function() {
    Window_SkillList.prototype.show.call(this);
    this.refresh();
}
Window_MapSkill.prototype.refresh = function() {
    Window_SkillList.prototype.refresh.call(this);
    this._gold = $gameParty._gold;
    this._weapon = this._actor.equips[0];
}
Window_MapSkill.prototype.needsRefresh = function() {
    if (this._gold !== $gameParty._gold || this._weapon !== this._actor.equips[0]) return true;
}
//-----------------------------------------------------------------------------
// Scene_Map
//-----------------------------------------------------------------------------
let MapSkill_Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function() {
    MapSkill_Scene_Map_createAllWindows.call(this);
    this.createMapSkillWindow();
};
Scene_Map.prototype.createMapSkillWindow = function() {
    let actor = $gameActors.actor(1);
    this._mapSkillWindow = new Window_MapSkill();
    this._mapSkillWindow.setActor(actor);
    this._mapSkillWindow.setStypeId(1);
    this.addChild(this._mapSkillWindow);
};
let MapSkill_Scene_Map_Stop = Scene_Map.prototype.stop;
Scene_Map.prototype.stop = function() {
    MapSkill_Scene_Map_Stop.call(this);
    this._mapSkillWindow._visible = false;
    this._mapSkillWindow.hide();
}
let MapSkill_Scene_Map_Update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
    MapSkill_Scene_Map_Update.call(this);
    this.updateSkillWindow();
}
Scene_Map.prototype.updateSkillWindow = function() {
    this.updateSkillWindowVisibility();
    this.updateSkillWindowRefresh();
}
Scene_Map.prototype.updateSkillWindowVisibility = function() {
    let window = this._mapSkillWindow;
    if (window.visible && !window.shouldShow()) {
        window.hide();
    } else if (!window.visible && window.shouldShow()) {
        window.show();
    }
}
Scene_Map.prototype.updateSkillWindowRefresh = function() {
    let window = this._mapSkillWindow;
    if (window.needsRefresh()) {
        window.refresh();
    }
}
@Kenen Amazing! This plugin works like a charm. Please excuse the ugly placeholder assets and mapping, just wanted to show off how it looks with the screenshot below.

Thanks so much!

1650993524328.png
You're welcome! It looks great. Feel free to PM me if the plugin causes any issues or if you need something tweaked. :ahappy:
Spoiler: Original post
@Kenen Whoops, I just realized the total doesn't pick up on changing my gold amount by spending it at a vendor. Which is weird, because things like using the party menu and changing equipment usually do.

Although maybe that's a problem with the skill's custom cost, which looks like this:

<Custom Requirement> user._goldCost = Math.floor(20 * (1 - (a.def * 0.15))); value = user.skillLimitedUseCurrent(25) < user.skillLimitedUseMax(25) && $gameParty.gold() > user._goldCost; </Custom Requirement> <Custom Execution> $gameParty.loseGold(user._goldCost); </Custom Execution> <Cost Display Eval> user._goldCost = Math.floor(20 * (1 - (a.def * 0.15))); $gameVariables.setValue(4, user._goldCost); </Cost Display Eval> <Custom Cost Display> \fs[20]\v[4]/\v[7]\I[218] </Custom Cost Display>

I hope there's a way to get this to refresh on exiting the vendor :hswt:


EDIT: Nevermind, I'm an idiot. I updated this skill with a bit that involves variable 7, and did not make this update for every gun. You can even see in what I pasted that v7 is called but there is no v7 😐
EDIT: Nevermind

Everything working the way you want, then? Just let me know if not and I'll try to take a look at it for you. :ahappy:

Original thread: https://forums.rpgmakerweb.com/threads/add-skill-window-on-map-maybe-modify-yanfly-mapselectskill.147086/