Custom Enchants not working

Discussion in 'Skript' started by B1a7e, Apr 2, 2020.

  1. So im making custom enchants and whenever you try to level-up the enchantment it will just stay at level 1
    Code (Text):
    command /explosive [<player>]:
        permission: admin.core
        trigger:
            set {explosivecost1::%arg-1's uuid%} to 3rd line of lore of tool of arg 1
            set {explosivecost::%arg-1%} to 50000+10000*{explosivecost1::%arg-1's uuid%}
            if {token::%arg-1's uuid%} is greater or equal to {explosivecost::%arg-1%}:
                remove {explosivecost::%arg-1%} from {token::%arg-1's uuid%}
                execute command "/scoreboardrl %arg-1%"
                if {explosive::%arg-1's uuid%} is not set:
                    set 3rd line of lore of arg-1's tool to "&7Explosive &71"
                    message "&5&l(!)&d You have upgraded explosive to &r1&d!" to arg-1
                if {explosive::%arg-1's uuid%} is set:
                    replace all "&7Explosive" with "" in {explosivecost1::%arg-1's uuid%}
                    set {explosive::%arg-1's uuid%} to {explosivecost1::%arg-1's uuid%} + 1
                    set 3rd line of lore of arg-1's tool to "&7Explosive &7%{explosive::%arg-1's uuid%}%"
                    message "&5&l(!)&d You have upgraded explosive to &r%{explosive::%arg-1's uuid%}%&d!" to arg-1
                make arg-1 execute command "/upgradepickaxe"
                clear {explosivecost::%arg-1%}
                clear {explosivecost1::%arg-1%}
            else:
                close inventory of arg-1
                message "&cInsufficient Funds! (Needed %{explosivecost::%arg-1%}%&c)" to arg-1
                clear {explosivecost::%arg-1%}
                clear {explosivecost1::%arg-1%}
     
  2. Code (Text):


          set {explosivecost1::%arg-1's uuid%} to 3rd line of lore of tool of arg 1
            set {explosivecost::%arg-1%} to 50000+10000*{explosivecost1::%arg-1's uuid%}
    here's your problem.

    you've forgot that lore is a string, thus it cannot be multiplied or added, because it is not a number.

    solution:
    if the lore has a number in it, make the server understand that it is number by first parsing it as a number, like this:
    Code (Text):

    set {_text} to "5"
    set {_number} to {_text} parsed as a number
     
    in your code that would be:
    Code (Text):


          set {explosivecost1::%arg-1's uuid%} to (3rd line of lore of tool of arg 1) parsed as a number
          set {explosivecost::%arg-1%} to 50000+10000*{explosivecost1::%arg-1's uuid%}
     
    but then it becomes really confusing, this line:
    Code (Text):
    replace all "&7Explosive" with "" in {explosivecost1::%arg-1's uuid%}
    so in some places you're treating it as a text, in some as a number, you really have to pick one. here's how your code looks outside variables:
    Code (Text):

    start:
    set {explosivecost::%arg-1%} to 50000+10000 * "Explosive 1"

    after replacing:
    set {explosive::%arg-1's uuid%} to " 1" + 1
     


    another thing, why are you using global variables here? if you're just clearing them immediately after, use {_variables}, they're more performant.

    and one more tip, use functions instead of commands, they're also more performant
     
    #2 Govindas, Apr 3, 2020
    Last edited: Apr 3, 2020