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.

Equip player with an enchanted armour piece and name using variables

Discussion in 'Skript' started by Chriz, Aug 30, 2020.

Tags:
Thread Status:
Not open for further replies.
  1. Chriz

    Chriz Member

    Joined:
    Aug 30, 2020
    Messages:
    14
    Likes Received:
    1
    How can i make this work?


    Code (Text):
    1.          
    2.             set {kit} to "name"
    3.             set {gearQuality} to "diamond"
    4.             set {protection} to 1
    5.             set {looptimes} to 0
    6.             loop 4 times:
    7.                 add 1 to {looptimes}
    8.                 if {looptimes} is 1:
    9.                     set {piece} to "%{gearQuality}% helmet"
    10.                 else if {looptimes} is 2:
    11.                     set {piece} to "%{gearQuality}% chestplate"
    12.                 else if {looptimes} is 3:
    13.                     set {piece} to "%{gearQuality}% leggings"
    14.                 else if {looptimes} is 4:
    15.                     set {piece} to "%{gearQuality}% boots"
    16.                 if player is not wearing {piece}:
    17.                     if {protection} is 0:
    18.                         equip player with {piece} named "%{kit}%"
    19.                     else:
    20.                         equip player with {piece} of protection {protection} named "%{kit}%"
    21.                 else:
    22.                     if {protection} is 0:
    23.                         give {piece} named "%{kit}%" to the player
    24.                     else:
    25.                         give {piece} of protection {protection} named "%{kit}%" to the player
     
    #1 Chriz, Aug 30, 2020
    Last edited: Aug 30, 2020
  2. Abdera7mane

    Abdera7mane Active Member

    Joined:
    Aug 18, 2019
    Messages:
    56
    Likes Received:
    7
    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 (Text):
    1. set {piece} to "%{gearQuality}% boots" parsed as item
    2. #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 Like x 1
  3. Chriz

    Chriz Member

    Joined:
    Aug 30, 2020
    Messages:
    14
    Likes Received:
    1
    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 (Text):
    1. #
    2. #    Stat GUI
    3. #
    4. command /stats:
    5.     trigger:
    6.         open virtual chest inventory with size 1 named "&bStats" to player
    7.         format gui slot 0 of player with player head named "&aIGName: &b%player%"
    8.         format gui slot 1 of player with slimeball named "&aBalance:&r &b%{%player%.bal}%"
    9. #        format gui slot 2 of player with  named ""
    10. #        format gui slot 3 of player with  named ""      
    11.         format gui slot 4 of player with red concrete named "&aKills:&r &b%{%player%.kills}%"
    12.         format gui slot 5 of player with totem of undying named "&aK/D&r &b%{%player%.kills}/{%player%.deaths}%"
    13.         format gui slot 6 of player with black concrete named "&aDeaths:&r &b%{%player%.deaths}%"
    14. #        format gui slot 7 of player with  named ""
    15. #        format gui slot 8 of player with  named ""
    16.        
    17. #
    18. #    JOIN STATS
    19. #
    20. on join:
    21.     if {%player%.bal} is not set:
    22.         set {%player%.bal} to 0
    23.     if {%player%.deaths} is not set:
    24.         set {%player%.deaths} to 0
    25.     if {%player%.kills} is not set:
    26.         set {%player%.kills} to 0
    27.     if {%player%.kitsowned} is not set:
    28.         set {%player%.kitsowned} to 0
    29. #    kits
    30.     if {%player%.kit1} is not set:
    31.         set {%player%.kit1} to 0
    32.     if {%player%.kit2} is not set:
    33.         set {%player%.kit2} to 0
    34.     if {%player%.kit3} is not set:
    35.         set {%player%.kit3} to 0
    36.     if {%player%.kit4} is not set:
    37.         set {%player%.kit4} to 0
    38.     if {%player%.kit5} is not set:
    39.         set {%player%.kit5} to 0
    40. #
    41. #    PLAYER KILL
    42. #
    43. on death:
    44.     victim is a player:
    45.         attacker is a player:
    46.             add 1 to {%victim%.deaths}
    47.             add 1 to {%damager%.kills}
    48.             add 15 to {%player%.bal}
    49.             give damager 1 golden apple
    50.             add 1 to {%damager%.strength}
    51.             apply strength {%damager%.strength} to the damager for 10 seconds
    52.             wait for 10 seconds
    53.             remove 1 from {%damager%.strength}
    54.  
    55. #
    56. #    KIT VISUAL GUI
    57. #
    58. command /kits:
    59.     trigger:
    60. #    Variables
    61.         set {kit1} to "&cplaceholder"
    62.         set {kit2} to "&cplaceholder"
    63.         set {kit3} to "&cplaceholder"
    64.         set {kit4} to "&cplaceholder"
    65.         set {kit5} to "&cplaceholder"
    66.        
    67.         open virtual chest inventory with size 6 named "&6Kits" to player
    68. #    Boarder
    69.         set {loopnumber} to 0
    70.         loop 8 times:
    71.             format gui slot {loopnumber} of player with light blue stained glass pane named " "
    72.             add 1 to {loopnumber}
    73.         loop 4 times:
    74.             format gui slot {loopnumber} of player with light blue stained glass pane named " "
    75.             add 1 to {loopnumber}
    76.             format gui slot {loopnumber} of player with light blue stained glass pane named " "
    77.             add 8 to {loopnumber}
    78.         loop 10 times:
    79.             format gui slot {loopnumber} of player with light blue stained glass pane named " "
    80.             add 1 to {loopnumber}
    81. #    Kits
    82.         format gui slot 20 of player with wooden sword named "%{kit1}%"
    83.         format gui slot 22 of player with stone sword named "%{kit2}%"
    84.         format gui slot 24 of player with iron sword named "%{kit3}%"
    85.         format gui slot 30 of player with diamond sword named "%{kit4}%"
    86.         format gui slot 32 of player with bow named "%{kit5}%"
    87.  
    88.  
    89. #
    90. #    KIT PRICES
    91. #
    92. on inventory click:
    93.     if inventory name of player's current inventory is "&6Kits":
    94.         if "%click type%" contains "LEFT":
    95.             set {%player%.kitprice} to {%player%.kitsowned}*100+200
    96. #    Buy / Select Kit
    97.             name of clicked item is {kit1}:
    98.                 if {%player%.kit1} is 0:
    99.                     if {%player%.bal} >= {%player%.kitprice}:
    100.                         set {%player%.kit1} to 1
    101.                         message "&aA purchase was made"
    102.                     else:
    103.                         message "&cYou dont have $%{%player%.kitprice}%"
    104.                 if {%player%.kit1} is 1:
    105.                     set {kitselect} to 1                  
    106.                    
    107.                    
    108.             name of clicked item is "%{kit2}%":
    109.                 if {%player%.kit2} is 0:
    110.                     if {%player%.bal} >= {%player%.kitprice}:
    111.                         set {%player%.kit2} to 1
    112.                         message "&aA purchase was made"
    113.                     else:
    114.                         message "&cYou dont have $%{%player%.kitprice}%"
    115.                 if {%player%.kit2} is 1:
    116.                     set {kitselect} to 2
    117.                
    118.                
    119.             name of clicked item is "%{kit3}%":
    120.                 if {%player%.kit3} is 0:
    121.                     if {%player%.bal} >= {%player%.kitprice}:
    122.                         set {%player%.kit3} to 1
    123.                         message "&aA purchase was made"
    124.                     else:
    125.                         message "&cYou dont have $%{%player%.kitprice}%"
    126.                 if {%player%.kit3} is 1:
    127.                     set {kitselect} to 3
    128.                
    129.                
    130.             name of clicked item is "%{kit4}%":
    131.                 if {%player%.kit4} is 0:
    132.                     if {%player%.bal} >= {%player%.kitprice}:
    133.                         set {%player%.kit4} to 1
    134.                         message "&aA purchase was made"
    135.                     else:
    136.                         message "&cYou dont have $%{%player%.kitprice}%"
    137.                 if {%player%.kit4} is 1:
    138.                     set {kitselect} to 4
    139.                
    140.                
    141.             name of clicked item is "%{kit5}%":
    142.                 if {%player%.kit5} is 0:
    143.                     if {%player%.bal} >= {%player%.kitprice}:
    144.                         set {%player%.kit5} to 1
    145.                         message "&aA purchase was made"
    146.                     else:
    147.                         message "&cYou dont have $%{%player%.kitprice}%"
    148.                 if {%player%.kit5} is 1:
    149.                     set {kitselect} to 5
    150.                    
    151.     #    Kits
    152.             if {kitselect} is 1:
    153.                 set {kit} to "%{kit1}%"
    154.                 set {gearQuality} to "diamond"
    155.                 set {swordQuality} to "diamond"
    156.                 set {protection} to 2
    157.                 set {sharpness} to 2
    158.                 set {gapple} to 2
    159.                 set {bow} to 0
    160.                 set {power} to 0
    161.                 set {infinity} to 0
    162.                 set {arrow} to 0
    163.                
    164.             if {kitselect} is 2:
    165.                 set {kit} to "%{kit2}%"
    166.                 set {gearQuality} to "diamond"
    167.                 set {swordQuality} to "diamond"
    168.                 set {protection} to 3
    169.                 set {sharpness} to 3
    170.                 set {gapple} to 4
    171.                 set {bow} to 0
    172.                 set {power} to 0
    173.                 set {infinity} to 0
    174.                 set {arrow} to 0
    175.                
    176.             if {kitselect} is 3:
    177.                 set {kit} to "%{kit}%"
    178.                 set {gearQuality} to "diamond"
    179.                 set {swordQuality} to "diamond"
    180.                 set {protection} to 4
    181.                 set {sharpness} to 4
    182.                 set {gapple} to 6
    183.                 set {bow} to 0
    184.                 set {power} to 0
    185.                 set {infinity} to 0
    186.                 set {arrow} to 0
    187.                
    188.             if {kitselect} is 4:
    189.                 set {kit} to "%{kit4}%"
    190.                 set {gearQuality} to "diamond"
    191.                 set {swordQuality} to "diamond"
    192.                 set {protection} to 5
    193.                 set {sharpness} to 5
    194.                 set {gapple} to 8
    195.                 set {bow} to 0
    196.                 set {power} to 0
    197.                 set {infinity} to 0
    198.                 set {arrow} to 0
    199.                
    200.             if {kitselect} is 5:
    201.                 set {kit} to "name"
    202.                 set {gearQuality} to "diamond"
    203.                 set {swordQuality} to "diamond"
    204.                 set {protection} to 1
    205.                 set {sharpness} to 1
    206.                 set {gapple} to 2
    207.                 set {bow} to 1
    208.                 set {power} to 5
    209.                 set {infinity} to 1
    210.                 set {arrow} to 1
    211.  
    212.  
    213.     #    Gear Piece
    214.             loop 4 times:
    215.                 if loop-number is 1:
    216.                     set {piece} to "%{gearQuality}% helmet" parsed as item
    217.                 else if loop-number is 2:
    218.                     set {piece} to "%{gearQuality}% chestplate" parsed as item
    219.                 else if loop-number is 3:
    220.                     set {piece} to "%{gearQuality}% leggings" parsed as item
    221.                 else if loop-number is 4:
    222.                     set {piece} to "%{gearQuality}% boots" parsed as item
    223.                 if player is not wearing {piece}:
    224.                     if {protection} is 0:
    225.                         equip player with {piece} named "%{kit}%"
    226.                     else:
    227.                         equip player with {piece} of protection {protection} named "%{kit}%"
    228.                 else:
    229.                     if {protection} is 0:
    230.                         give {piece} named "%{kit}%" to the player
    231.                     else:
    232.                         give {piece} of protection {protection} named "%{kit}%" to the player
    233.  
    234.     #    Sword / Bow
    235.             if {sharpness} is 0:
    236.                 give {swordQuality} sword named "%{kit}%" to the player
    237.             else:
    238.                 give {swordQuality} sword of sharpness {sharpness} named "%{kit}%" to the player
    239.             if {bow} is 1:
    240.                 if {power} is 0:
    241.                     give bow named "%{kit}%" to the player
    242.                 else:
    243.                     if {infinity} is 1:
    244.                         give bow of infinity and power  named "%{kit}%" to the player
    245.                     else if {infinity} is 0:
    246.                         give bow of power {power} named "%{kit}%" to the player
    247.                
    248.     #    Extras
    249.             give {gapple} golden apple to the player
    250.             give {arrow} arrow to the player
    251.  
    252.  
    253. #    Kit Copy Paste
    254. #                    set {kit} to "%{kit}%"
    255. #                    set {gearQuality} to ""
    256. #                    set {swordQuality} to ""
    257. #                    set {protection} to
    258. #                    set {sharpness} to
    259. #                    set {gapple} to
    260. #                    set {bow} to
    261. #                    set {power} to
    262. #                    set {infinity} to
    263. #                    set {arrow} to
     
  4. Abdera7mane

    Abdera7mane Active Member

    Joined:
    Aug 18, 2019
    Messages:
    56
    Likes Received:
    7
    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 (Text):
    1.  
    2. set {kits::example} to "example kit"
    3. set {kits::example::items::*}  to wooden sword, wooden axe, wooden shovel and 5 of apples
    4. set {kits::example::equipments::*} to iron halmet
    5.  
    • Giving a kit to the player

    Code (Text):
    1.  
    2. # first argument represent the kit name
    3. command kit <string>:
    4.     trigger:
    5.         # you need to check if the player have inventory space to hold and equip the kit
    6.         If {kits::%arg%} exists:
    7.             give player {kits::%arg%::items::*}
    8.             equip player {kits::%arg%::equipments::*}
    9.         else:
    10.             send "this kit doesn't exist"
    11.  
    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.
     
    #4 Abdera7mane, Aug 31, 2020
    Last edited: Aug 31, 2020
Thread Status:
Not open for further replies.

Share This Page

Loading...