I'm sure there's a better way of doing this ...

  • 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 community!

    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.

Jakkeren

Supporter
Mar 23, 2017
63
3
8
Basically I'm making a skript, making players able to exhange their gold nuggets into ingots, and ingots into blocks.

What I'm trying to achieve:
Using the exchange function linked below, should convert all of the selected currency (nugget, ingot, block) into either nuggets, ingots or block. Example: I do a veksel(block) function, and it calculates all of the possible blocks I can make out of the nuggets and ingots in my inventory and makes them into blocks without removing the spare ones. Same thing when exchanging into nuggets: it should turn your ingots and blocks into the amount of nuggets, they 'contain', you can say I guess.

What I've achieved:
Even though it's almost working, and without errors at all, it's really unstable, and sometimes gives you a tiny bit extra, or a tiny bit less than you're supposed to. It's not entirely a skript question, I guess you can say, but requires quite a bit of mathematics.

My current code(No errors):
Code:
function veksel(p: player, to: item):
    {_to} is gold nugget:
        {_p}'s inventory does not contain 1 of gold ingot or 1 of gold block:
            send "&cDu har ikke noget at veksle&l!" to {_p}
            stop
        set {_ingot} to amount of gold ingot in {_p}'s inventory
        set {_block} to amount of gold block in {_p}'s inventory
        set {_blockearn} to {_block} * 81
        set {_ingotearn} to {_ingot} * 9
        set {_get} to {_ingotearn} + {_blockearn}
        if {_p} has enough space for {_get} of gold nugget:
            set {_loseingot} to {_ingotearn} * 9
            set {_loseblock} to {_blockearn} * 81
            remove {_loseingot} of gold ingot from {_p}'s inventory
            remove {_loseblock} of gold block from {_p}'s inventory
            give {_p} {_get} of gold nugget
        else:
            send "&cDu har ikke plads i din inventory&l!" to {_p}
            stop
        send "&aSucces&l!" to {_p}
    {_to} is gold ingot:
        {_p}'s inventory does not contain 9 of gold nugget or 1 of gold block:
            send "&cDu har ikke noget at veksle&l!" to {_p}
            stop
        set {_nug} to amount of gold nugget in {_p}'s inventory
        set {_block} to amount of gold block in {_p}'s inventory
        set {_blockearn} to {_block} * 9
        set {_nugearn} to round({_nug} / 9)
        set {_get} to {_nugearn} + {_blockearn}
        if {_p} has enough space for {_get} of gold ingot:
            set {_losenug} to {_nugearn} * 9
            set {_loseblock} to {_blockearn} * 81
            remove {_losenug} of gold nugget from {_p}'s inventory
            remove {_loseblock} of gold block from {_p}'s inventory
            give {_p} {_get} of gold ingot
        else:
            send "&cDu har ikke plads i din inventory&l!" to {_p}
            stop
        send "&aSucces&l!" to {_p}
    {_to} is gold block:
        {_p}'s inventory does not contain 9 of gold ingot:
            send "&cDu har ikke noget at veksle&l!" to {_p}
            stop
        set {_ing} to amount of gold ingot in {_p}'s inventory
        set {_ingearn} to round({_ing} / 9)
        set {_get} to {_ingearn}
        if {_p} has enough space for {_get} of gold block:
            set {_loseing} to {_ingearn} * 9
            remove {_loseing} of gold ingot from {_p}'s inventory
            give {_p} {_get} of gold block
        else:
            send "&cDu har ikke plads i din inventory&l!" to {_p}
            stop
        send "&aSucces&l!" to {_p}

Thanks a lot. Hope to learn a bit from the skript sharks of the forums.

-jabbe
 
Status
Not open for further replies.