MV [SOLVED] Equipped Weapon ID to Variable

Hello, I've been trying to make a simple weapon upgrade mechanic in which the selected actor's currently equipped weapon is, as mentioned, upgraded. To do so, I'd need to pass on the weapon's ID to a variable which would then go through a common event that would deal with each specific weapon.
I was wondering how that would translate to script. I tried the following line:

$gameVariables.setValue(9, $gameActors.actor(1).equips()[0].ItemId);

but the variable remained unchanged. I assume it relates to using "ItemId", but I wouldn't know how to refer specifically to weapons. Could anyone help me correct my mistake or suggest another option? Thanks in advance!
You could make your database have similar weapons I'd think. For instance, have your sword you want in database, maybe 30 attack. Have sword +1, 35 attack, sword +2 with 40 attack, sword + 3 with 50 attack, etc.. Whenever the actor gets this sword 'upgrade', you can just change the sword they have equipped to these improved swords. Reference of the following might give your answer:

$gameActors.actor(actorId).changeEquip(slotId, item);

I'd think you would be able to use this script-call [or a similar one] to change the equipment of the actor whenever you'd want, such as with a common event. I also would bring to your attention this thread for script calls:


When I checked the doc, it had multiple references for dealing with equips and what-not. I bet this would help you get this answer you seek. Best of luck Doctor.

*Fast Edit for you* -- Ctrl + F in the doc to search. Should save you time, search for equip or equipment, etc..
You could make your database have similar weapons I'd think. For instance, have your sword you want in database, maybe 30 attack. Have sword +1, 35 attack, sword +2 with 40 attack, sword + 3 with 50 attack, etc.. Whenever the actor gets this sword 'upgrade', you can just change the sword they have equipped to these improved swords. Reference of the following might give your answer:

$gameActors.actor(actorId).changeEquip(slotId, item);

I'd think you would be able to use this script-call [or a similar one] to change the equipment of the actor whenever you'd want, such as with a common event. I also would bring to your attention this thread for script calls:


When I checked the doc, it had multiple references for dealing with equips and what-not. I bet this would help you get this answer you seek. Best of luck Doctor.

*Fast Edit for you* -- Ctrl + F in the doc to search. Should save you time, search for equip or equipment, etc..

Ah, sorry! I have not clarified myself enough. I was indeed planning to make multiple items for each upgrade, but the problem is there is no Select Weapon option, so my solution was to simply select an Actor (via Show Choices) and have their equipped weapon be the one to be upgraded. The problem with that is that I am currently unable to pass on the equipped weapon's ID onto a variable, that would later be referenced when performing the interchange between the old weapon and the upgraded version.
I also try consulting that same doc when in doubt, but this time I've been unable to find it of any help, sadly.
I used this and then note.

<Custom Equip Requirement Condition>
$gameVariables.setValue (ID, 1)
<\Custom Equip Requirement Condition>

The above command is slightly wrong.
Should be like this To check
Code:
if($gameActors.actor(1).hasWeapon($dataWeapons[2])){
$gameVariables.setValue(9, 1)
}

You put this condition into the script.
So that variable 9 = 1
When character 1 is equipped with 2 weapons.
The relevant property is id; you can use Control Variables > Script:
JavaScript:
var w = $gameActors.actor(1).weapons()[0]; w ? w.id : 0
I.e. "get the first equipped weapon of actor ID 1; if it exists, return its ID, else return 0".

If you'd rather reference actors by their position in the party (using \P[x] for your actor choices rather than \N[x]), try this instead:
JavaScript:
var m = $gameParty.members()[0]; var w = m ? m.weapons()[0] : null; w ? w.id : 0
I.e. "get the first member of the party (leader = index 0); get the first weapon equipped by that member, or null if they don't exist; return the weapon's ID if it exists, else 0".
Spoiler: Example use in event
Code:
◆Text:None, Window, Bottom
:    :Pick a party member!
◆Show Choices:\P[1], \P[2] (Window, Right, #1, -)
:When \P[1] 
  ◆Control Variables:#0001 = var m=$gameParty.members()[0];var w=m?m.weapons()[0]:null;w?w.id:0
  ◆
:When \P[2] 
  ◆Control Variables:#0001 = var m=$gameParty.members()[1];var w=m?m.weapons()[0]:null;w?w.id:0
  ◆
:End
◆Text:None, Window, Bottom
:    :Equipped weapon ID is \v[1].
The relevant property is id; you can use Control Variables > Script:
JavaScript:
var w = $gameActors.actor(1).weapons()[0]; w ? w.id : 0
I.e. "get the first equipped weapon of actor ID 1; if it exists, return its ID, else return 0".

If you'd rather reference actors by their position in the party (using \P[x] for your actor choices rather than \N[x]), try this instead:
JavaScript:
var m = $gameParty.members()[0]; var w = m ? m.weapons()[0] : null; w ? w.id : 0
I.e. "get the first member of the party (leader = index 0); get the first weapon equipped by that member, or null if they don't exist; return the weapon's ID if it exists, else 0".
Spoiler: Example use in event
Code:
◆Text:None, Window, Bottom[/INDENT]
[INDENT]:    :Pick a party member![/INDENT]
[INDENT]◆Show Choices:\P[1], \P[2] (Window, Right, #1, -)[/INDENT]
[INDENT]:When \P[1][/INDENT]
[INDENT]  ◆Control Variables:#0001 = var m=$gameParty.members()[0];var w=m?m.weapons()[0]:null;w?w.id:0[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:When \P[2][/INDENT]
[INDENT]  ◆Control Variables:#0001 = var m=$gameParty.members()[1];var w=m?m.weapons()[0]:null;w?w.id:0[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:End[/INDENT]
[INDENT]◆Text:None, Window, Bottom[/INDENT]
[INDENT]:    :Equipped weapon ID is \v[1].

Ah, works like a charm! And you even solved the problem with having no equipped weapon! Wonderful, thank you very much for your assistance! : o )

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-equipped-weapon-id-to-variable.127484/