Check if a specific set of weapons is owned by the party

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
Hello, let's say I'd like to create a conditional branch where the condition is the ownership of a given armor among a group.
Let's say party has weapon nr. 5,6,7, 9,24 and 37. I'd like to check if nr. 6 is owned. Another option I'd like would be : I'd like to check if 8 or 9 or 24 is owned.

Is there a simple way?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
you can use control variable to get the number of weapons/equipment/items in inventory for anything in the database, and you can check with multiple conditional branches in AND sequence if a certain combination is there.
and for OR you can just rearrange the conditional branches to an OR sequence, or any combination of AND/OR - that is just a logic structure of event commands.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
too much complicated, I've more than 200 weapons
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
it doesn't matter how much weapons you have - you always need to be able to pinpoint to which weapon to use. And that always comes down to selecting the weapon no matter how.

if you want to handle that selection by giving an ID-number you can simply look up the script equivalent of that section of control variable in the pinned topic about the script equivalent commands, but that doesn't change the fact that you'll need one single command for each weapon you want to check.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
I mean, maybe I've explained in a bad way.

Let's hypothesize I have 200 weapons in my database.

Now, I'd like a teleport to be teleporting the player to a map, if he has (in inventory, equipped or not) one of the weapons with
ID 1, 2, 5, 6, 15, 66, 102, 103, 104, 105

and to another different map if it has weapons with
ID 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 16, 44, 195

and to another map if it has any other weapon.

How can I optimize this avoiding to write any single conditional branch in the teleport event?

I was thinking to something like:

Script code within the event --> assign every weapon ID of the party to a variable
Then --> checks if the variable is within the previous sets of numbers
Then --> activate a different teleport


something like:

Code:
$gameVariables.setValue(1, $data.weaponID)
var num=[1,2,5,6,15,66,102,103,104,105];
if = to var num 
then teleport

But I can't get how to write it in the game code
 
Last edited:

pawsplay

Veteran
Veteran
Joined
Mar 29, 2012
Messages
397
Reaction score
137
First Language
English
Primarily Uses
RMMV
I think that would just be a three branch condition. The first IF is if the inventory of any of these certain items is > 0. I would just do it that way.
If you wanted to script this, you would just assign a note tag for each condition to each item, and then you would check if any item in the inventory has tag 1, tag 2, or tag 3. I can't really think of anything this approach gains you unless your equipment list is still very much not final.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
yes the note tag in the item box is the best idea and approach; how can I check if any item in the inventory has a specific tag? is it a script code or a pre-constructed plugin call from a plugin?
thank you

This is from Ruby, but don't think it would work similarly in MV which is Javascript

Code:
class RPG::BaseItem
  def read_notetags
    if @note =~ /<seed (.*)>/i
      @seed = eval("lambda {  |event| $1.to_i } ")
      return
    end
  end
end

class Game_Event
  def run_notetag(item)
    item.seed.call(self)
  end
end


I think that would just be a three branch condition. The first IF is if the inventory of any of these certain items is > 0. I would just do it that way.
If you wanted to script this, you would just assign a note tag for each condition to each item, and then you would check if any item in the inventory has tag 1, tag 2, or tag 3. I can't really think of anything this approach gains you unless your equipment list is still very much not final.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
read the help file on plugin specifications - it explains the meta function that is used to check for notetags
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV

I've read this, but I just need to see how to check meta notetag from dataWeapons of Party basically

Code:
$gameParty.Item($dataWeapons, /<\s*Strenght\s*:\s*(\d+\.*\d*)\s*>/ig;
if meta[Strenght !==1] {
 $gameVariables.setValue(1, 1)};
if meta[Strenght !==2] {
 $gameVariables.setValue(1, 2)};
if meta[Strenght !==3] {
 $gameVariables.setValue(1, 3)};
})
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
your code is nonsense on many levels - for example you don't need any regex when using the meta function of the engine, and you can't have comparisons inside array index and more.

please show what the notetags are in your items, then we can help you make the correct code for identifying the items.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
Let's say 5 ranks of notetags:

<Strenght: 1>
<Strenght: 2>
...
<Strenght: 5>
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
then the comparison if one item has the notetag is done with

$dataitem[ID].meta.strength === 'data';

with 'data' being the info on the notetag, for example '1' or '2'
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
Thank you!
Then, to check if there is at least 1 weapon in the inventory with Strenght 1 (or in other words: if strenght 1 weapons is > 0), how would that conditional branch script be made?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
it can't be done in a conditional branch, because you need to loop through every weapon.
you need to make a loop that checks for every existing weapon if it has a notetag with that data, and if the party owns one or more of those weapons.
if yes you can mark a switch or count a variable in the loop, and the conditional branch can then check that result.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
yes, can't figure the script to be put in the conditional branch anyway
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,064
Reaction score
2,376
First Language
EN
Primarily Uses
RMMZ
Maybe Conditional Branch -> Script:

$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, 10) >= 1; }); });
I.e. "true iff at least 1 party member has at least 1 weapon equipped that is tagged with <Strenght: X>, where X is 1 or more". Other cases:
  • Check equipped armors: replace weapons() with armors()
  • Check all equipment: replace weapons() with equips()
Also, the correct English spelling would be Strength, not sure if that's a typo.

I used the Array#some method for loops here, technical details:
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
Thank you!! will try it :D
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
So I've tried a lot, but it looks to work only if I make:

Weapon Notetag:
Code:
<Strenght: 11>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, 11) >= 1; }); });

If I instead try one of the following (1 to 6 examples below), it doesn't work:

1)
Weapon Notetag:
Code:
<Strenght: 1>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, 1) >= 1; }); });

2)
Weapon Notetag:
Code:
<Strenght: 10>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, 10) >= 1; }); });

3)
Weapon Notetag:
Code:
<Strenght: 5>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, 5) >= 1; }); });

4)
Weapon Notetag:
Code:
<Strenght: Strong>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Strenght, Strong) >= 1; }); });

5)
Weapon Notetag:
Code:
<Power: Super>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Power, Super) >= 1; }); });

6)
Weapon Notetag:
Code:
<Power: 5>
Conditional branch:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && parseInt(item.meta.Power, 5) >= 1; }); });
 

pawsplay

Veteran
Veteran
Joined
Mar 29, 2012
Messages
397
Reaction score
137
First Language
English
Primarily Uses
RMMV
Do you want the party to be able to access certain areas only after acquiring certain equipment, and lose that ability if they later sell or discard that equipment? It would be easier to help with this if I understood the desired game behavior.
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
228
Reaction score
58
First Language
English
Primarily Uses
RMMV
yes exactly, but more specifically i need the condition within the conditional branch as a meta check, because weapons will have different features and conditions is not only the id number. The previous method was nice, but somehow it doesn't work with every number or meta
 

Latest Threads

Latest Profile Posts

1.6 update incoming with quality breakthrough! :kaoluv:

1643254634071.png
I might try the mechanical bull at the fair on Friday... for one of the challenges, if you stay on for two minutes, you win $200. I might give that a try and see if I win--I'm pretty good at holding on to things.
Remaking a more streamlined version of my Remote Move map skill in MZ, just one switch and one variable to handle everything. If you seen the Move skill in Golden Sun before, moving far away items with your mind is pretty cool

MZtestRemoteMove.gif
I don't want to brag or anything but I was entertaining a woman the other night. I told her jokes while she bandaged my foot.
Okay so, I'm using this script, right? And it works. If you press :Y a menu should come up allowing you to choose an item to use. Nothing happens. You press :A to open the event options menu and choose "Use an Item"? The item selection menu appears. I have no idea how I set this up or why it works the way it does. Absolutely bizarre.

Forum statistics

Threads
118,733
Messages
1,118,327
Members
155,887
Latest member
dashenlingyu
Top