Solved Animal ownership script

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

grindser

Member
Sep 14, 2021
14
0
1
23
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?
 
You could use NBT, add custom nbt like {Owner:%player%} to the mob
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:
on damage of an animal:
    if attacker's tool is lead:
        cancel event
        if {animals::%attacker%::listen} is true:
            send "Confirmed, you now own this %victim%." to attacker
            set {animals::%attacker%::listen} to false
            add "{Owner:%attacker%}" to nbt of victim
            
        else:
            if nbt of victim does not contain "{Owner:}":
                send "Punch the %victim% again to confirm ownership" to attacker
                set {animals::%attacker%::listen} to true

on damage of an animal:
    if attacker's tool is lead:
        cancel event
        wait 5 seconds
        set {animals::%attacker%::listen} to false
 
To check the tag, use `if tag "Owner" of nbt of victim is "%attacker%"`
 
To check the tag, use `if tag "Owner" of nbt of victim is "%attacker%"`
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:
 
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:

what do you get if you broadcast the tag?
 
Code:
on damage of an animal:
    if attacker's tool is lead:
        cancel event
        if {animals::%attacker's uuid%::listen} is not set:
            set {animals::%attacker's uuid%::listen} to true
            send "Punch the %victim% again to confirm ownership" to attacker
            wait 5 seconds
            delete {animals::%attacker's uuid%::listen}
        else:
            add "{Owner:%attacker%}" to nbt of victim
            send "Confirmed, you now own this %victim%." to attacker
 
Code:
on damage of an animal:
    if attacker's tool is lead:
        cancel event
        if {animals::%attacker's uuid%::listen} is not set:
            set {animals::%attacker's uuid%::listen} to true
            send "Punch the %victim% again to confirm ownership" to attacker
            wait 5 seconds
            delete {animals::%attacker's uuid%::listen}
        else:
            add "{Owner:%attacker%}" to nbt of victim
            send "Confirmed, you now own this %victim%." to attacker
Oh my god, you did it, thanks!
[doublepost=1631823504,1631823263][/doublepost]
Code:
on damage of an animal:
    if attacker's tool is lead:
        cancel event
        if {animals::%attacker's uuid%::listen} is not set:
            set {animals::%attacker's uuid%::listen} to true
            send "Punch the %victim% again to confirm ownership" to attacker
            wait 5 seconds
            delete {animals::%attacker's uuid%::listen}
        else:
            add "{Owner:%attacker%}" to nbt of victim
            send "Confirmed, you now own this %victim%." to attacker
Actually, how would I check if the animal is already owned by someone?
 
Oh my god, you did it, thanks!
[doublepost=1631823504,1631823263][/doublepost]
Actually, how would I check if the animal is already owned by someone?
check the tag, as I showed before (if tag "Owner" of nbt of victim is set)
 
check the tag, as I showed before (if tag "Owner" of nbt of victim is set)
Code:
if tag "Owner" of nbt of victim is not set:
            if {animals::%attacker's uuid%::listen} is not set:
                set {animals::%attacker's uuid%::listen} to true
                send "Punch the %victim% again to confirm ownership" to attacker
                wait 5 seconds
                delete {animals::%attacker's uuid%::listen}
            else:
                add "{Owner:%attacker%}" to nbt of victim
                send "Confirmed, you now own this %victim%." to attacker
This seems to always be true
 
Code:
if tag "Owner" of nbt of victim is not set:
            if {animals::%attacker's uuid%::listen} is not set:
                set {animals::%attacker's uuid%::listen} to true
                send "Punch the %victim% again to confirm ownership" to attacker
                wait 5 seconds
                delete {animals::%attacker's uuid%::listen}
            else:
                add "{Owner:%attacker%}" to nbt of victim
                send "Confirmed, you now own this %victim%." to attacker
This seems to always be true
Does the NBT not get set? Broadcast the nbt after it's supposed to get set
 
Just did that, doesn't seem like it. I might try SkStuff for NBTs instead.
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
 
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
Right, okay. The issue is that the NBT tag never gets added to the entity.
 
does the message get sent to you?
This is the current script.

Code:
on damage of an animal:
    if attacker's tool is lead:
        cancel event
        send nbt of victim to console
        if tag "Owner" of nbt of victim is not set:
            if {animals::%attacker's uuid%::listen} is not set:
                set {animals::%attacker's uuid%::listen} to true
                send "Punch the %victim% again to confirm ownership" to attacker
                wait 5 seconds
                delete {animals::%attacker's uuid%::listen}
            else:
                add "{Owner:%attacker%}" to nbt of victim
                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:
{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}
 
that's just perfect, exactly how it should work, just add an else for the 2nd condition
 
Status
Not open for further replies.