Steal a item

  • 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 community!

    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.

SoMuchWessel

Active Member
Apr 3, 2017
147
3
18
Hey guys, i got this piece of code working:

code_language.skript:
on right-click on player:
    if player is holding a enchanted book named "&8Steal-Book" with lore "&7Right-click a player to steal something from him.":
        delete {steal::*}
        wait a tick
        loop all items in clicked player's inventory:
            if loop-item is not enchanted with curse of vanishing 1:
                add loop-item to {steal::*}
        set {stealed} to random element out of {steal::*}
        add {stealed} to player's inventory
        remove {stealed} from clicked player's inventory
        send "&8You stole %{stealed}% from %clicked player%!" to player
        send "&8%{stealed}% has been stolen from you!" to clicked player
        remove a enchanted book named "&8Steal-Book" with lore "&7Right-click a player to steal something from him." from the player
        delete {steal::*}
        delete {stealed}

But the problem here is, if it steals a piece of armor that is equiped, the armor will duplicate. Both players will now have the armor.

Is there a way to fix this? That the player that is stealed from, will unequip and lose his armor?
 
youll have to check each armor piece individually. also you can make this better by using local variables
code_language.skript:
on right-click on player:
    if player is holding a enchanted book named "&8Steal-Book" with lore "&7Right-click a player to steal something from him.":
        set {_item} to random element out of items in clicked player's inventory where [input is not enchanted with curse of vanishing 1]
        add {_item} to player's inventory
        if clicked player's helmet is {_item}:
            set clicked player's helmet to air
        else if clicked player's chestplate is {_item}:
            set clicked player's chestplate to air
        else if clicked player's leggings is {_item}:
            set clicked player's leggings to air
        else if clicked player's boots is {_item}:
            set clicked player's boots to air
        else:
            remove {_item} from clicked player's inventory      
        send "&8You stole %{_item}% from %clicked player%!" to player
        send "&8%{_item}% has been stolen from you!" to clicked player
        remove 1 of player's tool from player's tool
 
youll have to check each armor piece individually. also you can make this better by using local variables
code_language.skript:
on right-click on player:
    if player is holding a enchanted book named "&8Steal-Book" with lore "&7Right-click a player to steal something from him.":
        set {_item} to random element out of items in clicked player's inventory where [input is not enchanted with curse of vanishing 1]
        add {_item} to player's inventory
        if clicked player's helmet is {_item}:
            set clicked player's helmet to air
        else if clicked player's chestplate is {_item}:
            set clicked player's chestplate to air
        else if clicked player's leggings is {_item}:
            set clicked player's leggings to air
        else if clicked player's boots is {_item}:
            set clicked player's boots to air
        else:
            remove {_item} from clicked player's inventory     
        send "&8You stole %{_item}% from %clicked player%!" to player
        send "&8%{_item}% has been stolen from you!" to clicked player
        remove 1 of player's tool from player's tool

I tried the code, but nothing happens when i click on a player
 
Status
Not open for further replies.