script call to return id of actor with equipped item

New to the boards. I've managed to glean a lot of information about how to use script calls in RPG Maker VX Ace from this board, tutorials, etc.

But I've finally run into a wall.

I cannot seem to figure out what script call I can use to simply return the actor id of the character with a specified equipment.

The game I'm working on allows actors to swap bodies, so I bind the equip/unequip to common events that are then to find

which actor has an item equipped and change their sprite/portrait as needed.

I've got most of what I need to make this work, save that I can't figure out how to get it to "know" which character has

equipped the item.

I've tried using the script to change character sprite with equips, but it requires binding the change to a specific actor.

I need any actor to be able to change when using the equipment.

Can anyone assist me with this?
To start with.

By the term "script" do you mean an Event made by the menus "script"  or Ruby source code?
Preferably the source code if possible. If there's something like a $game_party.equips[x].actor.id or something along those lines.

i don't mind add on scripts when they're needed, but I like to try to keep it as simple as I can when i'm just trying to work with basic data.
I don't have Ace with me, so my syntax is bound to be wrong. It would be something like this:

Code:
$game_party.members.select {|actor| actor.equips.include?($data_weapons[5])}
which could return an empty array or an array containing multiple actors. If you just wanted the id of the first one, you might try:
Code:
actors = $game_party.members.select {|actor| actor.equips.include?($data_weapons[5])}; actors.size > 0 ? actors[0].id : 0
to return 0 if nobody has it equipped, otherwise the id of the first actor retrieved.
I'll play with it a bit, but that looks about like what I need. The equipment I'm having it look for, there will only ever be one of each in existence at any given time(unless I bugger it up somewhere), so it should either return nothing or the first character it finds to have it.

I think that might be a bit cleaner than the method I had arranged to do so, which was a conditional branch with a loop that would then use a variable to check each actor's

equipment to see if they had the item equipped.

edit: It doesn't seem like the syntax is bad, it does appear to run without error, but i'm not 100% sure what it's returning. Is it just the value for the character, like an integer, or is it returning something like $game_actors[#]?

Is there an easy way to see what it's returning?

here's an example of what I'm trying to do:
actors = $game_party.members.select {|actor| actor.equips.include?($data_armors[5])}; actors.size > 0 ? actors[0].id : 0
x = ???
actor1 = $game_actors[x]
actor1.set_graphic("custom1", 1, actor1.face_name, actor1.face_index)

I've tried it using actors.set_graphic(etc) but that doesn't appear to work, which prompted me to wonder just what it's returning.

The basic concept behind this idea might be comparable to the Moogle Suit from Final Fantasy 3/6, where if a character equipped it, they became a moogle.
It is returning a number. If the number is 0, it means nobody in your party has that item equipped. If it returns something other than 0, it is the ID of the actor who has it equipped.

So if Actor 3 is in your party and has it equipped, it will return 3

See, if you'd explained in the beginning what you were trying to do (what you planned to do with it afterwards), we could have saved a bit of time 😉 You asked for an actor id, which I gave you. If you had said you then want to change that actor's graphic, I could have just given you the actor object back. What you're doing above is getting an actor object, pulling out its id, and then using that id to get the actor object, which is exactly what you started with 😉

If you're doing all of the above in a script call, do it like this:

actors = $game_party.members.select {|actor| actor.equips.include?($data_armors[5])}actors[0].set_graphic("custom1", 1, actors[0].face_name, actors[0].face_index) if actors.size > 0How you define "custom1" would depend on the id of the actor, probably, so if you tell us the rules we'll even give you that line too 😉

If you only have a narrow script input window and those lines break automatically, say so, and I will show you EXACTLY what to put (where to break) - otherwise, if you let it do automatic line breaks, it's going to do them in the wrong places and will make your game crash.
Well, like I say, I'm new to posting, really new to the whole rpg maker scene, so I'll try to remember that going forward.

It's kind of a pain since there's no real manual to the scripting within the existing engine, so everything has to be reverse engineered. I've read the various tutorials and am getting the hang of how it all works, but like in this case I run into issues where there's a void in my information and I can't find a good ready resource.

But that's also why I'm kind of generic in my asking, as it's not about getting the easy answer of "how to do this thing", but about learning for myself "how to do this thing", so I can apply that information going forward. in this case, it's not just about getting the amor that changes a sprite to work, but about learning how to find and return a value

without having to reinvent the wheel to do so, as I will likely be using that information in other aspects of the project.

In this case, for example, I had no idea about the .select {parameters} option. Is that written down somewhere? Is there a resource i could read that has a list of all of these query options?
Additionally, so the .select then returns something like $game.actors[x] where x is the value of either the actor with the item or 0, correct? So then what does actors[0] do?

I guess what I'm trying to do is get into a position where I can sort of self check these things as I learn the way this system works.

Custom1 is just a custom sprite sheet as I've used the built in character generator for my actors.  I guess the rules there would be that an armor

would then be tied to a sprite set on that sheet, so $data_armors[5] would be tied to "custom1", 1
I learned by looking at the default scripts, and looking at scripts released by others. I have a Ruby manual which I go to sometimes, and there are also quite a few online resources available to help you with the language and syntax.


It's a matter of deciding what you want to do, working out what the engine already does that's close to it, and tweaking and testing (your own version, not the original code) until you get what you want.


Game_Interpreter is a good place to start - it's got the code behind all the event commands. There's a pinned thread here on the script call to make if you want to do any of those event commands within a script command. If I wasn't already familiar enough with Game_Actor to know about equips, that's where I'd go to start looking.
Yeah, that's pretty much how I'm learning it, reverse engineering. It just gets frustrating from time to time having to do it that way.

I've been browsing the existing scripts in the engine, but even those tend to be vague so it takes a goodly bit of trial an error to figure them out.

One more quick question. Is there a way to get a script to display the contents of a local variable in a text box?

say I want to know exactly what the script we've talked about is returning in the actors variable, how would i do that to double check that information?
If you play with the console turned on, you can just add a line like one of the following:

p actorsand that will print, to the console, what's been returned by the .select statement.
Note, though, it will be a Game_Actor object, so it'll show all the properties of the actor. Several of them if there happens to be more with that item equipped.
Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-return-id-of-actor-with-equipped-item.35832/