Is that right?

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

effiraid

Member
Jul 16, 2017
24
0
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_language.skript:
On command "/abc":
  Loop 1 times:
    Loop all items in player's inventory:
      If player has 1 diamond hoe named "aaaaa"
        Remove 1 diamond hoe named "aaaaa"
        Make player excute command "/abc"
 
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_language.skript:
On command "/abc":
  Loop 1 times:
    Loop all items in player's inventory:
      If player has 1 diamond hoe named "aaaaa"
        Remove 1 diamond hoe named "aaaaa"
        Make player excute command "/abc"

Okay, I'm going to break this down line by line.

code_language.skript:
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_language.skript:
command /abc:
    trigger:

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    If player has 1 diamond hoe named "aaaaa"

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_language.skript:
Remove 1 diamond hoe named "aaaaa"

This statement is probably correct, but I always suffix it with "from player".

code_language.skript:
Remove 1 diamond hoe named "aaaaa" from player

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    loop-item is diamond hoe named "aaaaa"
    remove loop-item from player

In the end, if you want to remove a single diamond hoe from the player's inventory, you could do this:
code_language.skript:
command /abc:
    trigger:
        If player has 1 diamond hoe named "aaaaa":
            Remove 1 diamond hoe named "aaaaa" from player

Or, if you want to remove all diamond hoes from the player:
code_language.skript:
command /abc:
    trigger:
        Loop all items in player's inventory:
            loop-item is diamond hoe named "aaaaa"
            remove loop-item from player

Unfortunately I'm unable to test any code I provided, so I can't say 100% that the examples I provided will compile!
 
Okay, I'm going to break this down line by line.

code_language.skript:
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_language.skript:
command /abc:
    trigger:

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    If player has 1 diamond hoe named "aaaaa"

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_language.skript:
Remove 1 diamond hoe named "aaaaa"

This statement is probably correct, but I always suffix it with "from player".

code_language.skript:
Remove 1 diamond hoe named "aaaaa" from player

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    loop-item is diamond hoe named "aaaaa"
    remove loop-item from player

In the end, if you want to remove a single diamond hoe from the player's inventory, you could do this:
code_language.skript:
command /abc:
    trigger:
        If player has 1 diamond hoe named "aaaaa":
            Remove 1 diamond hoe named "aaaaa" from player

Or, if you want to remove all diamond hoes from the player:
code_language.skript:
command /abc:
    trigger:
        Loop all items in player's inventory:
            loop-item is diamond hoe named "aaaaa"
            remove loop-item from player

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

Really Really nice answer...Thanks for the information!
[doublepost=1501082991,1501081398][/doublepost]
Okay, I'm going to break this down line by line.

code_language.skript:
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_language.skript:
command /abc:
    trigger:

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    If player has 1 diamond hoe named "aaaaa"

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_language.skript:
Remove 1 diamond hoe named "aaaaa"

This statement is probably correct, but I always suffix it with "from player".

code_language.skript:
Remove 1 diamond hoe named "aaaaa" from player

code_language.skript:
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_language.skript:
Loop all items in player's inventory:
    loop-item is diamond hoe named "aaaaa"
    remove loop-item from player

In the end, if you want to remove a single diamond hoe from the player's inventory, you could do this:
code_language.skript:
command /abc:
    trigger:
        If player has 1 diamond hoe named "aaaaa":
            Remove 1 diamond hoe named "aaaaa" from player

Or, if you want to remove all diamond hoes from the player:
code_language.skript:
command /abc:
    trigger:
        Loop all items in player's inventory:
            loop-item is diamond hoe named "aaaaa"
            remove loop-item from player

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

Are you there? I had a problem!
code_language.skript:
on command "/skill Blink":
    if player has not 1 diamond hoe named "&7aaaaa":
        cancel event
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"

It doesn't work from "if player has not 1 doamond hoe named ~~~~"
How can i instead this?
 
Really Really nice answer...Thanks for the information!
[doublepost=1501082991,1501081398][/doublepost]

Are you there? I had a problem!
code_language.skript:
on command "/skill Blink":
    if player has not 1 diamond hoe named "&7aaaaa":
        cancel event
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"

It doesn't work from "if player has not 1 doamond hoe named ~~~~"
How can i instead this?

Skript syntax can be odd to get to know from scratch; here's the correct syntax.

code_language.skript:
on command "/skill Blink":
    if player does not have 1 diamond hoe named "&7aaaaa":
        cancel event
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        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_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"

Or, if you plan to expand your code, you can also use an if else statement:

code_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"
    else:
        cancel event
 
Skript syntax can be odd to get to know from scratch; here's the correct syntax.

code_language.skript:
on command "/skill Blink":
    if player does not have 1 diamond hoe named "&7aaaaa":
        cancel event
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        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_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"

Or, if you plan to expand your code, you can also use an if else statement:

code_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7aaaaa":
        Remove 1 diamond hoe named "&7aaaaa" from player
        Make player excute command "/skill Blink"
    else:
        cancel event

Thanks! It works well but I think maybe skript can't read diamond hoe name...
This is my final code
code_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7마력의 돌":
        Remove 1 diamond hoe named "&7마력의 돌" from player
        Make player execute command "skill Blink"
    else:
        set name of player's tool to "&7마력의 돌"
        send "X" to player
        cancel event

And chat only shows me "X" when i have "&7마력의 돌" item.
http://imgur.com/a/2otbd
[doublepost=1501084391,1501084050][/doublepost]
Thanks! It works well but I think maybe skript can't read diamond hoe name...
This is my final code
code_language.skript:
on command "/skill Blink":
    If player has 1 diamond hoe named "&7마력의 돌":
        Remove 1 diamond hoe named "&7마력의 돌" from player
        Make player execute command "skill Blink"
    else:
        set name of player's tool to "&7마력의 돌"
        send "X" to player
        cancel event

And chat only shows me "X" when i have "&7마력의 돌" item.
http://imgur.com/a/2otbd

I created this item from Newitems plugin. This is probably related to item damage.
 
Last edited by a moderator:
Status
Not open for further replies.