How to create/query hidden attributes for items/weapons/armor?

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
81
Reaction score
17
First Language
English
Primarily Uses
RMMV
I could sure use some help with this one: I'd like all items/weapons/armor in my game to have a hidden value that I'd like to assign to each, and then later on, to query and store as a variable.

I know that I could do it in an event with a massive conditional branch for each and every item in the game, but that feels horribly inefficient, especially if that event has to be run many times.

Does anyone have any thoughts as to what might be a good way to go about this?

Thank ya!
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,899
Reaction score
1,030
First Language
Dutch
Primarily Uses
RMMV
the best way that can be done is to make a plugin for it and use a scriptcall or plugin command when to show
the attribute. Otherwise, I have no clue how too.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
a lot depends on what exactly you want to do with those values.

for most cases, the use of a notetag and the meta function should be enough, that way you don't even need a plugin. But that would be a fixed value from the meta-tag that you can calculate with, but not change it. Check the help file for more on the meta function.
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
81
Reaction score
17
First Language
English
Primarily Uses
RMMV
So @Andar, I'm actually still having a bit of difficulty with the meta property in the notetag, though it sounds like EXACTLY what I need.

Here's my use case -- an NPC who will accept only items that are red in color. So, I'd like to be able to add a "red" property to all items that are red, and then have the NPC check that property before deciding to accept the item.

Additionally I would love to use the meta property to assign each item a "how red" value. Like, certain items are "more red" than others. Just a number, like from 1-10.

So the NPC would first check the meta property of the item for "is it red", and then be able to store "how red" to a variable.

I actually can't find any mention of the meta property in the official RPGMV help file (how terrific would it be to have a "search" function in that help file, yikes). I did find a few pages here that discuss it but it's a bit over my head I'm afraid. My use case is pretty straightforward and I don't need to change these tags, so I'm hoping I could get this working without a plugin or too much scripting knowledge.

Thanks again for your help!
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
I actually can't find any mention of the meta property in the official RPGMV help file
Documentation - Plugin Specifications

You need to know javascript to know how to use it, but you can use the appropiate variants in the script lines of control variable and conditional branches, which should be what you need to do.

Sorry, I can't give you any specifics because I never used it myself, you need to replace "object" of the example with the javascript equivalent of the RM-Object (database entry, each tab in the database has its own structure) that you want to read the metadata from.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,093
Reaction score
1,509
First Language
EN
Primarily Uses
RMMZ
Let's say item 5 in the database has this line in its notebox:
Code:
<red: 8>
I believe this'll get the value of the "red" meta-property for the item with ID stored in game variable 1. Control Variables > Script:
Code:
parseInt($dataItems[$gameVariables.value(1)].meta.red, 10) || 0
So, for example, if the value of var 1 is 5, the above expression should return the value 8 (because item 5 has a "red" value of 8). Then you can check the value using a normal Conditional Branch command etc~ :kaothx:

For weapons or armors, replace $dataItems with $dataWeapons or $dataArmors respectively. :kaophew:

Technical notes: parseInt converts to a number (notetag values are stored as strings) and || 0 means it'll return 0 if the value was "falsy" (i.e. not defined, not a number, or zero).
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
81
Reaction score
17
First Language
English
Primarily Uses
RMMV
@caethyril, I think I almost understand this about 95%, which is better than I thought I'd manage :LZSjoy:

My only question, before I go testing this, is about why it would be storing the value of the property to game var 1. Is there something special about variable 1 that I should be reserving it for stuff like this? Or is there nothing special about it, and I can manage to store that value in a different variable?

Thanks again to everyone for their help!

EDIT: So it works exactly as you said, @caethyril. That leaves just one thing remaining to make this NPC functional: how to store the Item# to that variable.

For instance, if the NPC calls a Select Item, and the player selects Item #5, how can I go about storing "5" to the variable?

It's a bit dizzying to my middle-aged brain but I'm getting there :LZSwink:

EDIT #2: Scratch that, I forgot how select item works -- stores the item number right to that variable :) Thaaaaank you, you folks rock! I'll update if I run across any additional problems that I can't puzzle through.

Also, this plugin would seem to have similar functionality, I'll test that also!
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,093
Reaction score
1,509
First Language
EN
Primarily Uses
RMMZ
Oh, yes, I used a variable (can use any variable, I just picked number 1 because it was there) to interface more cleanly with the Select Item command. :kaothx:

Good to hear you got it working, and that plugin does look useful! Happy RPG Making~ :kaojoy:
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
81
Reaction score
17
First Language
English
Primarily Uses
RMMV
Oh, yes, I used a variable (can use any variable, I just picked number 1 because it was there) to interface more cleanly with the Select Item command. :kaothx:

Good to hear you got it working, and that plugin does look useful! Happy RPG Making~ :kaojoy:
I did get it working :)

How might I store the value to a different var from one though? That's the part I still can't figure out ...
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,093
Reaction score
1,509
First Language
EN
Primarily Uses
RMMZ
I did get it working :)

How might I store the value to a different var from one though? That's the part I still can't figure out ...
If you're talking about my line of script: you can refer to a different variable by changing the number in the $gameVariables.value(1) part: just replace the 1 with the ID of the variable you want to reference. E.g. to use variable 52's value instead of variable 1, you can use this in Control Variables > Script:
Code:
parseInt($dataItems[$gameVariables.value(52)].meta.red, 10) || 0
:)

(To change the variable the item ID gets stored in, that's just an event command thing: simply select the appropriate variable from the list. :p)
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
81
Reaction score
17
First Language
English
Primarily Uses
RMMV
Gottttt it. Duh!

Thanks!
 

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

Latest Threads

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,881
Messages
1,017,227
Members
137,607
Latest member
Maddo
Top