Item Owner

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

Quentin_GHG

Member
Mar 15, 2024
10
0
1
23
Hello Lately i have tried adding a custom sword to my server, wich uses a custom enchanting system, I just wanted to give the first Diamond axe (its different swords with Custom Model Data) a Tag or variable so only the original player can use it, the whole reason behind this is so that players cant copy their old sword enchantments on new sword. Ive tried this with nbt tags and normal Variables this didnt seem to work for me, but i probably just dont understand really how its supposed to work, anyway if you have any questions just ask me in this thread thanks in advance for this amazing community and all of your help
Code:
on right click:
    if player's held item is diamond axe:
        if {itemweapontemporary%event-item%} is not set:
            set {itemweapontemporary%event-item%} to player
        if {itemweapontemporary%event-item%} != "%player%":
            if {itemweapontemporary%event-item%} has permission "weapon.bypass": #for admins to still open the enchant menu
                enchanting(player) #just opens the enchant menu
 
If you would like to have an owner or multiple owners of the actual item itself, if that's what you mean, you can try this code right here.

Code:
on right click:
    if player is holding diamond axe:
        set {var::%player%} to player
        if {var::%player%} is "username" or "username": #input the usernames of the owner(s) here
            #input the enchant menu code here

(This code is untested. Please reply if you have any errors.)
 
Hello I think I did not really explain it well enough, sorry. I meant that the first person who uses the enchant interface on the axe gets the „Owner“ of the item, so that if the owner drops this weapon to an other player the player cant access the weapon, so that linger playing players cant boost new players with their enchants, sorry if I explained it weong, basically just an automatic irem owner skript
 
Okay I will try to explain it again: on join of my server, players get an axe, on first Right click they are supposed to be binded to axe automatically, so that no other person can enchant their item in a GUI, so that old players cant boost new Players, If I understood correctly your skript is supposed to do it manually, so I enter the usernames in front and yeah it checks it, I tried multiple ways and whatever, this is my latest try of trying to get it to work, perhaps you understand what I am trying to do. this skript doesnt work because the phrase: if player's tool does not have nbt tag "Owner": doesnt exist, so I dont really know hot to get it to work.
Code:
on right click with diamond axe:
    if player's tool doesn't have nbt tag "Owner":
        add nbt tag "Owner" with value "%uuid of player%" to player's tool
        send "&aThis axe is now bound to you." to player
    else:
        if nbt tag "Owner" of player's tool is not "%uuid of player%":
            cancel event
            send "&cYou are not the owner of this axe." to player
 
Hello Lately i have tried adding a custom sword to my server, wich uses a custom enchanting system, I just wanted to give the first Diamond axe (its different swords with Custom Model Data) a Tag or variable so only the original player can use it, the whole reason behind this is so that players cant copy their old sword enchantments on new sword. Ive tried this with nbt tags and normal Variables this didnt seem to work for me, but i probably just dont understand really how its supposed to work, anyway if you have any questions just ask me in this thread thanks in advance for this amazing community and all of your help
Code:
on right click:
    if player's held item is diamond axe:
        if {itemweapontemporary%event-item%} is not set:
            set {itemweapontemporary%event-item%} to player
        if {itemweapontemporary%event-item%} != "%player%":
            if {itemweapontemporary%event-item%} has permission "weapon.bypass": #for admins to still open the enchant menu
                enchanting(player) #just opens the enchant menu
You could just have it set the lore and use that to check what player owns which axe.
 
Thankyou so much, it probably is a temporary solution for me for now, I dont really want the lore to be on the item but for now its fine :emoji_grinning:, this is what worked for me for anyone reading this.
Code:
on right click with diamond axe:
    if lore of event-item does not contain "&a%player%'s &fWeapon!":
        set {itemweapontemporary%event-item%} to player
        set 9nd line of lore of player's tool to "&a%{itemweapontemporary%event-item%}%'s &fWeapon!"
        send message "&fBinded %event-item% to %player%!"
    if lore of event-item contains "&a%player%'s &fWeapon!":
        enchanting(player)
 
Hello, okay im back haha, It worked out for a while, untill I noticed today I use shopkeepers, and the lore of the player doesnt work in the trade menu because of that, so im thinking of a new solution, I found some interesting stuff tried it out, didnt get it to work sadly, uhm so yeah, I think It is possible to add a minecraft Tag to the item in form of text so "%player%" should work, but I did not get it to work, so if anybody has an Idea on how to add the Owner, and check for the owner, I would much appreciate it, It doesnt have to be a finished code, just a possible way of doing it, thanks!
 
Hello Lately i have tried adding a custom sword to my server, wich uses a custom enchanting system, I just wanted to give the first Diamond axe (its different swords with Custom Model Data) a Tag or variable so only the original player can use it, the whole reason behind this is so that players cant copy their old sword enchantments on new sword. Ive tried this with nbt tags and normal Variables this didnt seem to work for me, but i probably just dont understand really how its supposed to work, anyway if you have any questions just ask me in this thread thanks in advance for this amazing community and all of your help
Code:
on right click:
    if player's held item is diamond axe:
        if {itemweapontemporary%event-item%} is not set:
            set {itemweapontemporary%event-item%} to player
        if {itemweapontemporary%event-item%} != "%player%":
            if {itemweapontemporary%event-item%} has permission "weapon.bypass": #for admins to still open the enchant menu
                enchanting(player) #just opens the enchant menu

This can be achieved using nbt, specifically uuid tags:

code_language.skript:
function setOwner(item:item,player:offlineplayer) :: item:
  set uuid tag "owner" of nbt of {_item} to {_player}
  return {_item}

function deleteOwner(item:item) :: item:
  delete uuid tag "owner" of nbt of {_item}
  return {_item}

function getOwner(item:item) :: offlineplayer:
  return (uuid tag "owner" of nbt of {_item}) parsed as offlineplayer

function hasOwner(item:item) :: boolean:
  return true if nbt of {_item} has tag "owner", else false



Example:

code_language.skript:
if tool is air:
  set tool to setOwner(iron sword,player)
set {_owner} to getOwner(tool)
if {_owner} is set:
  broadcast "%player% is holding %tool% which is owned by %{_owner}%!"
else:
  broadcast "%player% is holding %tool% which is not owned by anybody!"