1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Problem with upgrading (no errors)

Discussion in 'Skript' started by Pqngs, May 29, 2021.

Thread Status:
Not open for further replies.
  1. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    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 (Text):
    1. every tick:
    2.     loop all players:
    3.         if amount of {pick::*} = 2:
    4.             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]"
    5.             set {pickcost::*} to 32
    6.             set {pickcost} to 32
    7.             stop
    8.         if amount of {pick::*} = 3:
    9.             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]"
    10.             set {pickcost::*} to 48
    11.             set {pickcost} to 48
    12.             stop
    13.         if amount of {pick::*} = 4:
    14.             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]"
    15.             set {pickcost::*} to 64
    16.             set {pickcost} to 64
    17.             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 (Text):
    1. every tick:
    2.     loop all players:
    3.         if amount of {pick::%loop-player%} = 2:
    4.             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]"
    5.             set {pickcost::%loop-player%} to 32
    6.             set {pickcost2::%loop-player%} to 32
    7.             stop
    8.         if amount of {pick::%loop-player%} = 3:
    9.             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]"
    10.             set {pickcost::%loop-player%} to 48
    11.             set {pickcost2::%loop-player%} to 48
    12.             stop
    13.         if amount of {pick::%loop-player%} = 4:
    14.             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]"
    15.             set {pickcost::%loop-player%} to 64
    16.             set {pickcost2::%loop-player%} to 64
    17.             stop


     
    #1 Pqngs, May 29, 2021
    Last edited: May 29, 2021
  2. Best Answer:
    Post #10 by Minecoll_YT, May 29, 2021
  3. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    I dont think you understand how list variables work
    edit: nvm, ignore that
    --- Double Post Merged, May 29, 2021, Original Post Date: May 29, 2021 ---
    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
     
  4. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    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
    --- Double Post Merged, May 29, 2021 ---
    I updated the main post to show my changes. didn't work :/
     
  5. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    Tell me what u need and I script it for ya
     
    • Friendly Friendly x 1
  6. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0

    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.
     
    #5 Pqngs, May 29, 2021
    Last edited: May 29, 2021
  7. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    sry took me a while to figure out the enchanting part..

    Code (Text):
    1. options:
    2.   increaseCost: 16
    3.   maxLevel: 5
    4.  
    5. on right click with wooden pickaxe:
    6.   if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    7.     set {_x} to name of player's tool
    8.     replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    9.     replace all "&8]" with "" in {_x}
    10.     set {_currentlevel} to {_x} parsed as a integer
    11.     if {_currentlevel} is not set:
    12.       send "&7Invalid level&8."
    13.     else:
    14.       if {_currentlevel} is less than {@maxLevel}:
    15.         set {_cost} to {@increaseCost} * {_currentlevel}
    16.         if amount of coal in player's inventory is more than or equal to {_cost}:
    17.           open virtual chest inventory with size 1 named "&1&0Pickaxe Upgrading" to player
    18.           format gui slot 2 of player with red wool named "&cCancel" to close
    19.           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})
    20.         else:
    21.           send "You need at least %{_cost}% coal"
    22.       else:
    23.         send "You reached the limit of upgrading"
    24.  
    25. function upgradePickaxe(p: player, cost: number, currentlevel: number):
    26.   if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    27.     set {_nextlevel} to {_currentlevel} + 1
    28.     remove {_cost} of coal from {_p}'s inventory
    29.     set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    30.     set level of efficiency of {_p}'s tool to {_nextlevel}
    31.  
    32. command /getpickaxe [<text>]:
    33.   permission: op
    34.   trigger:
    35.     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
    --- Double Post Merged, May 29, 2021, Original Post Date: May 29, 2021 ---
    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
     
    • Winner Winner x 1
  8. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    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:
    --- Double Post Merged, May 29, 2021 ---
    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
     
  9. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    Could you send the whole function thing? Or what you have changed?
     
    #8 Minecoll_YT, May 29, 2021
    Last edited: May 29, 2021
  10. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    I changed pretty much a lot around the skript. I'll just send you the new skript.
    Code (Text):
    1. on first join:
    2.     execute player command "/start-game"
    3.  
    4. options:
    5.   increaseCost: 16
    6.   maxLevel: 5
    7.  
    8. on inventory click:
    9.     if name of event-inventory is "&8Are you sure?":
    10.         if index of event-slot = 6:
    11.             cancel event
    12.             close player's inventory
    13.  
    14. on inventory click:
    15.     if name of event-inventory is "&8Are you sure?":
    16.         if index of event-slot = 2:
    17.             play sound "entity.experience_orb.pickup" to player
    18.             send action bar "&aYou successfully updated your pickaxe to tier &2%{_currentlevel}%" to player
    19.             cancel event
    20.             close player's inventory
    21.             run function upgradePickaxe(player, {_cost}, {_currentlevel})
    22. on right click with wooden pickaxe:
    23.   if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    24.     set {_x} to name of player's tool
    25.     replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    26.     replace all "&8]" with "" in {_x}
    27.     set {_currentlevel} to {_x} parsed as a integer
    28.     if {_currentlevel} is not set:
    29.       send "&7Invalid level&8."
    30.     else:
    31.       if {_currentlevel} is less than {@maxLevel}:
    32.         set {_cost} to {@increaseCost} * {_currentlevel}
    33.         if amount of coal in player's inventory is more than or equal to {_cost}:
    34.           set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
    35.           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"
    36.           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"
    37.           open {_gui} to player
    38.         else:
    39.           send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
    40.       else:
    41.         send "&cYou can't upgrade any further!"
    42.  
    43. function upgradePickaxe(p: player, cost: number, currentlevel: number):
    44.   if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    45.     set {_nextlevel} to {_currentlevel} + 1
    46.     remove {_cost} of coal from {_p}'s inventory
    47.     set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    48.     set level of efficiency of {_p}'s tool to {_nextlevel}
    49.  
    50. command /getpickaxe [<text>]:
    51.   permission: op
    52.   trigger:
    53.     give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"
    54.  
    55. command /start-game:
    56.     permission: op
    57.     trigger:
    58.         set {_currentlevel} to 0
    59.        
    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.
     
  11. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    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
    --- Double Post Merged, May 29, 2021, Original Post Date: May 29, 2021 ---
    Try:
    Code (Text):
    1.  
    2. options:
    3.   increaseCost: 16
    4.   maxLevel: 5
    5.  
    6. on quit:
    7.   delete {lastcost::%player%}
    8.   delete {lastlevel::%player%}
    9.  
    10. on inventory click:
    11.   if name of event-inventory is "&8Are you sure?":
    12.     if index of event-slot = 6:
    13.       cancel event
    14.         close player's inventory
    15.     else if index of event-slot = 2:
    16.       cancel event
    17.       close player's inventory
    18.       upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})
    19.  
    20. on right click with wooden pickaxe:
    21.   if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    22.     set {_x} to name of player's tool
    23.     replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    24.     replace all "&8]" with "" in {_x}
    25.     set {_currentlevel} to {_x} parsed as a integer
    26.     if {_currentlevel} is not set:
    27.       send "&7Invalid level&8."
    28.     else:
    29.       if {_currentlevel} is less than {@maxLevel}:
    30.         set {_cost} to {@increaseCost} * {_currentlevel}
    31.         if amount of coal in player's inventory is more than or equal to {_cost}:
    32.           set {lastlevel::%player%} to {_currentlevel}
    33.           set {lastcost::%player%} to {_cost}
    34.           set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
    35.           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"
    36.           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"
    37.           open {_gui} to player
    38.         else:
    39.           send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
    40.       else:
    41.         send "&cYou can't upgrade any further!"
    42.  
    43. function upgradePickaxe(p: player, cost: number, currentlevel: number):
    44.   if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    45.     set {_nextlevel} to {_currentlevel} + 1
    46.     remove {_cost} of coal from {_p}'s inventory
    47.     set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    48.     set level of efficiency of {_p}'s tool to {_nextlevel}
    49.     play sound "entity.experience_orb.pickup" to {_p}
    50.     send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    51.  
    52. command /getpickaxe [<text>]:
    53.   permission: op
    54.   trigger:
    55.     give player wooden pickaxe of efficiency 1 named "&7Wooden Pickaxe&8 [&c1&8]"
    56.  
     
  12. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    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
    --- Double Post Merged, May 29, 2021 ---
    I also have to go and will be back in 20 minutes. Expect a late message!
     
  13. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    Any error messages?
     
  14. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    Oh. no. Forgot to mention, there's no error messages
    it's just that when you click "confirm" everything works perfectly like the rename, closing the gui, etc. everything besides the enchantments...
     
  15. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
  16. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    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:
     
  17. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    So Level 1 would be a pickaxe with no efficiency? If yes change:
    Code (Text):
    1. set level of efficiency of {_p}'s tool to {_nextlevel}
    to
    Code (Text):
    1. set level of efficiency of {_p}'s tool to {_nextlevel} -1
    or
    Code (Text):
    1. set level of efficiency of {_p}'s tool to ({_nextlevel} -1)
     
  18. Pqngs

    Pqngs Member

    Joined:
    May 28, 2021
    Messages:
    11
    Likes Received:
    0
    Thanks a lot! This really helps me out :emoji_slight_smile:
    --- Double Post Merged, May 30, 2021, Original Post Date: May 29, 2021 ---
    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 (Text):
    1. options:
    2.   increaseCost: 16
    3.   maxLevel: 6
    4.  
    5. on quit:
    6.   delete {lastcost::%player%}
    7.   delete {lastlevel::%player%}
    8.  
    9. on inventory click:
    10.   if name of event-inventory is "&8Are you sure?":
    11.     if index of event-slot = 6:
    12.       cancel event
    13.       close player's inventory
    14.     else if index of event-slot = 2:
    15.       cancel event
    16.       close player's inventory
    17.       upgradePickaxe(player, {lastcost::%player%}, {lastlevel::%player%})
    18.  
    19. on right click with wooden pickaxe:
    20.   if name of player's tool contains "&7Wooden Pickaxe&8 [&c":
    21.     set {_x} to name of player's tool
    22.     replace all "&7Wooden Pickaxe&8 [&c" with "" in {_x}
    23.     replace all "&8]" with "" in {_x}
    24.     set {_currentlevel} to {_x} parsed as a integer
    25.     if {_currentlevel} is not set:
    26.       send "&cYou can't upgrade further."
    27.     else:
    28.       if {_currentlevel} is less than {@maxLevel}:
    29.         set {_cost} to {@increaseCost} * {_currentlevel}
    30.         if amount of coal in player's inventory is more than or equal to {_cost}:
    31.           set {lastlevel::%player%} to {_currentlevel}
    32.           set {lastcost::%player%} to {_cost}
    33.           set {_gui} to a new chest inventory with 1 row with name "&8Are you sure?"
    34.           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"
    35.           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"
    36.           open {_gui} to player
    37.         else:
    38.           play sound "block.anvil.break" to player
    39.           send "&cYou need &c%{_cost}% &ccoal to upgrade this!"
    40.       else:
    41.         play sound "block.anvil.break" to player
    42.         send "&cYou can't upgrade any further!"
    43.  
    44. function upgradePickaxe(p: player, cost: number, currentlevel: number):
    45.   if amount of coal in {_p}'s inventory is more than or equal to {_cost}:
    46.     set {_nextlevel} to {_currentlevel} + 1
    47.     remove {_cost} of coal from {_p}'s inventory
    48.     if {_nextlevel} = 6:
    49.       set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c&lMAX&8]"
    50.       enchant {_p}'s tool with efficiency 5
    51.       send action bar "&aYou successfully updated your pickaxe to the&2 Max Level&a." to {_p}
    52.       play sound "entity.experience_orb.pickup" to {_p}
    53.       play sound "ui.toast.challenge_complete" with volume 1 and pitch 2 to {_p}
    54.     else:
    55.       set name of tool of {_p} to "&7Wooden Pickaxe&8 [&c%{_nextlevel}%&8]"
    56.       if {_p}'s tool isn't enchanted:
    57.         enchant {_p}'s tool with efficiency 1
    58.         send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    59.         play sound "entity.experience_orb.pickup" to {_p}
    60.       else:
    61.         set {_} to level of efficiency of {_p}'s tool
    62.         if {_} = 1:
    63.           set level of efficiency of {_p}'s tool to 2
    64.           play sound "entity.experience_orb.pickup" to {_p}
    65.           send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    66.         if {_} = 2:
    67.           set level of efficiency of {_p}'s tool to 3
    68.           play sound "entity.experience_orb.pickup" to {_p}
    69.           send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    70.         if {_} = 3:
    71.           set level of efficiency of {_p}'s tool to 4
    72.           play sound "entity.experience_orb.pickup" to {_p}
    73.           send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    74.         if {_} = 4:
    75.           set level of efficiency of {_p}'s tool to 5
    76.           play sound "entity.experience_orb.pickup" to {_p}
    77.           send action bar "&aYou successfully updated your pickaxe to tier &2%{_nextlevel}%" to {_p}
    78.  
    79. command /getpickaxe [<text>]:
    80.     permission: op
    81.     trigger:
    82.         give player wooden pickaxe named "&7Wooden Pickaxe&8 [&c1&8]"
    83.         give player 64 coal
    84.  
    85. command /picktest:
    86.     permission: op
    87.     trigger:
    88.         set {_} to level of efficiency of player's tool
    89.         send "%{_}%"
    90.         send "level: %{_currentlevel}%"
     
Thread Status:
Not open for further replies.

Share This Page

Loading...