MZ Converting HUD Maker State Cycling to a Window Function

Hey all,

I am working with a script in HUDMaker that i think @caethyril (?) helped me with


Spoiler: Icon Cycling Script
const actor = $gameParty.members()[0]; // leader
const states = actor?.states().filter(state => state.id !== 2); // Filter out Guard state (ID 2)
if (states && states.length > 0) { // Ensure there are states to process
const icons = states.map(state => state.iconIndex);
if (icons.length === 1) {

return icons[0]; // Only one icon, return it without cycling

}
const c = icons.length; // icon count
const t = 60; // frames per icon
const f = Graphics.frameCount % (c * t); // time loop of c * t duration
const currentIndex = Math.floor(f / t);
return icons[currentIndex]; // Return the current icon
} else {
return null; // No states, return null or a default value
}


In battle this works just fine, it cycles throuuggh the battlers states in order and omits the state i don't want it to show. What i'm looking to do is apply this same sort of icon cycling within a window. Rather than the traditional way drawActorIcons works. The problem is Window_MenuStatus wouuld only uupdate the icons while the window is activated and being interacted with.


Does anyone have a Window_Base or Window_StatusBase function handy that can handle drawing a sequence of icons refreshing on its own?
The typical "self-updating icon cycle" thing is Sprite_StateIcon (rmmz_sprites.js). The default battle status window uses the placeStateIcon method of Window_StatusBase to create one of those as an inner child sprite for each actor (rmmz_windows.js):
JavaScript:
Window_StatusBase.prototype.placeStateIcon = function(actor, x, y) {
This method is also available to Window_MenuStatus due to inheritance. So you could write a plugin to make the menu status add these, e.g. (untested):
JavaScript:
;void (alias => {
  Window_MenuStatus.prototype.drawItem = function(index) {
    alias.apply(this, arguments);
    const r = this.itemRect(index);  // display area for this index
    const x = r.x;       // left edge
    const y = r.y + 25;  // top edge plus 25 px
    this.placeStateIcon(this.actor(index), x, y);
  };
})(Window_MenuStatus.prototype.drawItem);
Those coordinates are probably awful, but they're only meant as a placeholder.

(As for your source...looks like an elaboration of the code I posted over here?)
(As for your source...looks like an elaboration of the code I posted over here?)
Yes, That is where i stole it from! I couldnt find the original post. Did sp,e tweakingg to prevent "Guard" status from showing


I'll try throwing this.placeStateIcon into the function thats running my other draws. Will report back!

Thats perfect! Thanks @caethyril !
This thread is closed due to being reported as solved. If you need it reopened, report it to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/converting-hud-maker-state-cycling-to-a-window-function.176008/