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

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

KroterPvP

Active Member
Apr 10, 2017
178
7
18
22
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?
 
Last edited:
You could save the value using this:
code_language.skript:
set yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml" to ...
and read the value like this:
code_language.skript:
set {...} to yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml"



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


Example:
http://skunity.com/search?search=Yaml+(skUtilities)
 
  • Like
Reactions: glowgrew
You could save the value using this:
code_language.skript:
set yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml" to ...
and read the value like this:
code_language.skript:
set {...} to yml value "%uuid of player%" of file "plugins/SuperEconomy/data.yml"



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


Example:
http://skunity.com/search?search=Yaml+(skUtilities)
I have done this part of code:
code_language.skript:
on join:
    file "plugins/SuperEconomy/data/%uuid of player%.yml" doesn't exist:
        create file "plugins/SuperEconomy/data/%uuid of player%.yml"
        set yml value "Data of" of file "plugins/SuperEconomy/data/%uuid of player%.yml" to "%player%"
        set yml value "balance" of file "plugins/SuperEconomy/data/%uuid of player%.yml" to "0"
        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
 
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.
 
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.
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?
 
Yes, if you don't rewrite the file, it can't be updated.

Why do you think is a file safer than a Variable?
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.
 
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
 
Last edited by a moderator:
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
Yes, I'm planning to add SQLite or MySQL support for my skript. Do you know how can I do it?
 
Status
Not open for further replies.