ShopAPI
A script api that brings creating shops to ease
__________________________________________________________________________________________
Syntax:
buy([item], [amount], %player%)
#Checks for the requested %player% balance.
#Gives the [item] to %player% with the [amount] provided.
Sell("single", [item], [price], %player%)
#Sells a single piece of [item] and adding [price] to %player% balance.
Sell("all", [item], [price], %player%)
#Sells all of [item] in %player% inventory and adding [price] to their balance.
Requirements:
Skript: This script wouldn't run without this plugin.
Vault: This plugin is to handle the economy this script contains
TuSKe: This is only required if you plan on making a shop gui instead.
Example:
format a gui slot 0 of player with stone lored "&6&l* &e[Buyable] &f$3 &7per||&6&l* &e[Sellable] &f$0.01 &7per||||&e[Click to Transact]||||&7&o (( Tip: Use middle mouse button to sell all. ))" to run:
if click type is left mouse button:
Buy(stone, 3, player)
if click type is middle mouse button:
Sell("all", stone, 0.01, player)
if click type is right mouse button:
Sell("single", stone, 0.01, player)
Code:
function Sell(type: text, item: item type, price: num, p: player):
set {_amount} to amount of {_item} in {_p}'s inventory
set {_totalProfit} to {_amount} * {_price}
set {_v::*} to vanilla name of {_item}
replace all "minecraft:" and "_block" with "" in {_v::1}
replace all "_" with " " in {_v::1}
if {_type} contains "all":
if {_amount} is greater than or equal to 1:
add ({_amount} * {_price}) to {_p}'s balance
send "&e&l(!) &eYou successfully sold all &6&n%{_v::1}%&7 (&8%{_amount}%&8x&7) &efor &6&n$%{_totalProfit}%" to {_p}
remove all {_item} from {_p}
else:
send "&e&l(!) &eYou don't have enough &6&n%{_v::*}%&e to sell." to {_p}
if {_type} contains "single":
if {_amount} is greater than or equal to 1:
add {_price} to {_p}'s balance
send "&e&l(!) &eYou successfully sold all &6&n%{_v::1}%&7 (&81x&7) &efor &6&n$%{_price}%" to {_p}
remove 1 of {_item} from {_p}
else:
send "&e&l(!) &eYou don't have enough &6&n%{_v::1}%&e to sell." to {_p}
function Buy(item: item type, price: num, p: player):
set {_v::*} to vanilla name of {_item}
replace all "minecraft:" and "_block" with "" in {_v::1}
replace all "_" with " " in {_v::1}
if {_p}'s balance is greater than or equal to {_price}:
remove {_price} from {_p}'s balance
give {_p} 1 of {_item}
send "&e&l(!) &eYou successfully bought &71x &6&n%{_v::1}%&e for &6&n$%{_price}%&e." to {_p}
else:
send "&e&l(!) &eYou don't have enough money, you need &6&n$%{_price}%&e to buy this item." to {_p}