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.

How to save player's balance in a YAML file.

Discussion in 'Skript' started by KroterPvP, May 21, 2017.

Thread Status:
Not open for further replies.
  1. KroterPvP

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    Hello, I need help. I have created a new skript (https://forums.skunity.com/resources/✎-supereconomy-✐-trying-to-be-the-perfect-economy.230/) which has it's own economy. I need to save the player balance into a file.
    Do I need to save all the server balance into a file or create a single file with the name of the player and his balance inside of it?
    Do I need to use UUID's or player name?
    Which is the best addon which does this? SkUtilities?

    I don't know how can I do this, who can help me with a little part of code?
     
    #1 KroterPvP, May 21, 2017
    Last edited: May 21, 2017
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    You could save the value using this:
    Code (Skript):
    1. set yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml" to ...
    and read the value like this:
    Code (Skript):
    1. set {...} to yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml"


    or create a new file for each user:
    Code (Skript):
    1. set yml value "balance" of file "plugins/SuperEconomy/data/%uuid of player%.yml" to ...
    and read the value like this:
    Code (Skript):
    1. set {...} to yml value "balance" of file "plugins/SuperEconomy/data/%uuid of player%.yml"

    Example:
    http://skunity.com/search?search=Yaml+(skUtilities)
     
    • Like Like x 1
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    I have done this part of code:
    Code (Skript):
    1. on join:
    2.     file "plugins/SuperEconomy/data/%uuid of player%.yml" doesn't exist:
    3.         create file "plugins/SuperEconomy/data/%uuid of player%.yml"
    4.         set yml value "Data of" of file "plugins/SuperEconomy/data/%uuid of player%.yml" to "%player%"
    5.         set yml value "balance" of file "plugins/SuperEconomy/data/%uuid of player%.yml" to "0"
    6.         set {seco.bal::%player%} to yml value "balance" of file "plugins/SuperEconomy/data/%uuid of player%.yml"
    It creates the file correctly, but the variable {seco.bal::%player%} doesn't refer to the file. If I set this variable to another value, it should update the value "balance" from the file to the new value, but it does nothing. Can somebady help me?
    Thanks
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Why do you event want to save it using a file instead of a variable? Just variables are easier and much faster.

    My Ideas:
    1) You can create a function which updates the file every time you edit the variable.
    2) You can create a function which updates the file on quit, join, every 5 seconds, unload, etc.
    3) Don't even use Variables. Just read the file every time you need it.
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    I think it's better to have the money safe in a file for each user.
    So what I need to do is to rewrite the file every time I need to change the value?
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Yes, if you don't rewrite the file, it can't be updated.

    Why do you think is a file safer than a Variable?
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Because the file is always there, and if the server gets crashed the value is not going to get damaged, and it allows you to change values manualy, while you can't do that in the skript variable exel.
     
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    I do not recommend to do that.
    But if you still want to do this you'll have to edit and read the file every time you need it.

    If you would use a SQLite database, you could still edit the values manually easily
     
    #8 ShaneBee, May 22, 2017
    Last edited by a moderator: May 22, 2017
  9. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Yes, I'm planning to add SQLite or MySQL support for my skript. Do you know how can I do it?
     
  10. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Yes. You need this Plugin: https://dev.bukkit.org/projects/sqlibrary

    After you installed it, you can use SQLite as database in the config.sk of skript.
    Code (Skript):
    1. databases:
    2.     default:
    3.         type: SQLite
    4.         pattern: .*
    5.         file: ./plugins/Skript/database.db
    6.         backup interval: 6 hours
    7.         monitor changes: false
    8.         monitor interval: 120 seconds
     
  11. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...