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.

Solved Animal ownership script

Discussion in 'Skript' started by grindser, Sep 15, 2021 at 7:17 PM.

  1. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    I'd like to make a script to allow players to own animals, and sell or transfer them. (e.g allowing a player to own 20 sheep to have on their farm)
    What would be the best way to do this?
     
  2. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    You could use NBT, add custom nbt like {Owner:%player%} to the mob
     
  3. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    I can't quite get the NBT to work, no errors but doesn't seem like the NBT tag is being added, see any issues?

    Code (Text):
    1. on damage of an animal:
    2.     if attacker's tool is lead:
    3.         cancel event
    4.         if {animals::%attacker%::listen} is true:
    5.             send "Confirmed, you now own this %victim%." to attacker
    6.             set {animals::%attacker%::listen} to false
    7.             add "{Owner:%attacker%}" to nbt of victim
    8.            
    9.         else:
    10.             if nbt of victim does not contain "{Owner:}":
    11.                 send "Punch the %victim% again to confirm ownership" to attacker
    12.                 set {animals::%attacker%::listen} to true
    13.  
    14. on damage of an animal:
    15.     if attacker's tool is lead:
    16.         cancel event
    17.         wait 5 seconds
    18.         set {animals::%attacker%::listen} to false
     
  4. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    To check the tag, use `if tag "Owner" of nbt of victim is "%attacker%"`
     
  5. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    That if statements seems to be always outputting false, would you mind testing the script for yourself? I'm truly lost, been working on this for 5 hours :emoji_slight_smile:
     
  6. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    what do you get if you broadcast the tag?
     
  7. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Code (Text):
    1. send tag "Owner" of nbt of victim to attacker
    Doesn't do anything.
     
  8. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    How do you use code blocks here?
     
  9. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Accidenally deleted my reply, in case you didn't catch it;
    Hit the plus button on the formatting bar
     
  10. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    Code (Text):
    1. on damage of an animal:
    2.     if attacker's tool is lead:
    3.         cancel event
    4.         if {animals::%attacker's uuid%::listen} is not set:
    5.             set {animals::%attacker's uuid%::listen} to true
    6.             send "Punch the %victim% again to confirm ownership" to attacker
    7.             wait 5 seconds
    8.             delete {animals::%attacker's uuid%::listen}
    9.         else:
    10.             add "{Owner:%attacker%}" to nbt of victim
    11.             send "Confirmed, you now own this %victim%." to attacker
     
  11. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Oh my god, you did it, thanks!
    --- Double Post Merged, Sep 16, 2021 at 9:18 PM, Original Post Date: Sep 16, 2021 at 9:14 PM ---
    Actually, how would I check if the animal is already owned by someone?
     
  12. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    check the tag, as I showed before (if tag "Owner" of nbt of victim is set)
     
  13. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Code (Text):
    1. if tag "Owner" of nbt of victim is not set:
    2.             if {animals::%attacker's uuid%::listen} is not set:
    3.                 set {animals::%attacker's uuid%::listen} to true
    4.                 send "Punch the %victim% again to confirm ownership" to attacker
    5.                 wait 5 seconds
    6.                 delete {animals::%attacker's uuid%::listen}
    7.             else:
    8.                 add "{Owner:%attacker%}" to nbt of victim
    9.                 send "Confirmed, you now own this %victim%." to attacker
    This seems to always be true
     
  14. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    Does the NBT not get set? Broadcast the nbt after it's supposed to get set
     
  15. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Just did that, doesn't seem like it. I might try SkStuff for NBTs instead.
     
  16. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    what? no, never. the addon is not the issue, skstuff hasn't been updated in 5 years, skbee is up to date and one of the best addons, you just don't give enough context for me to understand what you actually try and what doesn't work
     
  17. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    Right, okay. The issue is that the NBT tag never gets added to the entity.
     
  18. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    does the message get sent to you?
     
  19. grindser

    grindser Member

    Joined:
    Tuesday
    Messages:
    14
    Likes Received:
    0
    This is the current script.

    Code (Text):
    1. on damage of an animal:
    2.     if attacker's tool is lead:
    3.         cancel event
    4.         send nbt of victim to console
    5.         if tag "Owner" of nbt of victim is not set:
    6.             if {animals::%attacker's uuid%::listen} is not set:
    7.                 set {animals::%attacker's uuid%::listen} to true
    8.                 send "Punch the %victim% again to confirm ownership" to attacker
    9.                 wait 5 seconds
    10.                 delete {animals::%attacker's uuid%::listen}
    11.             else:
    12.                 add "{Owner:%attacker%}" to nbt of victim
    13.                 send "Confirmed, you now own this %victim%." to attacker
    I get the "Punch to confirm" and "You now own", however if I keep punching I get the same thing. This is what it prints to console;
    Code (Text):
    1. {AbsorptionAmount:0.0f,Age:0,AgeLocked:0b,Air:300s,ArmorDropChances:[0.085f,0.085f,0.0f,0.085f],ArmorItems:[{},{},{},{}],Attributes:[{Base:0.21916751001978602d,Name:"minecraft:generic.movement_speed"},{Base:21.0d,Name:"minecraft:generic.max_health"},{Base:0.0d,Name:"minecraft:generic.armor"},{Base:16.0d,Modifiers:[{Amount:0.0031947673230036293d,Name:"Random spawn bonus",Operation:1,UUID:[I;1978012985,833571285,-1771715006,378728803]}],Name:"minecraft:generic.follow_range"},{Base:0.5593834170847802d,Name:"minecraft:horse.jump_strength"}],Brain:{memories:{}},Bred:0b,Bukkit.Aware:1b,Bukkit.MaxDomestication:100,Bukkit.updateLevel:2,CanPickUpLoot:0b,DeathTime:0s,EatingHaystack:1b,FallDistance:0.0f,FallFlying:0b,Fire:-1s,ForcedAge:0,HandDropChances:[0.085f,0.085f],HandItems:[{},{}],Health:21.0f,HurtByTimestamp:0,HurtTime:0s,InLove:0,Invulnerable:0b,LeftHanded:0b,Motion:[0.0d,-0.0784000015258789d,0.0d],OnGround:1b,Paper.Origin:[-287.5d,4.0d,54.5d],Paper.OriginWorld:[I;1733674433,134760230,-1952856429,1826994894],Paper.SpawnReason:"NATURAL",PersistenceRequired:1b,PortalCooldown:0,Pos:[-287.1304967023017d,4.0d,74.8592314286132d],Rotation:[315.25912f,0.0f],Spigot.ticksLived:15143,Tame:0b,Temper:0,UUID:[I;322025419,-760984888,-1241188896,-1346078824],Variant:1030,WorldUUIDLeast:-8387454494511351090L,WorldUUIDMost:7446074991781103398L}
     
  20. oToghty

    VIP Supporter +

    Joined:
    Sep 1, 2020
    Messages:
    39
    Likes Received:
    1
    that's just perfect, exactly how it should work, just add an else for the 2nd condition
     

Share This Page

Loading...