Weapon Type Conditions

TheObermotz1

Veteran
Veteran
Joined
Mar 5, 2014
Messages
34
Reaction score
17
First Language
German
Primarily Uses
Sorry for troubling you folks, but I've run into a problem, I can't solve on my own.
The situation is the following:

In my current project I want to include crates/chests that have to be pried open, before they can be lootet. The way it's supposed to work, is a condition checking if anyone in the party has any 'light weapons' or 'heavy weapons' (those are some of my weapon types) equipped and then either open the crate/chest or telling the player, that they need an appropriate weapon.
It shouldn't matter, who is carrying the weapon (as long as it's somebody in the current party) or what exact weapon it is (as long as it's a 'light weapon' or 'heavy weapon').

However, the vanilla conditions can only check if a certain character is carrying a certain weapon (instead of a weapon type).

If anyone knows a way around this, i'd be much obliged. A script that activates a switch, if a weapon is being equiped could do the trick, but I'm open to every kind of suggestion.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,262
Reaction score
7,138
First Language
German
Primarily Uses
RMMV
Most likely you have to use conditional branches instead of conditions.
That means the event is always triggered and then checks for every actor in the party if one of those weapons is equipped.

Most likely that will require a script line, but you can check what is possible in game data section of control variables as well - sometimes you can load the data you want into a variable there and then check the variable.
I have no RM near to check unfortunately.
 

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
You can use this script in the script box of a conditional to check if an actor has weapon type x equipped.

$game_actors[id].equips[0].wtype_id == x

If you want to check by party member's index instead of actor id this should work:

$game_party.members[index].equips[0].wtype_id == x
 

TheObermotz1

Veteran
Veteran
Joined
Mar 5, 2014
Messages
34
Reaction score
17
First Language
German
Primarily Uses
$game_party.members[index].equips[0].wtype_id == x
That certainly looks promising. However, I have trouble getting it to work; it makes the game crash.

Script 'Game_Interpreter' line 450: NoMethodError occured.
undefined method 'equips' for nil:NilClass


Am I doing something wrong?
 

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
Yeah, I should have mentioned that you need to check if they have anything equipped at all. If they don't have any weapon at all equipped that will happen. This should work. This is for the first party member. Index 0.

$game_party.members[0].equips[0] && $game_party.members[0].equips[0].wtype_id == x
 

TheObermotz1

Veteran
Veteran
Joined
Mar 5, 2014
Messages
34
Reaction score
17
First Language
German
Primarily Uses
$game_party.members[0].equips[0] && $game_party.members[0].equips[0].wtype_id == x
Ah, yes. Now we're getting somewhere. But two problems came up:

1. A chain of conditions with your skript (with Index 0-3 for all 4 party members) still crashes the game, if there are less than 4 members in the party. The same goes for a chain that only counts for 3 party members, with a party without 3 members.

2. The chain of conditions (just a long 'if-else' chain) still only checks the first party member and ignores the rest. Party members 2, 3 & 4 could be armed to the teeth, but the crate only cares if the leady carries a weapon.

I'm not used to working with skripts in RPG Maker, so I'd be much obliged if you could help me out one more time.
 

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
What you should do is set a variable to the number of party members. Like this:

$game_party.members.count

Then make a loop variable equal to 0. Then you have to use the loop variable in place of the party member index. It would be like this for game variable 19 as loop variable:

$game_party.members[$game_variables[19]].equips[0] && $game_party.members[$game_variables[19]].equips[0].wtype_id == 2

Add 1 to loop variable for each iteration and when the loop variable is equal to the members.count variable, break loop.

Here's a link to an example, though some is cut off. Assuming the link works.

https://photos.app.goo.gl/EWneDHBV7Vg1A8Bn9
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
638
Reaction score
416
First Language
English
Primarily Uses
RMVXA
I would actually do this in a conditional branch:
Code:
!($game_party.members.select { |m| m.equips[0] && m.equips[0].wtype_id == 2 }).empty?
If you just want to check the battle members, you can do:
Code:
!($game_party.battle_members.select { |m| m.equips[0] && m.equips[0].wtype_id == 2 }).empty?
Basically, that iterates through each member of the party and checks whether they have a weapon equipped and if said weapon has a weapon type ID of 2. Much neater in my opinion.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,291
Reaction score
6,048
First Language
Indonesian
Primarily Uses
RMVXA
Why not like this? (If you want ANY of party members has wtype = 2)
Code:
$game_party.members.any? { |m| m.equips[0] && m.equips[0].wtype_id == 2 }
or (If you want ALL of party members has wtype = 2)
Code:
$game_party.members.all? { |m| m.equips[0] && m.equips[0].wtype_id == 2 }
*adding more confusion*
 

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

Latest Threads

Latest Profile Posts

Chaos17 wrote on Poryg's profile.
Hi, I am following your videos tutorials serie about coding on MV and I am at the third video. Thank you for making it but's a bit hard to follow since you don't show the whole plugin at the end. I had to screenshot the lines between 110-159 because you scrolled so fast on them.
:rtear:
I'm not sure if I should be happy for MZ, or sad for MV.
Not going to lie.... The update's cool and all, but I immediately ran to Mog's site and was like, "Update! Update! Update!" while breathing on the page of his Star Ocean Battle System plugin. :kaoswt:
Ho boi. I can already see the storm of ugly actor faces RTP customizable facesets from MZ are gonna flood. XD
<-- Meet Seith. He begins the story as an apprentice druid, learning to survive in the wilderness by communing with nature and honing his herbalism. Seith has a deep desire to understand the world around him. When wells of chaotic energy begin erupting from the land,corrupting plant, animal and man alike, Seith finds himself on a journey to discover just what this means for the fate of his home, the land of Myarr.

Forum statistics

Threads
99,463
Messages
965,681
Members
131,073
Latest member
James1998
Top