RMMV (SOLVED) Need help with Yanfly Item_Core Remove Use Function

Status
Not open for further replies.

Kirye

Developing Luminera: The Radiant Journey
Member
Joined
Jan 15, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'm slowly but surely learning my Javascript, but i'm having way too many issues with this code. I'm trying to modify this:

JavaScript:
Scene_Item.prototype.onItemOk = function() {
    var item = this.item();
    if (DataManager.isItem(this._item))  {
        this.onActionUse();
        } else {
        this._itemActionWindow.setItem(item);
        }; 
};

So that when you're on the Item Menu and select a consumable item, it won't open the window asking you to confirm that you would like to use an item and instead immediately open the character profiles

1653095379426.png

1653095418005.png


Before I found a snippet of code that removed the action window altogether, but the problem with that is that if you select a weapon the game will immediately crash. So I was hoping I could set up an if statement that would use "this.onActionUse();" when the object is an Item, and ActionWindow if it's a Weapon or Armor.

Unfortunately the code isn't recognizing if something is an item, and is opening the ActionWindow regardless of what I use. Best case scenario, using an item will go straight to ActionUse and pressing Okay on Armor/Weapons should just return an error sound effect and nothing else.

Some help would be greatly appreciated! Hope I was clear enough.

Thanks!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,512
Reaction score
2,875
First Language
English
Primarily Uses
RMMV
You had the right idea, but you're using the wrong method.

DataManager.isItem() returns true if the argument is a database item - that is, an object of type Item.

What you're selecting in the menu is an object of type UsableItem..

So you want to try:
Code:
if (item.itypeId==1) this.onActionUse();

Note that this will prevent you from using the custom actions that the plugin offers, but I'm presuming you're not using those.
 

Kirye

Developing Luminera: The Radiant Journey
Member
Joined
Jan 15, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
You had the right idea, but you're using the wrong method.

DataManager.isItem() returns true if the argument is a database item - that is, an object of type Item.

What you're selecting in the menu is an object of type UsableItem..

So you want to try:
Code:
if (item.itypeId==1) this.onActionUse();

Note that this will prevent you from using the custom actions that the plugin offers, but I'm presuming you're not using those.

That worked! Thank you so much!

I don't mean to keep annoying you after helping me out, but would you know what I could change in the script so instead of the use command opening it just does nothing on the "else" branch?

If not, no worries! This already helped a lot!

EDIT: Nevermind, I figured it out! Thanks for the help Turan!

If anyone gets stuck with this particular problem, here's how I resolved it.

JavaScript:
Scene_Item.prototype.onItemOk = function() {
    var item = this.item();
    if (item.itypeId==1) {this.onActionUse();
        } else {
        Yanfly.Item.Scene_Item_onItemCancel.call(this);
        this._statusWindow.setItem(null);
        this._infoWindow.setItem(null);
        }; 
};

It cancels out back to the ItemCategory menu which isn't 'super' ideal, but it works! No longer will I have to see the "Use" command when it should have been an optional feature of Item_Core.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,512
Reaction score
2,875
First Language
English
Primarily Uses
RMMV
would you know what I could change in the script so instead of the use command opening it just does nothing on the "else" branch?...No longer will I have to see the "Use" command when it should have been an optional feature of Item_Core.
I'm a little confused. You'd only see that if you intentionally scroll from the Items to a different category and select a Weapon/Armor/Key Item. And if you know (as the designer) that none of those item types have a Use action attached to them, why would you ever scroll into that category and select one? It seems to me, logically, you never "have" to see the Use at this point :stickytongue:

But if that's what you want...why do you bother having an else branch? Just leave the rest of that function blank, and it will simply do nothing if someone tries to select/activate one of those item types.

If that's not ideal...what would be? You could look up the function calls to go to the equip menu, I suppose.
 

Kirye

Developing Luminera: The Radiant Journey
Member
Joined
Jan 15, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'm a little confused. You'd only see that if you intentionally scroll from the Items to a different category and select a Weapon/Armor/Key Item. And if you know (as the designer) that none of those item types have a Use action attached to them, why would you ever scroll into that category and select one? It seems to me, logically, you never "have" to see the Use at this point :stickytongue:

But if that's what you want...why do you bother having an else branch? Just leave the rest of that function blank, and it will simply do nothing if someone tries to select/activate one of those item types.

If that's not ideal...what would be? You could look up the function calls to go to the equip menu, I suppose.
If you selected a weapon without the else it just freezes in place afterwards. I know not to press it, but a random player wouldn't. :p
 

BlackGoldSaw

Veteran
Veteran
Joined
Oct 10, 2017
Messages
91
Reaction score
50
First Language
English
Primarily Uses
RMMV
If anyone gets stuck with this particular problem, here's how I resolved it.

JavaScript:
Scene_Item.prototype.onItemOk = function() {
    var item = this.item();
    if (item.itypeId==1) {this.onActionUse();
        } else {
        Yanfly.Item.Scene_Item_onItemCancel.call(this);
        this._statusWindow.setItem(null);
        this._infoWindow.setItem(null);
        };
};

It cancels out back to the ItemCategory menu which isn't 'super' ideal, but it works! No longer will I have to see the "Use" command when it should have been an optional feature of Item_Core.
If you still need it, you can replace this:
JavaScript:
Yanfly.Item.Scene_Item_onItemCancel.call(this);
With this:
JavaScript:
this._itemWindow.activate();
When I did it that way it didn't freeze OR cancel out to the ItemCategory Menu.
 

Kirye

Developing Luminera: The Radiant Journey
Member
Joined
Jan 15, 2017
Messages
9
Reaction score
1
First Language
English
Primarily Uses
RMMV
If you still need it, you can replace this:
JavaScript:
Yanfly.Item.Scene_Item_onItemCancel.call(this);
With this:
JavaScript:
this._itemWindow.activate();
When I did it that way it didn't freeze OR cancel out to the ItemCategory Menu.
Awesome, thanks for the help! Both of you!
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
16,621
Reaction score
9,217
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Kes
Let me ask you this - when was the last time you backed up? Can you afford to lose all the progress you've made since the last backup?
Just asking.
Working on fun ways to get around the Midnight Circus level! Cannons were a given :LZSlol:

apolloblastoff.gif

Forum statistics

Threads
123,077
Messages
1,153,803
Members
161,406
Latest member
Tree_of_Topaz
Top