Skip to content

Instantly share code, notes, and snippets.

@sug0
Created April 21, 2020 14:22
Show Gist options
  • Select an option

  • Save sug0/79cbb42ab7fc2f70836b960d72f4379b to your computer and use it in GitHub Desktop.

Select an option

Save sug0/79cbb42ab7fc2f70836b960d72f4379b to your computer and use it in GitHub Desktop.
Scarpet script to manage a diamond bank
__command() -> usage();
usage() -> (
'/diamonds consult\n' +
'/diamonds deposit <amount>\n' +
'/diamonds withdraw <amount>\n' +
'/diamonds sacrifice <amount>\n' +
'/diamonds transfer <target-user> <amount>'
);
consult() -> (
diamonds = scoreboard('diamonds', player());
str('You have %.0fĐ.', diamonds)
);
deposit(amount) -> (
if (
number(amount) == null,
return('Amount is non numeric.')
);
amt = floor(amount);
if (
amt <= 0,
return('The deposit amount should be positive.')
);
if (
inventory_remove(player(), 'diamond', amt),
(
diamonds = scoreboard('diamonds', player());
new_diamonds = diamonds + amt;
scoreboard('diamonds', player(), new_diamonds);
str('Deposited %.0fĐ. Your current balance is now %.0fĐ.', amt, new_diamonds)
),
str('You don\'t have, at least, %.0f diamonds in your inventory.', amt)
)
);
withdraw(amount) -> (
if (
number(amount) == null,
return('Amount is non numeric.')
);
amt = floor(amount);
if (
amt <= 0,
return('The withdraw amount should be positive.')
);
diamonds = scoreboard('diamonds', player());
new_diamonds = diamonds - amt;
if (
new_diamonds < 0,
// true
str('Your current balance (%.0fĐ) isn\'t enough to withdraw the requested amount.', diamonds),
// false
(
scoreboard('diamonds', player(), new_diamonds);
run(str('give @s minecraft:diamond %.0f', amt));
str('Withdrew %.0fĐ. Your current balance is now %.0fĐ', amt, new_diamonds)
)
)
);
sacrifice(amount) -> transfer('DIAMOND_POOL', amount);
transfer(target_user, amount) -> (
if (
number(amount) == null,
return('Amount is non numeric.')
);
amt = floor(amount);
if (
amt <= 0,
return('The transfer amount should be positive.')
);
diamonds = scoreboard('diamonds', player());
new_diamonds = diamonds - amt;
if (
new_diamonds < 0,
// true
str('Your current balance (%.0fĐ) isn\'t enough to perform the transfer.', diamonds),
// false
(
scoreboard('diamonds', player(), new_diamonds);
target_diamonds = scoreboard('diamonds', target_user);
scoreboard('diamonds', target_user, target_diamonds + amt);
if (
target_user == 'DIAMOND_POOL',
target_user = 'the diamond pool'
);
str('Transfered %.0fĐ to %s.', amt, target_user)
)
)
);
__config() -> m(l('stay_loaded', true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment