Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
As the title says, I'm trying to figure out and see how to check if an actor has an equipment type equipped. I've been using the script call
Code:
$gameActors.actor(actor_id).equips()[slot_id] == null;
but either I'm not using it right or it's not what i'm looking for. The actual code I'm using in my conditional branch is
Code:
$gameActors.actor(1).equips()[2] == 14;
"2" is the equipment type and "14" is the armor type. I don't really need to check the equipment type, the armor type is what's important.
 

Aloe Guvner

Walrus
Regular
Joined
Sep 28, 2017
Messages
1,627
Reaction score
1,201
First Language
English
Primarily Uses
RMMV
Can you open the console (press F8 during playtest to open it) and paste the following and press enter on your keyboard? What comes up?

Code:
$gameActors.actor(1).equips()[2]
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
164
First Language
Indonesian
Primarily Uses
N/A
Code:
$gameActors.actor(1).equips()
will return an array of equipment objects, not just the ID. You can use wTypeId for Weapon type ID and aTypeId for Armor type ID.
So your code will be something like this:
Code:
$gameActors.actor(1).equips()[2] && $gameActors.actor(1).equips()[2].aTypeId == 14
Actor 1 slot 3 equipment is not empty and Actor 1 equipment slot 3 armor type ID is 14
Edit:
I forgot that what you've asked is the equipment type. For getting the equipment type ID use eTypeId.
 
Last edited:

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@Aloe Guvner It returns "null"

@DrDhoom I tried
Code:
$gameActors.actor(1).equips()[2] && $gameActors.actor(1).equips()[2].aTypeId == 14
but it didn't work either.
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
164
First Language
Indonesian
Primarily Uses
N/A
I've edited my post, basically change aTypeId to eTypeId.
But if it's null then either you didn't set the equipment correctly or the slot index is wrong. Which equipment slot is the equipment that you want to check? Remember that the index start from 0.
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@DrDhoom Under equipment types it's set as 2, so I'm guessing I need to change the 2 to a 1. The armor type is also set as 14 so should I change that to 13?
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
164
First Language
Indonesian
Primarily Uses
N/A
No, only for the index, you can leave the armor type ID as it is.
Screenshot_120.png
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@DrDhoom Hmm I removed Head and Shield so the Body/Armor ID is 1 for me. Script still isn't working though. I set it up as...
Code:
$gameActors.actor(1).equips()[1] && $gameActors.actor(1).equips()[1].eTypeId == 14
Assuming I get it working, is the first part of the code necessary?
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
164
First Language
Indonesian
Primarily Uses
N/A
Change eTypeId to aTypeId, you want to check the armor type ID right? Sorry if I confused you xD

Assuming I get it working, is the first part of the code necessary?
Yes, without it the game will crash if the equipment slot is null/empty.
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@DrDhoom Ah, ok, was just checking.

Code:
$gameActors.actor(1).equips()[1] && $gameActors.actor(1).equips()[1].aTypeId == 14
still isn't working though. I typed it in the console (f8) to see what it would say and when I do it returns "false". I'm pretty sure the script is working, or at least doing something, it' just not looking for what I want it to look for. Just so I completely understand the basics of what's going on here...

$gameActors.actor(1)= The ID for which game actor you want referenced, sorted by the actors list in the actor panel.
equips()[1]= The ID for which equipment type you want to reference, sorted by the actors initial equipment type in the actor panel.
&&= Adds another condition.
$gameActors.actor(1)= Back to which actor ID to reference, should be the same as the first reference.
equips()[1]= Back to the equipment type ID to reference, should be the same as the first reference.
aTypeId == 14= The ID for the armor type referenced based off the armor types in the types panel.
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
164
First Language
Indonesian
Primarily Uses
N/A
Dang it, the script is wrong. My bad xD
It is atypeId instead of aTypeId.

$gameActors.actor(1)= The ID for which game actor you want referenced, sorted by the actors list in the actor panel.
equips()[1]= The ID for which equipment type you want to reference, sorted by the actors initial equipment type in the actor panel.
&&= Adds another condition.
$gameActors.actor(1)= Back to which actor ID to reference, should be the same as the first reference.
equips()[1]= Back to the equipment type ID to reference, should be the same as the first reference.
aTypeId == 14= The ID for the armor type referenced based off the armor types in the types panel.
Ding ding!
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@DrDhoom Nice, changing it to atypeId worked like a charm! Script is running fine now, thanks for your help!
 

Aloe Guvner

Walrus
Regular
Joined
Sep 28, 2017
Messages
1,627
Reaction score
1,201
First Language
English
Primarily Uses
RMMV
For the future, the console is really helpful for things like this. You can go through each part step-by-step to understand what it's doing:

upload_2018-12-30_13-55-16.png

And to explain why you need the first part of this (the part before the &&)
Code:
$gameActors.actor(1).equips()[1] && $gameActors.actor(1).equips()[1].atypeId == 14
&& means "and" in Javascript. If you have a condition that doesn't have things like "==", ">=", "<", etc. then what that condition is doing is figuring out whether it exists or not. So the first part of it:
Code:
$gameActors.actor(1).equips()[1]
This is just checking whether the 2nd equip exists or not. If the 2nd equip exists then it moves to the next part. But if the 2nd equip doesn't exist, it will return false and it won't try the next part.

If you didn't have the first part, and used only this:
Code:
$gameActors.actor(1).equips()[1].atypeId == 14
If the actor didn't have a 2nd equip (the 2nd equip doesn't exist), then it would basically trying to do this:
Code:
undefined.atypeId == 14
And you would receive an error like this that crashes the game:
  • Uncaught TypeError: Cannot read property 'atypeId' of undefined


Also, things start counting at zero, which is why
  • $gameActors.actor(1).equips()[0] --> the first equip
  • $gameActors.actor(1).equips()[1] --> the second equip
  • etc.
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
Is there a way to do this, or something similar to this, in a damage formula? Rather than start a new post I figured I'd ask here. I was looking over at a nice damage formula thread and it seems to be possible but I'm unsure of the syntax.

I'm pretty sure "actorId()" is the relevant variable I'm looking for, but how to use it I'm not so clear on. I'm using
Code:
if actorId(1) 50 + (v[307] * 2); else 0
as my damage formula but it crashes the game. The "else 0" is there, potentially wrongly, because it's an if then statement but I mainly just need to get the first part to work. The formula is meant to do fixed damage, ignoring defense, plus an actor unique multiplayer times 2. Once the code works as intended I'll add additional actors to the formula. The end result would look something like this if it was proper formula, which it's not.
Code:
if actorId(1) 50 + (v[307] * 2) || actorId(2) 50 + (v[308] * 2) || actorId(3) 50 + (v[309] * 2); else 0
The last part isn't needed in a working formula, unless it's actually needed for said formula to work.

Is what I want possible?
 

Aloe Guvner

Walrus
Regular
Joined
Sep 28, 2017
Messages
1,627
Reaction score
1,201
First Language
English
Primarily Uses
RMMV
It's kind of a different question, but here's some general advice:
  1. It's always possible, it's just a matter of getting the syntax correct. The damage formula is Javascript, so you can always look up Javascript syntax
  2. In the damage formula 'a' refers to the user of the skill and 'b' refers to the target of the skill. Take a look at the default formula for 'Attack'. So you'd have the check the actor ID of 'a' which is the user
  3. If the skill can also be used by enemies, then you'd have to check to make sure that 'a' is an actor. Because enemies don't have an actor ID
  4. Depending on how many actors you have, using 'if...else' becomes unmanageable. There are other ways such as 'switch...case', using a key/value map, or numbering your variables smartly
A great damage formula guide:
https://steamcommunity.com/sharedfiles/filedetails/?id=681253029

Javascript if...else
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

Javascript switch...case
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

Javascript object literal (key/value map)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
 

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
I forgot the "a". I got
Code:
if (a.actorId(1)) 50 + (v[307] * 2); else 0
to work but it always returns true. I could change the 1 to 10 and not have actor 10 in the party but it would still do damage and not 0
 

ozubon

surströmming?
Regular
Joined
Oct 16, 2018
Messages
178
Reaction score
171
First Language
English
Primarily Uses
RMMV
actorId() returns the actor's id if I recall correctly. It's not a boolean and therefore you have to compare the value to a number.
Code:
if (a.actorId() === 1) 50 + (v[307] * 2); else 0
Does this work or am I talking out of my hat? I cannot check if it does right now.
 
Last edited:

Dope

Regular
Regular
Joined
May 29, 2017
Messages
162
Reaction score
34
First Language
English
Primarily Uses
RMMZ
@ozubon I must've been tired because I should've seen that. I got it to work using the syntax
Code:
if (a.actorId() ===1) 50 + (v[307] * 2); else if (a.actorId() ===2) 50 + (v[307] * 2); else 0
I only need it to work for one actor right now but I wanted to make sure I could set it up to work for at least two. Thanks for your help!
 

Latest Threads

Latest Posts

Latest Profile Posts

I was wondering why Skyler's hair looked weird on their new sprite. Well I forgot adding their iconic hairband
Anyone up to give Holder, TRIDIUM, GenericFantasyDev and Black Mage the fight of their lives?
Go ahead.
"The internet made everyone way too comfortable with disrespecting each other and not getting punched in the face."
I woke up a touch early and was going to draw by the fireplace until it’s a more appropriate noise-making time, but I left my stylus AND my glasses (WHAT?!) upstairs and it’s just too cold to get out of the blanket now.
Made some simple samples with the Time Reversal Mechanic. It would be interesting to make a bigger puzzle where you could dynamically choose which elements are affected by the time reverse. But if there's much more than move routes and waits, it's starts to get too annoying for my brain :D Like even that exploding bomb was such a bother.

Forum statistics

Threads
134,870
Messages
1,251,428
Members
177,670
Latest member
ZalomonZZX
Top