RMMV YEP_X_EquipRequirements

Pootscooter

Veteran
Veteran
Joined
Jun 7, 2020
Messages
115
Reaction score
62
First Language
Mandarin
Primarily Uses
RMMV
Hello, I'm trying to check if the selected equipment slot is a certain slot. By slot, I mean the slot #, not the slot type. (i.e. user.equips()[0] would refer to the 1st slot). Basically, I want to say:
Code:
<Custom Equip Requirement Condition>
if ("the selected slot is the 2nd slot") {
  condition = false
} else {
  condition = true
}
</Custom Equip Requirement Condition>
Doing it by slot type won't work due to dual wielding turning the 2nd slot into the same type as the 1st slot. Checking if a certain weapon/armor type is equipped won't work either since there are loopholes w/ that method (I've tried it).
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,772
Reaction score
1,192
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi!
I don't know if I get it right, but it seems that you want to see if the player is equipping something in a specific slot?
If so, assuming that the "user" refers to the $gameActors:
$gameActors.actor(id).equips()[slotNumber] === $dataWeapons[weaponId]
This will return true if the player is equipping that weapon in the specified slotNumber.

Is that it? Or is something specific of this plugin?
 

Pootscooter

Veteran
Veteran
Joined
Jun 7, 2020
Messages
115
Reaction score
62
First Language
Mandarin
Primarily Uses
RMMV
I don't know if I get it right, but it seems that you want to see if the player is equipping something in a specific slot?
Sorry, actually I already know how to do what you suggested, but it's not what I'm looking for. I need to check what the slot the player is about to put the equipment into is a certain slot #. You know how you select which slot you want 1st then pick the equipment to put in? I'm looking for the code to reference the active/selected slot.

The $gameActors.actor(id).equips()[slotNumber] you mentioned is essentially the same as user.equips()[0]. It's basically what I'm using now:
JavaScript:
<Custom Equip Requirement Condition>
if (user.equips()[1]) {
  condition = false;
} else {
  condition = true;
}
</Custom Equip Requirement Condition>
I mentioned checking by weapon/armor type like in your example as loopholes. For instance, if you have a 1H (a weapon w/ the DW trait) in both slots (slot 0 & 1) and then you won't be able to use a 2H (a weapon w/ the <Custom Equip Requirement Condition> code I pasted above. So that works so far, however, if you have a single 1H equipped in slot 0 and empty in the other weapon slot (slot 1), the player is able to equip the 2H into the second weapon slot. This is one of the loopholes I mentioned. If I add another conditional like so:
JavaScript:
<Custom Equip Requirement Condition>
if (user.equips()[1] || user.isDualWield) {
  condition = false;
} else {
  condition = true;
}
</Custom Equip Requirement Condition>
This helps, but it also prevents the player from equipping a 2H if they only have a single 1H equipped. The player would have to remove the 1H weapon 1st before being able to equip the 2H, which does not provide for a good player experience.

The best way I can think of is to simply check if the selected/active slot (the slot the player is trying to put the equipment into) is slot #1 (aka the 2nd slot).
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,819
Reaction score
1,581
First Language
English
Primarily Uses
RMMV
Damn, I was trying to figure this out months ago and never found a solution... If anyone figures it out, please reply!:kaothx:

I noticed the loopholes too when I used OP's method a couple of months back. However, if someone figures out how to check the active/selected equipment slot to put in the equip requirement conditional, that would pretty much solve it!

Try: https://capnrammo.itch.io/
 
Last edited:

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
587
Reaction score
243
First Language
english
Primarily Uses
RMMV
should look into ramza's dual wield plugin.
it has tags so can make some weapons main hand only and off hand only equips.
also has tags specific for 2H weapons and arm mounted shields (equipable even when using a 2H weapon)
also compatable with action sequences so can make some skills only use the offhand weapon for the attack, as well as some other interesting ways to change how dual wielding works.
(like a way to make main and offhand attack seperately using only the main hands atk stat for the 1st hit and only use the offhand weapons atk stat for the 2nd hit)
 

Pootscooter

Veteran
Veteran
Joined
Jun 7, 2020
Messages
115
Reaction score
62
First Language
Mandarin
Primarily Uses
RMMV
I already tried Ramza's DW plugin, it's not compatible w/ LTBS. So, I would really appreciate it if someone could please just tell me the script to reference the selected/active slot. All I need is that tiny bit of code, thank you!

I imagine the solution may be hiding somewhere in here:
(something to do w/ slotId perhaps?)
JavaScript:
//-----------------------------------------------------------------------------
// Window_EquipSlot
//
// The window for selecting an equipment slot on the equipment screen.

function Window_EquipSlot() {
    this.initialize.apply(this, arguments);
}

Window_EquipSlot.prototype = Object.create(Window_Selectable.prototype);
Window_EquipSlot.prototype.constructor = Window_EquipSlot;

Window_EquipSlot.prototype.initialize = function(x, y, width, height) {
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._actor = null;
    this.refresh();
};

Window_EquipSlot.prototype.setActor = function(actor) {
    if (this._actor !== actor) {
        this._actor = actor;
        this.refresh();
    }
};

Window_EquipSlot.prototype.update = function() {
    Window_Selectable.prototype.update.call(this);
    if (this._itemWindow) {
        this._itemWindow.setSlotId(this.index());
    }
};

Window_EquipSlot.prototype.maxItems = function() {
    return this._actor ? this._actor.equipSlots().length : 0;
};

Window_EquipSlot.prototype.item = function() {
    return this._actor ? this._actor.equips()[this.index()] : null;
};

Window_EquipSlot.prototype.drawItem = function(index) {
    if (this._actor) {
        var rect = this.itemRectForText(index);
        this.changeTextColor(this.systemColor());
        this.changePaintOpacity(this.isEnabled(index));
        this.drawText(this.slotName(index), rect.x, rect.y, 138, this.lineHeight());
        this.drawItemName(this._actor.equips()[index], rect.x + 138, rect.y);
        this.changePaintOpacity(true);
    }
};

Window_EquipSlot.prototype.slotName = function(index) {
    var slots = this._actor.equipSlots();
    return this._actor ? $dataSystem.equipTypes[slots[index]] : '';
};

Window_EquipSlot.prototype.isEnabled = function(index) {
    return this._actor ? this._actor.isEquipChangeOk(index) : false;
};

Window_EquipSlot.prototype.isCurrentItemEnabled = function() {
    return this.isEnabled(this.index());
};

Window_EquipSlot.prototype.setStatusWindow = function(statusWindow) {
    this._statusWindow = statusWindow;
    this.callUpdateHelp();
};

Window_EquipSlot.prototype.setItemWindow = function(itemWindow) {
    this._itemWindow = itemWindow;
};

Window_EquipSlot.prototype.updateHelp = function() {
    Window_Selectable.prototype.updateHelp.call(this);
    this.setHelpWindowItem(this.item());
    if (this._statusWindow) {
        this._statusWindow.setTempActor(null);
    }
};
And here's the same section Yanfly's EquipCore:
JavaScript:
//=============================================================================
// Window_EquipSlot
//=============================================================================

Yanfly.Equip.Window_EquipSlot_setActor = Window_EquipSlot.prototype.setActor;
Window_EquipSlot.prototype.setActor = function(actor) {
    this.setSlotNameWidth(actor);
    Yanfly.Equip.Window_EquipSlot_setActor.call(this, actor);
};

Window_EquipSlot.prototype.refresh = function() {
    if (this._actor) this._actor.refresh();
    Window_Selectable.prototype.refresh.call(this);
};

Window_EquipSlot.prototype.isEnabled = function(index) {
    if (this._actor) {
      return Yanfly.Equip.Game_Actor_isEquipChangeOk.call(this._actor, index);
    } else {
      return false;
    }
};

Window_EquipSlot.prototype.drawItem = function(index) {
    if (!this._actor) return;
    var rect = this.itemRectForText(index);
    this.changeTextColor(this.systemColor());
    this.changePaintOpacity(this.isEnabled(index));
    var ww1 = this._nameWidth;
    this.drawText(this.slotName(index), rect.x, rect.y, ww1);
    var ww2 = rect.width - ww1;
    var item = this._actor.equips()[index];
    if (item) {
      this.drawItemName(item, rect.x + ww1, rect.y, ww2);
    } else {
      this.drawEmptySlot(rect.x + ww1, rect.y, ww2);
    }
    this.changePaintOpacity(true);
};

Window_EquipSlot.prototype.setSlotNameWidth = function(actor) {
    if (!actor) return;
    this._nameWidth = 0;
    for (var i = 0; i < actor.equipSlots().length; ++i) {
      var text = $dataSystem.equipTypes[actor.equipSlots()[i]] + ' ';
      this._nameWidth = Math.max(this._nameWidth, this.textWidth(text));
    }
};

Window_EquipSlot.prototype.drawEmptySlot = function(wx, wy, ww) {
    this.changePaintOpacity(false);
    var ibw = Window_Base._iconWidth + 4;
    this.resetTextColor();
    this.drawIcon(Yanfly.Icon.EmptyEquip, wx + 2, wy + 2);
    var text = Yanfly.Param.EquipEmptyText;
    this.drawText(text, wx + ibw, wy, ww - ibw);
};

Window_EquipSlot.prototype.setInfoWindow = function(infoWindow) {
    this._infoWindow = infoWindow;
    this.update();
};

Yanfly.Equip.Window_ItemList_updateHelp = Window_EquipSlot.prototype.updateHelp;
Window_EquipSlot.prototype.updateHelp = function() {
    Yanfly.Equip.Window_ItemList_updateHelp.call(this);
    if (SceneManager._scene instanceof Scene_Equip && this._infoWindow) {
      this._infoWindow.setItem(this.item());
    }
};
 
Last edited:

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
832
Reaction score
525
First Language
English
Primarily Uses
RMMV
Actually the equipment swapping stuff works fine with LTBS, it's the multiple hits and damage splitting that doesn't exactly work. Although @Frostorm has been making it work slowly.

Anyways, you could probably do this by checking against SceneManager._scene._slotWindow._index. This is the index value of the currently selected slot in the equipslot window. If it's 0, that's your weapon slot, 1, shield slot, etc.

I don't know how often the equip requirements plugin actually checks for changes to the requirements, so it might not work. And if it checks those requirements when the equip scene isn't on screen, well, that probably won't work either, so you'd need a series of ifs to make sure the current scene is the equip scene first.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,819
Reaction score
1,581
First Language
English
Primarily Uses
RMMV
Yep can confirm, anything out of combat works just fine.

Edit: Using what @ramza posted, I've come up w/ something if you just want DW to work in the equip menu... (you'll want to give 1H weapons the DW trait btw, and the following goes on 2H weapons)
JavaScript:
<Custom Equip Requirement Condition>
if (user.equips()[1]) {
  condition = false;
} else if (SceneManager._scene._slotWindow) { //This is to avoid "TypeError: Cannot read property '_index' of undefined"
  if (SceneManager._scene._slotWindow._index == 1) {
    condition = false;
  } else {
    condition = true;
  }
} else {
  condition = true;
}
</Custom Equip Requirement Condition>
If anyone wants to improve upon this, feel free to do so!

Using if (user.equips()[1] || SceneManager._scene._slotWindow._index == 1) also works perfectly fine, but you'll find the error I mention above even if the player won't see it. I'm of the belief that it's good practice to run error-free code, whenever possible. It occurs in the background while the player is outside the equip scene, where _index (aka the selected slot doesn't exist).
 
Last edited:

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
832
Reaction score
525
First Language
English
Primarily Uses
RMMV
If anyone wants to improve upon this, feel free to do so!

Using if (user.equips()[1] || SceneManager._scene._slotWindow._index == 1) also works perfectly fine, but you'll find the error I mention above even if the player won't see it. I'm of the belief that it's good practice to run error-free code, whenever possible. It occurs in the background while the player is outside the equip scene, where _index (aka the selected slot doesn't exist).
Without my plugin you could use use the below notetags to check against whether the weapon is being placed into the main or offhand slot.
JavaScript:
<Custom Equip Requirement Condition>
    //weapon can only be placed in the offhand
    condition = (SceneManager._scene.constructor.name === "Scene_Equip" && SceneManager._scene._slotWindow._index == 1)
</Custom Equip Requirement Condition>
<Custom Equip Requirement Condition>
    //weapon can only be placed in the mainhand
    condition = (SceneManager._scene.constructor.name === "Scene_Equip" && SceneManager._scene._slotWindow._index == 0)
</Custom Equip Requirement Condition>
You could add the check at the beginning of Frostorm's code to see if a weapon is being held in the offhand already or not, to prevent the two handed weapon from being equipped, but you could also use something like @waynee95 's CustomOnEquipEval plugin to automatically remove the offhand weapon if a two-handed one is put in the mainhand too. This stuff is built in to the dual wield plugin, though, if you already have that.
 

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

Latest Threads

Latest Profile Posts

My computer broke yesterday, so no RPG maker for at least a week until I can get it repaired. :(
Just wanted to share how my game won 1st place in a game jam for itch.io. Everyone else used Unreal, Unity, GMS2, Godot, etc but I used RPG Maker 2003 :guffaw: It just shows that you can create a good game and it doesn't matter which engine you use
Working on cutscenes~

if your game is the first (or ONLY) in a series and still has a colon in its title, you are a bad person and I hate you...... jk.

who could ever hate BETWEEN: TWO SOULS?

Forum statistics

Threads
107,405
Messages
1,029,444
Members
139,504
Latest member
lobsterknees
Top