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):
Thanks a lot. Hope to learn a bit from the skript sharks of the forums.
-jabbe
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