How to access selected actor from common event while in menu

I'm using Selchar's Equipment Durability scripts, and I want to create a Repair skill as an alternative to using the Equip Repair Scene. (This question doesn't have much to do with those scripts, but this is the scenario that helps explain what I'm doing)

I've created a Repair Sword skill, which requires a sword to be equipped, and I've set it up to call a common event. I've also set the Occasion field to "Only from the Menu".

In the common event, I can set up a script call to do this:

a = $game_actors[1].equips[0]

a.repair

This works perfectly, as long as I have one actor in the party. I can invoke the skill from the menu (press ESC, select Skills, select actor 1, and select the Repair Sword skill), and it works - but it's hardcoded to work on actor 1. When I have more than one actor in the party, I don't know how to detect which actor was selected from the menu. I've searched through the RGSS reference material in the Help system, and I don't see how to do this.

Can anyone point me in the right direction?
One quick and dirty way you could do it:

class Game_Temp

  attr_accessor :skill_user

end

class Scene_ItemBase < Scene_MenuBase

  alias trihan_use_item use_item

  def use_item

    $game_temp.skill_user = user

    trihan_use_item

  end

end

Then in your common event you can use $game_temp.skill_user to get the object of the actor who used the skill.

The inherent problem is that the part of Scene_ItemBase which checks whether a common event is waiting to run goes to Scene_Map before it executes the event, so the user/target information are lost.
I think you can do it directly from the skill damage formula (set it to hp/mp recover)

b.equips[0].repairEdit: oh wait, if you use that only from menu it won't let you use it unless you give it another effect, like adding and removing a state (e.g add and remove silence state), then it should work.
Yeah, I would have suggested a formula if that wasn't the case.

Edit: You don't even have to add and remove a state, just add one with a 0% chance.

Also be careful if you do it that way that you don't end up returning any value above 0, or the target will take that much damage.
I think you can do it directly from the skill damage formula (set it to hp/mp recover)

b.equips[0].repairEdit: oh wait, if you use that only from menu it won't let you use it unless you give it another effect, like adding and removing a state (e.g add and remove silence state), then it should work.
Hm. I just tried that, but it didn't work. The sword wasn't repaired. I also tried "a.equips[0].repair", but that didn't make any difference. I've attached a screenshot of the skill page: did I miss something?

Also be careful if you do it that way that you don't end up returning any value above 0, or the target will take that much damage.
I'm not sure I follow. I'm not in the battle scene. I just press ESC from the map to get to the menu, and access the skill from there.

repairskill.jpg
Whatever value the method called from the battle formula returns will be the amount of damage or recovery the skill ends up doing, so if your repair method returns a value the target will regain that much HP, which is obviously not what you want.

I'm assuming you've added "repair" as a new method available to weapons for this to work, yes?
Yeah, that's a method that Selchar added via his script. It doesn't return anything.
Oh, I see what it is. You've got the scope of the skill set to "none" so there's no target to assign to b.
Ok. I changed the scope to "The User". Interestingly, after select the Repair Sword skill, it now prompts me to select an actor. But it still doesn't actually perform the repair. I tried invoking repair on "b" and "a" in the damage formula. No difference.

Edit: tried setting scope to "One Ally" also. Didn't work either.
Would it be possible to do this coming at it from a totally different angle?  I'm not sure that I've exactly understood your conditions.  The following assumes that it is the skill 'Repair' which is key, but if it's the sword, then substitute that.

You have an actor who has the skill 'Repair'.  One feature of this skill could be that it inflicts a passive state on the actor with that skill.  That state does nothing, has no icon, it's just there.  Then in your common event, have the event check if the actor has that state.  if s/he does, then repair the sword, if not, do nothing.

Is that what you are trying to do?
@Trihan & EatYourBeetS: if I set the damage type to HP Damage and set the formula to "1", that works. So it looks like the skill settings are correct (scope, effects, etc). If I take out "1" and put in "b.equips[0].repair" (leaving damage type set to "HP Damage", that causes instant death. I wonder if having damage type set to "HP Recover" and the fact that my party actors are at full health means that it doesn't do anything...

@ksjp17: the common event would have to check each party member to find which one has that state, right? That's not a bad idea - I can try to set that up.
Put "return 0" at the end of the repair method. (and keep it on HP Damage)
@Trihan: that didn't work either.

@ksjp17: that worked! I created a new Repair state. In the Repair Sword skill, I set the damage type to "None", Scope to "One Ally", and added an effect to add the Repair state. Then in the common event, I set up a series of if checks for the different party members to find out which one had the Repair state, and when it finds a match, it calls the repair method for that actor's equip slot 0 and clears the Repair state from that actor. Thanks!
That's weird, it worked for me. Oh well, you've got a solution that works, so that's good! If you do want to get it working entirely with scripts, give me a shout, but sounds like that way you've got works fine.
I think the common event will work fine. But thank you for your help, trihan! Much appreciated!
I've just done a bit of testing with the actual script and it's working fine for me: the only problem was that the Repair skill was using up 1 durability as well, but setting its durability cost to 0 fixed that.

Just for your own future reference: I have it set up thusly:

Scope: The User

Type: HP Recover

Formula: b.equips[0].repair

Effects: Add state [Poison] 0%

Note: <durability cost: 0>

Then at the end of the repair method I put "return 0" so that it doesn't damage the character when used.
That worked for me too, Trihan. Thanks for pursuing that - I've learned a lot through this exercise.

With everything I've learned, I've decided to rename the skill to be "Repair" so it's more generic, and have it repair all of the gear equipped by the selected actor. This way, the user can repair all of the equipped items in one shot (without having to individually repair each equipped item, which could get frustrating early on with a large party and cheaper equipment). So the common event works best for me with this general repair skill - I have it checking each of the weapon and armor equip slots and repairing all the equipped items for the selected actor.

Thanks, again!
Glad to hear you've learned stuff! That always gives me the warm and fuzzies.

I very much look forward to your next request for help! (seriously, nobody's posting any questions and I keep refreshing the forums hoping there'll be someone to help. So bored...)
All way too complicated, and not necessary - the script already saves both the actor using the skill and the target of the skill or item.


To get the id of an actor who used a skill, use the following in a conditional branch (or Control Variables with this in the Script part):

$game_party.menu_actor.idTo get the id of an actor the skill was used on, use this instead:
Code:
$game_party.target_actor.id
Note - these work from the regular menu, not from the battle menu. If you want it to work in battle as well, say so and I'll try to find the equivalent.
And of course, if you want the actor object itself and not the id, just leave out .id - otherwise you're getting the actor object, taking the id, then converting back to an actor object using that id, which is a bit redundant.
.....doh. Never even thought of looking in $game_party.

You win, Shaz. *hands in RPG Maker helper badge and gun*

Original thread: https://forums.rpgmakerweb.com/threads/how-to-access-selected-actor-from-common-event-while-in-menu.38935/