Equip player with an enchanted armour piece and name using variables

  • 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.

Chriz

Member
Aug 30, 2020
18
1
3
How can i make this work?


Code:
            set {kit} to "name"
            set {gearQuality} to "diamond"
            set {protection} to 1
            set {looptimes} to 0
            loop 4 times:
                add 1 to {looptimes}
                if {looptimes} is 1:
                    set {piece} to "%{gearQuality}% helmet"
                else if {looptimes} is 2:
                    set {piece} to "%{gearQuality}% chestplate"
                else if {looptimes} is 3:
                    set {piece} to "%{gearQuality}% leggings"
                else if {looptimes} is 4:
                    set {piece} to "%{gearQuality}% boots"
                if player is not wearing {piece}:
                    if {protection} is 0:
                        equip player with {piece} named "%{kit}%"
                    else:
                        equip player with {piece} of protection {protection} named "%{kit}%"
                else:
                    if {protection} is 0:
                        give {piece} named "%{kit}%" to the player
                    else:
                        give {piece} of protection {protection} named "%{kit}%" to the player
 
Last edited:
I have few marks, you are trying to give/equip the player a string because {piece} variables is set to a text and not an item stack so you would need to parse it as an item as the following example
Code:
set {piece} to "%{gearQuality}% boots" parsed as item
#now you can safely use the variable as an item as long as the parsed string formed an item stack
There is absolutly no need to create {looptime} variable as loop in skript has a its usefull expressions like loop-number which returns the current iteration and if you ever feel that you need to have that variable then make it local by adding "_" before the variable name (I'm sure you didn't notice that {looptime} will remain at 4 after the first execution therfore it will break the entire code. Please read about global and local variables in the wiki ) .
Your whole loop is useless just create local variables for each item and give/equip them to a player in individual lines, still want to loop instead ? Save the items to a list and loop though it !
 
  • Like
Reactions: Chriz
Thank you for the help, still have some issues, want to make it so the people I'm making it for can easily add more kits. Which is why I went to the trouble of adding the different variables (they cant script). The entire script is listed below however its only the last part (line.213 and after) I have issues with the equipping of items that are using {piece} and {protection} in the same line.
Code:
#
#    Stat GUI
#
command /stats:
    trigger:
        open virtual chest inventory with size 1 named "&bStats" to player
        format gui slot 0 of player with player head named "&aIGName: &b%player%"
        format gui slot 1 of player with slimeball named "&aBalance:&r &b%{%player%.bal}%"
#        format gui slot 2 of player with  named ""
#        format gui slot 3 of player with  named ""       
        format gui slot 4 of player with red concrete named "&aKills:&r &b%{%player%.kills}%"
        format gui slot 5 of player with totem of undying named "&aK/D&r &b%{%player%.kills}/{%player%.deaths}%"
        format gui slot 6 of player with black concrete named "&aDeaths:&r &b%{%player%.deaths}%"
#        format gui slot 7 of player with  named ""
#        format gui slot 8 of player with  named ""
        
#
#    JOIN STATS
#
on join:
    if {%player%.bal} is not set:
        set {%player%.bal} to 0
    if {%player%.deaths} is not set:
        set {%player%.deaths} to 0
    if {%player%.kills} is not set:
        set {%player%.kills} to 0
    if {%player%.kitsowned} is not set:
        set {%player%.kitsowned} to 0
#    kits
    if {%player%.kit1} is not set:
        set {%player%.kit1} to 0
    if {%player%.kit2} is not set:
        set {%player%.kit2} to 0
    if {%player%.kit3} is not set:
        set {%player%.kit3} to 0
    if {%player%.kit4} is not set:
        set {%player%.kit4} to 0
    if {%player%.kit5} is not set:
        set {%player%.kit5} to 0
#
#    PLAYER KILL
#
on death:
    victim is a player:
        attacker is a player:
            add 1 to {%victim%.deaths}
            add 1 to {%damager%.kills}
            add 15 to {%player%.bal}
            give damager 1 golden apple
            add 1 to {%damager%.strength}
            apply strength {%damager%.strength} to the damager for 10 seconds
            wait for 10 seconds
            remove 1 from {%damager%.strength}

#
#    KIT VISUAL GUI
#
command /kits:
    trigger:
#    Variables
        set {kit1} to "&cplaceholder"
        set {kit2} to "&cplaceholder"
        set {kit3} to "&cplaceholder"
        set {kit4} to "&cplaceholder"
        set {kit5} to "&cplaceholder"
        
        open virtual chest inventory with size 6 named "&6Kits" to player
#    Boarder
        set {loopnumber} to 0
        loop 8 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
        loop 4 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 8 to {loopnumber}
        loop 10 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
#    Kits
        format gui slot 20 of player with wooden sword named "%{kit1}%"
        format gui slot 22 of player with stone sword named "%{kit2}%"
        format gui slot 24 of player with iron sword named "%{kit3}%"
        format gui slot 30 of player with diamond sword named "%{kit4}%"
        format gui slot 32 of player with bow named "%{kit5}%"


#
#    KIT PRICES
#
on inventory click:
    if inventory name of player's current inventory is "&6Kits":
        if "%click type%" contains "LEFT":
            set {%player%.kitprice} to {%player%.kitsowned}*100+200
#    Buy / Select Kit
            name of clicked item is {kit1}:
                if {%player%.kit1} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit1} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit1} is 1:
                    set {kitselect} to 1                   
                    
                    
            name of clicked item is "%{kit2}%":
                if {%player%.kit2} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit2} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit2} is 1:
                    set {kitselect} to 2
                
                
            name of clicked item is "%{kit3}%":
                if {%player%.kit3} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit3} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit3} is 1:
                    set {kitselect} to 3
                
                
            name of clicked item is "%{kit4}%":
                if {%player%.kit4} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit4} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit4} is 1:
                    set {kitselect} to 4
                
                
            name of clicked item is "%{kit5}%":
                if {%player%.kit5} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit5} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit5} is 1:
                    set {kitselect} to 5
                    
    #    Kits
            if {kitselect} is 1:
                set {kit} to "%{kit1}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 2
                set {sharpness} to 2
                set {gapple} to 2
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
                
            if {kitselect} is 2:
                set {kit} to "%{kit2}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 3
                set {sharpness} to 3
                set {gapple} to 4
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
                
            if {kitselect} is 3:
                set {kit} to "%{kit}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 4
                set {sharpness} to 4
                set {gapple} to 6
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
                
            if {kitselect} is 4:
                set {kit} to "%{kit4}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 5
                set {sharpness} to 5
                set {gapple} to 8
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
                
            if {kitselect} is 5:
                set {kit} to "name"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 1
                set {sharpness} to 1
                set {gapple} to 2
                set {bow} to 1
                set {power} to 5
                set {infinity} to 1
                set {arrow} to 1


    #    Gear Piece
            loop 4 times:
                if loop-number is 1:
                    set {piece} to "%{gearQuality}% helmet" parsed as item
                else if loop-number is 2:
                    set {piece} to "%{gearQuality}% chestplate" parsed as item
                else if loop-number is 3:
                    set {piece} to "%{gearQuality}% leggings" parsed as item
                else if loop-number is 4:
                    set {piece} to "%{gearQuality}% boots" parsed as item
                if player is not wearing {piece}:
                    if {protection} is 0:
                        equip player with {piece} named "%{kit}%"
                    else:
                        equip player with {piece} of protection {protection} named "%{kit}%"
                else:
                    if {protection} is 0:
                        give {piece} named "%{kit}%" to the player
                    else:
                        give {piece} of protection {protection} named "%{kit}%" to the player

    #    Sword / Bow
            if {sharpness} is 0:
                give {swordQuality} sword named "%{kit}%" to the player
            else:
                give {swordQuality} sword of sharpness {sharpness} named "%{kit}%" to the player
            if {bow} is 1:
                if {power} is 0:
                    give bow named "%{kit}%" to the player
                else:
                    if {infinity} is 1:
                        give bow of infinity and power  named "%{kit}%" to the player
                    else if {infinity} is 0:
                        give bow of power {power} named "%{kit}%" to the player
                
    #    Extras
            give {gapple} golden apple to the player
            give {arrow} arrow to the player


#    Kit Copy Paste
#                    set {kit} to "%{kit}%"
#                    set {gearQuality} to ""
#                    set {swordQuality} to ""
#                    set {protection} to
#                    set {sharpness} to
#                    set {gapple} to
#                    set {bow} to
#                    set {power} to
#                    set {infinity} to
#                    set {arrow} to
 
Thank you for the help, still have some issues, want to make it so the people I'm making it for can easily add more kits. Which is why I went to the trouble of adding the different variables (they cant script). The entire script is listed below however its only the last part (line.213 and after) I have issues with the equipping of items that are using {piece} and {protection} in the same line.9
Code:
#
#    Stat GUI
#
command /stats:
    trigger:
        open virtual chest inventory with size 1 named "&bStats" to player
        format gui slot 0 of player with player head named "&aIGName: &b%player%"
        format gui slot 1 of player with slimeball named "&aBalance:&r &b%{%player%.bal}%"
#        format gui slot 2 of player with  named ""
#        format gui slot 3 of player with  named "" 
        format gui slot 4 of player with red concrete named "&aKills:&r &b%{%player%.kills}%"
        format gui slot 5 of player with totem of undying named "&aK/D&r &b%{%player%.kills}/{%player%.deaths}%"
        format gui slot 6 of player with black concrete named "&aDeaths:&r &b%{%player%.deaths}%"
#        format gui slot 7 of player with  named ""
#        format gui slot 8 of player with  named ""
  
#
#    JOIN STATS
#
on join:
    if {%player%.bal} is not set:
        set {%player%.bal} to 0
    if {%player%.deaths} is not set:
        set {%player%.deaths} to 0
    if {%player%.kills} is not set:
        set {%player%.kills} to 0
    if {%player%.kitsowned} is not set:
        set {%player%.kitsowned} to 0
#    kits
    if {%player%.kit1} is not set:
        set {%player%.kit1} to 0
    if {%player%.kit2} is not set:
        set {%player%.kit2} to 0
    if {%player%.kit3} is not set:
        set {%player%.kit3} to 0
    if {%player%.kit4} is not set:
        set {%player%.kit4} to 0
    if {%player%.kit5} is not set:
        set {%player%.kit5} to 0
#
#    PLAYER KILL
#
on death:
    victim is a player:
        attacker is a player:
            add 1 to {%victim%.deaths}
            add 1 to {%damager%.kills}
            add 15 to {%player%.bal}
            give damager 1 golden apple
            add 1 to {%damager%.strength}
            apply strength {%damager%.strength} to the damager for 10 seconds
            wait for 10 seconds
            remove 1 from {%damager%.strength}

#
#    KIT VISUAL GUI
#
command /kits:
    trigger:
#    Variables
        set {kit1} to "&cplaceholder"
        set {kit2} to "&cplaceholder"
        set {kit3} to "&cplaceholder"
        set {kit4} to "&cplaceholder"
        set {kit5} to "&cplaceholder"
  
        open virtual chest inventory with size 6 named "&6Kits" to player
#    Boarder
        set {loopnumber} to 0
        loop 8 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
        loop 4 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 8 to {loopnumber}
        loop 10 times:
            format gui slot {loopnumber} of player with light blue stained glass pane named " "
            add 1 to {loopnumber}
#    Kits
        format gui slot 20 of player with wooden sword named "%{kit1}%"
        format gui slot 22 of player with stone sword named "%{kit2}%"
        format gui slot 24 of player with iron sword named "%{kit3}%"
        format gui slot 30 of player with diamond sword named "%{kit4}%"
        format gui slot 32 of player with bow named "%{kit5}%"


#
#    KIT PRICES
#
on inventory click:
    if inventory name of player's current inventory is "&6Kits":
        if "%click type%" contains "LEFT":
            set {%player%.kitprice} to {%player%.kitsowned}*100+200
#    Buy / Select Kit
            name of clicked item is {kit1}:
                if {%player%.kit1} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit1} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit1} is 1:
                    set {kitselect} to 1             
              
              
            name of clicked item is "%{kit2}%":
                if {%player%.kit2} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit2} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit2} is 1:
                    set {kitselect} to 2
          
          
            name of clicked item is "%{kit3}%":
                if {%player%.kit3} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit3} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit3} is 1:
                    set {kitselect} to 3
          
          
            name of clicked item is "%{kit4}%":
                if {%player%.kit4} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit4} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit4} is 1:
                    set {kitselect} to 4
          
          
            name of clicked item is "%{kit5}%":
                if {%player%.kit5} is 0:
                    if {%player%.bal} >= {%player%.kitprice}:
                        set {%player%.kit5} to 1
                        message "&aA purchase was made"
                    else:
                        message "&cYou dont have $%{%player%.kitprice}%"
                if {%player%.kit5} is 1:
                    set {kitselect} to 5
              
    #    Kits
            if {kitselect} is 1:
                set {kit} to "%{kit1}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 2
                set {sharpness} to 2
                set {gapple} to 2
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
          
            if {kitselect} is 2:
                set {kit} to "%{kit2}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 3
                set {sharpness} to 3
                set {gapple} to 4
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
          
            if {kitselect} is 3:
                set {kit} to "%{kit}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 4
                set {sharpness} to 4
                set {gapple} to 6
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
          
            if {kitselect} is 4:
                set {kit} to "%{kit4}%"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 5
                set {sharpness} to 5
                set {gapple} to 8
                set {bow} to 0
                set {power} to 0
                set {infinity} to 0
                set {arrow} to 0
          
            if {kitselect} is 5:
                set {kit} to "name"
                set {gearQuality} to "diamond"
                set {swordQuality} to "diamond"
                set {protection} to 1
                set {sharpness} to 1
                set {gapple} to 2
                set {bow} to 1
                set {power} to 5
                set {infinity} to 1
                set {arrow} to 1


    #    Gear Piece
            loop 4 times:
                if loop-number is 1:
                    set {piece} to "%{gearQuality}% helmet" parsed as item
                else if loop-number is 2:
                    set {piece} to "%{gearQuality}% chestplate" parsed as item
                else if loop-number is 3:
                    set {piece} to "%{gearQuality}% leggings" parsed as item
                else if loop-number is 4:
                    set {piece} to "%{gearQuality}% boots" parsed as item
                if player is not wearing {piece}:
                    if {protection} is 0:
                        equip player with {piece} named "%{kit}%"
                    else:
                        equip player with {piece} of protection {protection} named "%{kit}%"
                else:
                    if {protection} is 0:
                        give {piece} named "%{kit}%" to the player
                    else:
                        give {piece} of protection {protection} named "%{kit}%" to the player

    #    Sword / Bow
            if {sharpness} is 0:
                give {swordQuality} sword named "%{kit}%" to the player
            else:
                give {swordQuality} sword of sharpness {sharpness} named "%{kit}%" to the player
            if {bow} is 1:
                if {power} is 0:
                    give bow named "%{kit}%" to the player
                else:
                    if {infinity} is 1:
                        give bow of infinity and power  named "%{kit}%" to the player
                    else if {infinity} is 0:
                        give bow of power {power} named "%{kit}%" to the player
          
    #    Extras
            give {gapple} golden apple to the player
            give {arrow} arrow to the player


#    Kit Copy Paste
#                    set {kit} to "%{kit}%"
#                    set {gearQuality} to ""
#                    set {swordQuality} to ""
#                    set {protection} to
#                    set {sharpness} to
#                    set {gapple} to
#                    set {bow} to
#                    set {power} to
#                    set {infinity} to
#                    set {arrow} to

That's not the best way to create a kit system and you will have a pain to add more kits later. Your code need a refractor, I highly recommand you to read about skript lists because I'm going to use that in the next example.
That's how I would make a kit system:
  • Registering a kit

Code:
set {kits::example} to "example kit"
set {kits::example::items::*}  to wooden sword, wooden axe, wooden shovel and 5 of apples
set {kits::example::equipments::*} to iron halmet
  • Giving a kit to the player

Code:
# first argument represent the kit name
command kit <string>:
    trigger:
        # you need to check if the player have inventory space to hold and equip the kit
        If {kits::%arg%} exists:
            give player {kits::%arg%::items::*}
            equip player {kits::%arg%::equipments::*}
        else:
            send "this kit doesn't exist"
See ? The code is much simpler clear and it makes it easy for you to add more kits.
However I will now list the mistakes you made in your code:
  1. Not using list variables.
  2. Still using global variables where it should be a local variable and not taking care to reset iteration variables at the and of the loop.
  3. Using loop improperly and when it's not needed making the code harder to read.
  4. Relying on numbers to determine kit items and type (lead to problem 1).
I advice you to learn more on what skript has, using it's features properly will let you code in ease, checkout the wiki and the docs.
 
Last edited:
Status
Not open for further replies.