Solved Problem with upgrading (no errors)

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Pqngs

Member
May 28, 2021
11
0
1
23
I'm trying to make a skript where when you right click with it, it'll upgrade the pickaxe. Not gonna show the full skript, but if you wan't it i'll give it to you
the issue:
Code:
every tick:
    loop all players:
        if amount of {pick::*} = 2:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c1&8]" in loop-player's inventory with wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c2&8]"
            set {pickcost::*} to 32
            set {pickcost} to 32
            stop
        if amount of {pick::*} = 3:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c2&8]" in loop-player's inventory with wooden pickaxe of efficiency 2 named "&7Wooden Pickaxe&8 [&c3&8]"
            set {pickcost::*} to 48
            set {pickcost} to 48
            stop
        if amount of {pick::*} = 4:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c3&8]" in loop-player's inventory with wooden pickaxe of efficiency 3 named "&7Wooden Pickaxe&8 [&c4&8]"
            set {pickcost::*} to 64
            set {pickcost} to 64
            stop

the issue is it won't upgrade past tier 2. when I try to upgrade it through a GUI I made, it just doesn't work, and stays at two. I've tried to fix this for hours but I gave up and just came here.
Again, if you want the full code, just ask. I'm not very active but i'll try to check for msgs.

Many Thanks! :emoji_slight_smile:
EDIT: incase anyone didn't read, there are no errors on reload. it simply doesn't work

Alright, New Update, i switched everything to loop-player/player variables and it doesn't work, this time with errors on reload.
ERROR:
"{pick::%loop-player%} can only ever have one value at most, thus the 'amount of ... ' has a value. (pick.sk, line 65: if amount of {pick::%loop-player%} = 3"

now my shop gui and stuff doesn't work and I broke everything.
New Code:

Code:
every tick:
    loop all players:
        if amount of {pick::%loop-player%} = 2:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c1&8]" in loop-player's inventory with wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c2&8]"
            set {pickcost::%loop-player%} to 32
            set {pickcost2::%loop-player%} to 32
            stop
        if amount of {pick::%loop-player%} = 3:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c2&8]" in loop-player's inventory with wooden pickaxe of efficiency 2 named "&7Wooden Pickaxe&8 [&c3&8]"
            set {pickcost::%loop-player%} to 48
            set {pickcost2::%loop-player%} to 48
            stop
        if amount of {pick::%loop-player%} = 4:
            replace wooden pickaxe named "&7Wooden Pickaxe&8 [&c3&8]" in loop-player's inventory with wooden pickaxe of efficiency 3 named "&7Wooden Pickaxe&8 [&c4&8]"
            set {pickcost::%loop-player%} to 64
            set {pickcost2::%loop-player%} to 64
            stop
 
Last edited:
I dont think you understand how list variables work
edit: nvm, ignore that
[doublepost=1622303578,1622303333][/doublepost]But I don't get what you mean with

set {pickcost::*} to 32
set {pickcost} to 64

you know these are global variables and not for a specific player
 
I dont think you understand how list variables work
edit: nvm, ignore that
[doublepost=1622303578,1622303333][/doublepost]But I don't get what you mean with

set {pickcost::*} to 32
set {pickcost} to 64

you know these are global variables and not for a specific player
yeah I was thinking about that. Should I change them to player variables (i.e. {pickcost::%player%})?
Also I started skript only about a month ago, with constant breaks and very little usage each day. I don't know much about it
[doublepost=1622304327][/doublepost]
I dont think you understand how list variables work
edit: nvm, ignore that
[doublepost=1622303578,1622303333][/doublepost]But I don't get what you mean with

set {pickcost::*} to 32
set {pickcost} to 64

you know these are global variables and not for a specific player
I updated the main post to show my changes. didn't work :/
 
Tell me what u need and I script it for ya


EDIT:
I wasn't specific enough.
When you Right Click with a wooden pickaxe, it opens a gui that tells you yes or no (lime wool and red wool) if you click no, it closes the gui, if you click yes, it'll upgrade your pickaxe for 16 coal.
In order to open the GUI, you need enough coal to purchase the upgrade.
Once you upgrade the pickaxe, of course. It adds 1 efficiency level and increases the price by 16. (coal)
It renames the pickaxe too but i'll rename it myself.
upgrading to tier 2: 16 coal, tier 3: 32 coal, tier 4: 48 coal, tier 5: 64 coal

Thank you very, very much! I really appreciate this as i'm new and really have no clue what i'm doing.
 
Last edited:
sry took me a while to figure out the enchanting part..

Code:
options:
  increaseCost: 16
  maxLevel: 5

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          open virtual chest inventory with size 1 named "&1&0Pickaxe Upgrading" to player
          format gui slot 2 of player with red wool named "&cCancel" to close
          format gui slot 6 of player with lime wool named "&aUpgrade" with lore "&7Cost: &c%{_cost}% Coal" to close then run function upgradePickaxe(player, {_cost}, {_currentlevel})
        else:
          send "You need at least %{_cost}% coal"
      else:
        send "You reached the limit of upgrading"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"

Its fully automated, if you plan to add more levels just increase the {@maxLevel} option
[doublepost=1622311850,1622311350][/doublepost]If you are planning on changing the item name or smth else just write me a message here or on discord: Jonas L. | Minecoll_YT#0741
 
sry took me a while to figure out the enchanting part..

Code:
options:
  increaseCost: 16
  maxLevel: 5

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          open virtual chest inventory with size 1 named "&1&0Pickaxe Upgrading" to player
          format gui slot 2 of player with red wool named "&cCancel" to close
          format gui slot 6 of player with lime wool named "&aUpgrade" with lore "&7Cost: &c%{_cost}% Coal" to close then run function upgradePickaxe(player, {_cost}, {_currentlevel})
        else:
          send "You need at least %{_cost}% coal"
      else:
        send "You reached the limit of upgrading"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"

Its fully automated, if you plan to add more levels just increase the {@maxLevel} option
[doublepost=1622311850,1622311350][/doublepost]If you are planning on changing the item name or smth else just write me a message here or on discord: Jonas L. | Minecoll_YT#0741
Thank you very much! I really appreciate the help, seriously.
I'll do any customizing I can, I know skript at least a little bit.
Thanks! :emoji_slight_smile:
[doublepost=1622312798][/doublepost]
sry took me a while to figure out the enchanting part..

Code:
options:
  increaseCost: 16
  maxLevel: 5

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          open virtual chest inventory with size 1 named "&1&0Pickaxe Upgrading" to player
          format gui slot 2 of player with red wool named "&cCancel" to close
          format gui slot 6 of player with lime wool named "&aUpgrade" with lore "&7Cost: &c%{_cost}% Coal" to close then run function upgradePickaxe(player, {_cost}, {_currentlevel})
        else:
          send "You need at least %{_cost}% coal"
      else:
        send "You reached the limit of upgrading"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"

Its fully automated, if you plan to add more levels just increase the {@maxLevel} option
[doublepost=1622311850,1622311350][/doublepost]If you are planning on changing the item name or smth else just write me a message here or on discord: Jonas L. | Minecoll_YT#0741
Alright due to some problems, I don't think I have the right plugins either. I can't test it because the function upgradePickaxe(player, {_cost}, {_currentlevel}) doesn't work.
ERROR ON RELOAD:
Can't understand this condition/effect (I moved the function.): function upgradePickaxe(player, {_cost},{_currentlevel}) (pick2.sk, line 16)

Also the plugins I have for skripting are SkBee, and SkRayFall
 
Thank you very much! I really appreciate the help, seriously.
I'll do any customizing I can, I know skript at least a little bit.
Thanks! :emoji_slight_smile:
[doublepost=1622312798][/doublepost]
Alright due to some problems, I don't think I have the right plugins either. I can't test it because the function upgradePickaxe(player, {_cost}, {_currentlevel}) doesn't work.
ERROR ON RELOAD:
Can't understand this condition/effect (I moved the function.): function upgradePickaxe(player, {_cost},{_currentlevel}) (pick2.sk, line 16)

Also the plugins I have for skripting are SkBee, and SkRayFall
I changed pretty much a lot around the skript. I'll just send you the new skript.
Code:
on first join:
    execute player command "/start-game"

options:
  increaseCost: 16
  maxLevel: 5
 
on inventory click:
    if name of event-inventory is "&8Are you sure?":
        if index of event-slot = 6:
            cancel event
            close player's inventory

on inventory click:
    if name of event-inventory is "&8Are you sure?":
        if index of event-slot = 2:
            play sound "entity.experience_orb.pickup" to player
            send action bar "&aYou successfully updated your pickaxe to tier &2%{_currentlevel}%" to player
            cancel event
            close player's inventory
            run function upgradePickaxe(player, {_cost}, {_currentlevel})
on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
          set slot 6 of {_gui} to red wool named "&c&lCANCEL" with lore "&7I don't want to upgrade my pickaxe." and "&8" and "&cCloses GUI"
          set slot 2 of {_gui} to lime wool named "&a&lUPGRADE" with lore "&7I'd like to upgrade my pickaxe." and "&8" and "&cCost: &c%{_cost}% Coal"
          open {_gui} to player
        else:
          send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
      else:
        send "&cYou can't upgrade any further!"
 
function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}
 
command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"

command /start-game:
    permission: op
    trigger:
        set {_currentlevel} to 0
As you can see (if you can...) I added a bit and moved a bit around to fit with my plugins. the GUI and stuff works just upgrading does nothing. Meaning there's only 1 problem.
 
You don't need to change the {_currentlevel} variable, its a local variable
And you changed the complete structure of it, I have to change it completely, please give me a second
[doublepost=1622314072,1622313909][/doublepost]Try:
Code:
options:
  increaseCost: 16
  maxLevel: 5

on quit:
  delete {lastcost::%player%}
  delete {lastlevel::%player%}

on inventory click:
  if name of event-inventory is "&8Are you sure?":
    if index of event-slot = 6:
      cancel event
        close player's inventory
    else if index of event-slot = 2:
      cancel event
      close player's inventory
      upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          set {lastlevel::%player%} to {_currentlevel}
          set {lastcost::%player%} to {_cost}
          set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
          set slot 6 of {_gui} to red wool named "&c&lCANCEL" with lore "&7I don't want to upgrade my pickaxe." and "&8" and "&cCloses GUI"
          set slot 2 of {_gui} to lime wool named "&a&lUPGRADE" with lore "&7I'd like to upgrade my pickaxe." and "&8" and "&cCost: &c%{_cost}% Coal"
          open {_gui} to player
        else:
          send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
      else:
        send "&cYou can't upgrade any further!"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}
    play sound "entity.experience_orb.pickup" to {_p}
    send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"
 
You don't need to change the {_currentlevel} variable, its a local variable
And you changed the complete structure of it, I have to change it completely, please give me a second
[doublepost=1622314072,1622313909][/doublepost]Try:
Code:
options:
  increaseCost: 16
  maxLevel: 5

on quit:
  delete {lastcost::%player%}
  delete {lastlevel::%player%}

on inventory click:
  if name of event-inventory is "&8Are you sure?":
    if index of event-slot = 6:
      cancel event
        close player's inventory
    else if index of event-slot = 2:
      cancel event
      close player's inventory
      upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          set {lastlevel::%player%} to {_currentlevel}
          set {lastcost::%player%} to {_cost}
          set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
          set slot 6 of {_gui} to red wool named "&c&lCANCEL" with lore "&7I don't want to upgrade my pickaxe." and "&8" and "&cCloses GUI"
          set slot 2 of {_gui} to lime wool named "&a&lUPGRADE" with lore "&7I'd like to upgrade my pickaxe." and "&8" and "&cCost: &c%{_cost}% Coal"
          open {_gui} to player
        else:
          send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
      else:
        send "&cYou can't upgrade any further!"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}
    play sound "entity.experience_orb.pickup" to {_p}
    send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"
Alright! Almost worked like a charm. It renames the pickaxe but doesn't enchant it.
Sorry if I keep bothering you. It means a lot to me :emoji_slight_smile:
Thanks again in advance
[doublepost=1622315151][/doublepost]
You don't need to change the {_currentlevel} variable, its a local variable
And you changed the complete structure of it, I have to change it completely, please give me a second
[doublepost=1622314072,1622313909][/doublepost]Try:
Code:
options:
  increaseCost: 16
  maxLevel: 5

on quit:
  delete {lastcost::%player%}
  delete {lastlevel::%player%}

on inventory click:
  if name of event-inventory is "&8Are you sure?":
    if index of event-slot = 6:
      cancel event
        close player's inventory
    else if index of event-slot = 2:
      cancel event
      close player's inventory
      upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})

on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&7Invalid level&8."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          set {lastlevel::%player%} to {_currentlevel}
          set {lastcost::%player%} to {_cost}
          set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
          set slot 6 of {_gui} to red wool named "&c&lCANCEL" with lore "&7I don't want to upgrade my pickaxe." and "&8" and "&cCloses GUI"
          set slot 2 of {_gui} to lime wool named "&a&lUPGRADE" with lore "&7I'd like to upgrade my pickaxe." and "&8" and "&cCost: &c%{_cost}% Coal"
          open {_gui} to player
        else:
          send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
      else:
        send "&cYou can't upgrade any further!"

function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    set level of efficiency of {_p}'s tool to {_nextlevel}
    play sound "entity.experience_orb.pickup" to {_p}
    send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}

command /getpickaxe [<text>]:
  permission: op
  trigger:
    give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"
I also have to go and will be back in 20 minutes. Expect a late message!
 
thats weird
Hello again! I couldn' figure out how to message you but I figured out the problem.
I haven't worked on my server in about an hour. But I tried again, and the code worked! Sort of.
You see, the code you made is perfectly fine - but the issue is that the pickaxe starts as efficiency 1. I didn't want that, I wanted it to start as a plain pickaxe.
It doesn't upgrade the pickaxe unless it starts with efficiency 1, which is the problem at hand - and I was wondering if you could fix it?
I really appreciate the extra effort you're putting in to help me and this is the last the I need.

Thank you very much for the help today! :emoji_slight_smile:
 
So Level 1 would be a pickaxe with no efficiency? If yes change:
Code:
set level of efficiency of {_p}'s tool to {_nextlevel}
to
Code:
set level of efficiency of {_p}'s tool to {_nextlevel} -1
or
Code:
set level of efficiency of {_p}'s tool to ({_nextlevel} -1)
 
So Level 1 would be a pickaxe with no efficiency? If yes change:
Code:
set level of efficiency of {_p}'s tool to {_nextlevel}
to
Code:
set level of efficiency of {_p}'s tool to {_nextlevel} -1
or
Code:
set level of efficiency of {_p}'s tool to ({_nextlevel} -1)
Thanks a lot! This really helps me out :emoji_slight_smile:
[doublepost=1622385574,1622328536][/doublepost]
So Level 1 would be a pickaxe with no efficiency? If yes change:
Code:
set level of efficiency of {_p}'s tool to {_nextlevel}
to
Code:
set level of efficiency of {_p}'s tool to {_nextlevel} -1
or
Code:
set level of efficiency of {_p}'s tool to ({_nextlevel} -1)
Didn't work, but I managed to do something. And it worked. FINALLY
I googled for many hours this morning since like 7am (in my time) to try and find this. I figured it out and now it works perfectly. I learned there are many unnessacary (i misspelled that) things in the code, but for now. It works. And that's all I care about.

Thank you for the help, without you I wouldn't have my server.

:emoji_slight_smile:
Code:
options:
  increaseCost: 16
  maxLevel: 6
 
on quit:
  delete {lastcost::%player%}
  delete {lastlevel::%player%}
 
on inventory click:
  if name of event-inventory is "&8Are you sure?":
    if index of event-slot = 6:
      cancel event
      close player's inventory
    else if index of event-slot = 2:
      cancel event
      close player's inventory
      upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})
 
on right click with wooden pickaxe:
  if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    set {_x} to name of player's tool
    replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    replace all "&8]" with "" in {_x}
    set {_currentlevel} to {_x} parsed as a integer
    if {_currentlevel} is not set:
      send "&cYou can't upgrade further."
    else:
      if {_currentlevel} is less than {@maxLevel}:
        set {_cost} to {@increaseCost} * {_currentlevel}
        if amount of coal in player's inventory is more than or equal to {_cost}:
          set {lastlevel::%player%} to {_currentlevel}
          set {lastcost::%player%} to {_cost}
          set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
          set slot 6 of {_gui} to red wool named "&c&lCANCEL" with lore "&7I don't want to upgrade my pickaxe." and "&8" and "&cCloses GUI"
          set slot 2 of {_gui} to lime wool named "&a&lUPGRADE" with lore "&7I'd like to upgrade my pickaxe." and "&8" and "&cCost: &c%{_cost}% Coal"
          open {_gui} to player
        else:
          play sound "block.anvil.break" to player
          send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
      else:
        play sound "block.anvil.break" to player
        send "&cYou can't upgrade any further!"
 
function upgradePickaxe(p: player, cost: number, currentlevel: number):
  if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    set {_nextlevel} to {_currentlevel} + 1
    remove {_cost} of coal from {_p}'s inventory
    if {_nextlevel} = 6:
      set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c&lMAX&8]"
      enchant {_p}'s tool with efficiency 5
      send action bar "&aYou successfully updated your pickaxe to the&2 Max Level&a." to {_p}
      play sound "entity.experience_orb.pickup" to {_p}
      play sound "ui.toast.challenge_complete" with volume 1 and pitch 2 to {_p}
    else:
      set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
      if {_p}'s tool isn't enchanted:
        enchant {_p}'s tool with efficiency 1
        send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
        play sound "entity.experience_orb.pickup" to {_p}
      else:
        set {_} to level of efficiency of {_p}'s tool
        if {_} = 1:
          set level of efficiency of {_p}'s tool to 2
          play sound "entity.experience_orb.pickup" to {_p}
          send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
        if {_} = 2:
          set level of efficiency of {_p}'s tool to 3
          play sound "entity.experience_orb.pickup" to {_p}
          send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
        if {_} = 3:
          set level of efficiency of {_p}'s tool to 4
          play sound "entity.experience_orb.pickup" to {_p}
          send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
        if {_} = 4:
          set level of efficiency of {_p}'s tool to 5
          play sound "entity.experience_orb.pickup" to {_p}
          send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
 
command /getpickaxe [<text>]:
    permission: op
    trigger:
        give player wooden pickaxe named "&7Wooden Pickaxe&8 [&c1&8]"
        give player 64 coal

command /picktest:
    permission: op
    trigger:
        set {_} to level of efficiency of player's tool
        send "%{_}%"
        send "level: %{_currentlevel}%"
 
Status
Not open for further replies.