Solved A way to save horse stats?

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

Wardle

Member
May 15, 2017
20
2
0
I'm looking for a way to save horse stats so that a player can run a command to make their horse disappear and when they run a command again, they get the exact same horse back. Is this even possible?

I have no current code but I can provide an example of what I want to happen. (Example is bare bones due to not knowing where to start :emoji_frowning:)

code_language.skript:
command /horse [<text>]:
    trigger:
        if arg-1 is set:
            if arg-1 is "store":
#                Save horse stats and make the horse vanish
                send "&aSuccessfully stored horse."
            if arg-1 is "summon":
#                Retrieve horse stats and make the horse appear
                send "&aSuccessfully summoned horse."
 
The easiest way to do this is just storing it's nbt data, but that isn't the most reliable way to do it. Another way to accomplish it would be serializing all the important data and setting it on a new horse.
 
The easiest way to do this is just storing it's nbt data, but that isn't the most reliable way to do it. Another way to accomplish it would be serializing all the important data and setting it on a new horse.
Could you give me a code example on how I could achieve this? I have zero clue on what I'm doing when it comes to saving data and restoring it, thanks for the help :emoji_slight_smile:
 
Could you give me a code example on how I could achieve this? I have zero clue on what I'm doing when it comes to saving data and restoring it, thanks for the help :emoji_slight_smile:
There is skstuff for nbt, but like I said NBT is best avoided because since spigot has no proper api for it, it has to be done through something called NMS which has a pretty big chance of breaking between versions. If you are the kind of person who forever stays on 1.8 or 1.7, this isn't a big deal so nbt would be the easiest way to do it on those versions. For other versions, what kind of data do you want to save? E.g. jump height, color
 
There is skstuff for nbt, but like I said NBT is best avoided because since spigot has no proper api for it, it has to be done through something called NMS which has a pretty big chance of breaking between versions. If you are the kind of person who forever stays on 1.8 or 1.7, this isn't a big deal so nbt would be the easiest way to do it on those versions. For other versions, what kind of data do you want to save? E.g. jump height, color
Preferably, I'd like to save everything. Name of the horse, color, speed and jump height would be the main ones.
 
I update on every spigot release, currently on 1.12.2.
It's considerably more complex then. Here's a start for you with skript-mirror:
code_language.skript:
on script load:
  import "org.bukkit.attribute.Attribute"
  import "org.bukkit.entity.Horse$Color" as {HorseColor}
  import "org.bukkit.entity.Horse$Style" as {HorseStyle}
  import "java.util.Locale"

function horseSpeed(horse: entity, speed: number = -999) :: number:
  set {_attribute} to {_horse}.getAttribute({Attribute}.GENERIC_MOVEMENT_SPEED!)
  if {_speed} is not -999:
    {_attribute}.setBaseValue({_speed});
  return {_attribute}.getBaseValue()

function horseJump(horse: entity, height: number = -999) :: number:
  set {_attribute} to {_horse}.getAttribute({Attribute}.HORSE_JUMP_STRENGTH!)
  if {_height} is not -999:
    {_attribute}.setBaseValue({_height});
  return {_attribute}.getBaseValue()

function horseColor(horse: entity, color: string = "unchanged") :: string:
  if {_color} is not "unchanged":
    {_horse}.setColor({HorseColor}..{_color}.toUpperCase({Locale}.ENGLISH!)!);
  return {_horse}.getColor().name()

function horseStyle(horse: entity, style: string = "unchanged") :: string:
  if {_style} is not "unchanged":
    {_horse}.setStyle({HorseStyle}..{_style}.toUpperCase({Locale}.ENGLISH!)!);
  return {_horse}.getStyle().name()
 
Status
Not open for further replies.