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.

Is that right?

Discussion in 'Skript' started by effiraid, Jul 26, 2017.

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

    effiraid Member

    Joined:
    Jul 16, 2017
    Messages:
    24
    Likes Received:
    0
    Aloha, guys i want to excute player command "/abc" if player have 'diamond hoe' item named "aaaaa" in inventory(also remove this item)

    So i coded. Please check below my practice code.

    Code (Skript):
    1. On command "/abc":
    2.   Loop 1 times:
    3.     Loop all items in player's inventory:
    4.       If player has 1 diamond hoe named "aaaaa"
    5.         Remove 1 diamond hoe named "aaaaa"
    6.         Make player excute command "/abc"
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Okay, I'm going to break this down line by line.

    Code (Skript):
    1. On command "/abc"
    The on command event is pretty useful for listening when a player runs an existing command, but if this is a custom command, it would make more sense to use command definition:

    Code (Skript):
    1. command /abc:
    2.     trigger:

    Code (Skript):
    1. Loop 1 times:
    When a event is triggered, such as an on command event or command definition, the code in its trigger is ran once. The loop expression loops code within its trigger n amount of times. Looping code once, while it's already going to be ran once, is redundant; we'll get the same effect if we remove the loop expression from this example.

    Code (Skript):
    1.  
    2. Loop all items in player's inventory:
    3.     If player has 1 diamond hoe named "aaaaa"
    4.  
    The way you use the loop expression here makes me think you're trying to use the loop all items as a way to reference all items in the player's inventory at once in its trigger, which is an understandable mistake.

    Similar to how we described before with looping n (number) amount of times, the loop all items expression will loop i (items) amount of times. What's the difference? In the previous loop, we can use the expression loop-number, as it refers to the amount of numbers being looped, and will output what number it is currently looping. Similarly, in this loop, we can use the expression loop-item, to reference the current item being looped.

    However, using loop all items is redundant, as the very next condition if player has already references the player's entire inventory for us!

    Code (Skript):
    1. Remove 1 diamond hoe named "aaaaa"
    This statement is probably correct, but I always suffix it with "from player".

    Code (Skript):
    1. Remove 1 diamond hoe named "aaaaa" from player

    Code (Skript):
    1. Make player excute command "/abc"
    Okay, so it looks like you're trying to make your statement recursive, meaning, it calls itself until a condition stops it (if the player no longer has a diamond hoe named "aaaaa"). I can jump into a whole lesson about recursive statements, but that would take a while, and this mini-tutorial is already pretty long ;P (but I totally can if you want)

    If you're trying to remove all the diamond hoes named "aaaaa" from a player's inventory, it may be better to use what we talked about before with looping items!

    Code (Skript):
    1.  
    2. Loop all items in player's inventory:
    3.     loop-item is diamond hoe named "aaaaa"
    4.     remove loop-item from player
    5.  

    In the end, if you want to remove a single diamond hoe from the player's inventory, you could do this:
    Code (Skript):
    1.  
    2. command /abc:
    3.     trigger:
    4.         If player has 1 diamond hoe named "aaaaa":
    5.             Remove 1 diamond hoe named "aaaaa" from player
    6.  
    Or, if you want to remove all diamond hoes from the player:
    Code (Skript):
    1.  
    2. command /abc:
    3.     trigger:
    4.         Loop all items in player's inventory:
    5.             loop-item is diamond hoe named "aaaaa"
    6.             remove loop-item from player
    7.  

    Unfortunately I'm unable to test any code I provided, so I can't say 100% that the examples I provided will compile!
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Really Really nice answer...Thanks for the information!
    --- Double Post Merged, Jul 26, 2017, Original Post Date: Jul 26, 2017 ---
    Are you there? I had a problem!
    Code (Skript):
    1. on command "/skill Blink":
    2.     if player has not 1 diamond hoe named "&7aaaaa":
    3.         cancel event
    4.     If player has 1 diamond hoe named "&7aaaaa":
    5.         Remove 1 diamond hoe named "&7aaaaa" from player
    6.         Make player excute command "/skill Blink"
    It doesn't work from "if player has not 1 doamond hoe named ~~~~"
    How can i instead this?
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Skript syntax can be odd to get to know from scratch; here's the correct syntax.

    Code (Skript):
    1. on command "/skill Blink":
    2.     if player does not have 1 diamond hoe named "&7aaaaa":
    3.         cancel event
    4.     If player has 1 diamond hoe named "&7aaaaa":
    5.         Remove 1 diamond hoe named "&7aaaaa" from player
    6.         Make player excute command "/skill Blink"
    It should also be noted that (if your provided code is the entire command, and there's nothing after the "if player has" condition) you could also not include that statement entirely for the same effect:

    Code (Skript):
    1. on command "/skill Blink":
    2.     If player has 1 diamond hoe named "&7aaaaa":
    3.         Remove 1 diamond hoe named "&7aaaaa" from player
    4.         Make player excute command "/skill Blink"
    Or, if you plan to expand your code, you can also use an if else statement:

    Code (Skript):
    1. on command "/skill Blink":
    2.     If player has 1 diamond hoe named "&7aaaaa":
    3.         Remove 1 diamond hoe named "&7aaaaa" from player
    4.         Make player excute command "/skill Blink"
    5.     else:
    6.         cancel event
    7.  
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Thanks! It works well but I think maybe skript can't read diamond hoe name...
    This is my final code
    Code (Skript):
    1. on command "/skill Blink":
    2.     If player has 1 diamond hoe named "&7마력의 돌":
    3.         Remove 1 diamond hoe named "&7마력의 돌" from player
    4.         Make player execute command "skill Blink"
    5.     else:
    6.         set name of player's tool to "&7마력의 돌"
    7.         send "X" to player
    8.         cancel event
    And chat only shows me "X" when i have "&7마력의 돌" item.
    http://imgur.com/a/2otbd
    --- Double Post Merged, Jul 26, 2017, Original Post Date: Jul 26, 2017 ---
    I created this item from Newitems plugin. This is probably related to item damage.
     
    #5 ShaneBee, Jul 26, 2017
    Last edited by a moderator: Jul 26, 2017
Thread Status:
Not open for further replies.

Share This Page

Loading...