That's because the weapon is an independent item. The way Yanfly's Item Core makes independent items is that it copies the base item to create a new item with a new generated id that is a really high number so that it does not clash with the base item ids.
To get the id of the base item, try this:
$gameVariables.setValue(9, $gameActors.actor(5).equips()[0].baseItemId);
Thank you very much.... Yes, i'm using yanfly's Item Core and i have tried your script. It can detect the first weapon id only but after upgrading my weapon to let say Bronze Sword +1 which is weapon id 17. I called the weapon id variable, but it says 0 not 17.
This is the script i'm using :
var charid = $gameVariables.value(222);
var weaponid = $gameActors.actor(charid).equips()[0].baseItemId;
$gameParty.gainItem($dataWeapons[weaponid + 1], 1);
$gameActors.actor(charid).changeEquip(0, $dataWeapons[weaponid + 1]);
$gameParty.gainItem($dataWeapons[weaponid], -1);
var upgradecount = $gameVariables.value(charid + 236);
$gameVariables.setValue(charid + 236, upgradecount + 1);
If you are using a script/plugin, you should say what script/plugin you're using. I would have just answered to use Control Variables.
Will do that another time when i need help again. Using Control Variables is another options i had but it is not really efficient for upgrade weapon/armor thing as i need to check per actor what weapon id that actor equip and just +1 from that id. using script would be faster than manually check using Control Variables.
Anyway... Thank you very much for the help....