MZ how to return id of equipped weapon of actor in battler?

I'm making a reloading skill that triggers a common event which should - 1, check id of the weapon that's being equipped by the actor who used the skill (in battle); 2, reload the gun according to what kind of gun that's being equipped.
I'm stuck on the first part (the 2nd part is fine, i think).

I used chatgpt for a script and it gave me this:

var tempvar = BattleManager._subject;

$gameVariables.setValue(4, tempvar.weapons()[0]?.id || 0);

I only vaguely understand what's happening in this code. I adjusted it a bit and made it into this.

$gameVariables.setValue(4, BattleManager._subject.weapons()[0]?.id || 0);
Neither of these work. There are three guns in the game (weapons 10-12). For play testing, I added a text right after, returning the id of the weapon, and there is also a conditional branch that checks if the id returned matches that of the guns and it returns "no guns equipped" which it does if other melee weapons are equipped. The conditional branch checks if the 4th variable has a value of 10, 11, or 12 before returning that message.
I'm using the following plugins: Vistustella Core, Visustella SkillStates and DM_limitedinventory. I don't think any of them have an effect though.

What should I change?? I don't know what the error is.
You can't use BattleManager._subject in the common event any longer. Use the last action data to get the last actor to act. Btw, AI sucks.
You can't use BattleManager._subject in the common event any longer. Use the last action data to get the last actor to act. Btw, AI sucks.
Yeah it's not really reliable. I know python but I don't know Java unfortunately.

I perused the script call excel sheet for mz online and I found this: $gameTemp.lastActionData(2). Is this what you meant?
How would I go about doing this?
Can i directly do $gameTemp.lastActionData(2).weapons() under the control variable event command or do i have to like assign $gameTemp.lastActionData(2) to a variable first, in a script, so that the actor id that gets returned is stored separately?
I think it's like:

$gameActors.actor($gameTemp.lastActionData(2)).weapons()[0]?.id

If you wanna check specific slots, I think you should use equips()
I think it's like:

$gameActors.actor($gameTemp.lastActionData(2)).weapons()[0]?.id

If you wanna check specific slots, I think you should use equips()
Oh ok thank you, I'll try it out
I don't know Java unfortunately.
Javascript, not Java. They're completely different languages.
I think it's like:

$gameActors.actor($gameTemp.lastActionData(2)).weapons()[0]?.id

If you wanna check specific slots, I think you should use equips()
ok it did work, thanks again.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-return-id-of-equipped-weapon-of-actor-in-battler.179136/