[RMMV] Weapon Upgrade system problem...

I'm trying to make my own upgrade weapon system with just eventing and so far so good. I want, what I desire...

Let's start from overview:

Database contains sets of weapons with different traits and params and it follows :

#0000 - #0009 - These weapons are not for upgrade (Basic / starting weapons).
Spoiler
Code:
#0010 - Iron Sword +0
#0011 - Iron Sword +1
#0012 - Iron Sword +2
#0013 - Iron Sword +3
#0014 - Iron Sword +4
#0015 - Iron Sword +5
#0016 - Iron Sword +6
#0017 - Iron Sword +7
#0018 - Iron Sword +8
#0019 - Iron Sword +9
#0020 - Epic Iron Sword +0
#0021 - Epic Iron Sword +1
#0022 - Epic Iron Sword +2
#0023 - Epic Iron Sword +3
#0024 - Epic Iron Sword +4
#0025 - Epic Iron Sword +5
#0026 - Epic Iron Sword +6
#0027 - Epic Iron Sword +7
#0028 - Epic Iron Sword +8
#0029 - Epic Iron Sword +9
The whole event looks like this:
Spoiler
Code:
◆Comment:First we need check if actor has any weapon at all
◆If:Script:$gameActors.actor(1)._equips[0]._itemId === 0
  ◆Text:npc(71), Window, Bottom
  :    :You must have a weapon equipped in order to upgrade.
  ◆
:Else
  ◆Comment:If actor has weapon we need to check he can afford to upgrade.
  :       :Cost is dynamic and it increases with each upgrade level
  ◆If:Script:$gameParty.gold() >= $gameVariables.value(24)
    ◆Comment:Set upgrade cost.
    ◆Script:$gameVariables.setValue(24, 2000 + (50 * $gameVariables.value(25)))
    ◆Show Animation:This Event, Pierce Fire
    ◆Script:var currWeapon = $gameActors.actor(1)._equips[0]._itemId
    :      :$gameParty.gainItem($dataWeapons[currWeapon], -1, true)
    :      :$gameParty.gainItem($dataWeapons[currWeapon+1], 1, true)
    ◆Control Variables:#0025 UPGRADE_COUNT += 1
    ◆Comment:Now... The problem starts here...
    :       :How to stop upgrading weapon when upgrade reaches item +9?
    ◆If:UPGRADE_COUNT ≥ 9
      ◆Text:npc(71), Window, Bottom
      :    :This item cannot be more upgraded.
      ◆Comment:But the variable is for all members in party, so
      :       :if this variable UPGRADE_COUNT reaches value 9...
      :       :Upgrading will be disabled.
      ◆
    :End
    ◆
  :Else
    ◆Text:npc(71), Window, Bottom
    :    :Sorry, you can't afford for upgrade...
    ◆
  :End
  ◆
:End

What I need to work it perfectly is to make two things -
#1 Upgrade weapons only if last numbers of IDs are 0 up to 9
#2 Can't upgrade if last number of ID is 9

If this is too confusing then I'll try to picture it with this:
Spoiler
#0010 - Iron Sword +0 - Can upgrade to #0011
#0011 - Iron Sword +1 - Can upgrade to #0012
#0012 - Iron Sword +2 - Can upgrade to #0013
#0013 - Iron Sword +3 - Can upgrade to #0014
#0014 - Iron Sword +4 - Can upgrade to #0015
#0015 - Iron Sword +5 - Can upgrade to #0016
#0016 - Iron Sword +6 - Can upgrade to #0017
#0017 - Iron Sword +7 - Can upgrade to #0018
#0018 - Iron Sword +8 - Can upgrade to #0019
#0019 - Iron Sword +9 - No more further upgrades!
#0020 - Epic Iron Sword +0 - Can upgrade to #0021
#0021 - Epic Iron Sword +1 - Can upgrade to #0022
#0022 - Epic Iron Sword +2 - Can upgrade to #0023
#0023 - Epic Iron Sword +3 - Can upgrade to #0024
#0024 - Epic Iron Sword +4 - Can upgrade to #0025
#0025 - Epic Iron Sword +5 - Can upgrade to #0026
#0026 - Epic Iron Sword +6 - Can upgrade to #0027
#0027 - Epic Iron Sword +7 - Can upgrade to #0028
#0028 - Epic Iron Sword +8 - Can upgrade to #0029
#0029 - Epic Iron Sword +9 - No more further upgrades!

And if someone will think of upgrade system like in Metin2, then... You're right. It's almost the same.
You can store the itemId in a variable then check the last digit via something like

Code:
var num = your itemId;
//converts it to string so we can easily
//pick the last item
var str = num.ToString();
//gets the value in last position
//length-1 is used because first position is 0
var ones = int.Parse(str[str.length-1]);

then check if the variable named "ones" is 9.

Note though that this is untested and just based on what I knoe
Not working, but found other method.
Code:
weaponId.toString().split('').pop();

and rearranged conditional branches and it's working. 🙂
Thank you for tip! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-weapon-upgrade-system-problem.105700/