Files
shop.sk
Code
1 146
shop.sk
options:
shop-title: &8Server Shop
admin-permission: shop.admin
command /shop [<text>] [<number>] [<number>]:
trigger:
if sender is not a player:
send "&cThis command can only be used by a player."
stop
if arg-1 is not set:
delete {shop.gui.slot::%uuid of player%::*}
set {_gui} to chest inventory with 6 rows named "{@shop-title}"
set {_slot} to 0
loop {shop.item::*}:
if {_slot} is greater than 44:
stop loop
set {_display} to loop-value
set amount of {_display} to 1
set {_buy} to {shop.buy::%loop-index%}
set {_sell} to {shop.sell::%loop-index%}
set lore of {_display} to "&7Buy: &a$%{_buy}%" and "&7Sell: &c$%{_sell}%" and "" and "&eLeft-click to buy" and "&eRight-click to sell"
set slot {_slot} of {_gui} to {_display}
set {shop.gui.slot::%uuid of player%::%{_slot}%} to loop-index
add 1 to {_slot}
open {_gui} to player
stop
if arg-1 is "add":
if player doesn't have permission "{@admin-permission}":
send "&cYou do not have permission to add shop items."
stop
if arg-2 is not set or arg-3 is not set:
send "&cUsage: /shop add <buy price> <sell price>"
stop
if arg-2 is less than or equal to 0:
send "&cThe buy price must be greater than zero."
stop
if arg-3 is less than 0:
send "&cThe sell price cannot be negative."
stop
if player's tool is air:
send "&cHold the item you want to add in your hand."
stop
add 1 to {shop.next-id}
set {_id} to {shop.next-id}
set {shop.item::%{_id}%} to player's tool
set {shop.buy::%{_id}%} to arg-2
set {shop.sell::%{_id}%} to arg-3
send "&aAdded &f%type of player's tool% &ato the shop with ID &e%{_id}%&a."
stop
if arg-1 is "remove":
if player doesn't have permission "{@admin-permission}":
send "&cYou do not have permission to remove shop items."
stop
if arg-2 is not set:
send "&cUsage: /shop remove <ID>"
stop
set {_id} to arg-2
if {shop.item::%{_id}%} is not set:
send "&cNo shop item exists with ID %{_id}%."
stop
delete {shop.item::%{_id}%}
delete {shop.buy::%{_id}%}
delete {shop.sell::%{_id}%}
send "&aRemoved shop item &e%{_id}%&a."
stop
if arg-1 is "list":
if player doesn't have permission "{@admin-permission}":
send "&cYou do not have permission to view the shop list."
stop
if {shop.item::*} is not set:
send "&cThere are no items in the shop."
stop
send "&8&m--------------------"
send "&6Shop Items:"
loop {shop.item::*}:
send "&eID %{loop-index}% &7- &f%type of loop-value% &7- Buy: &a$%{shop.buy::%loop-index%}% &7Sell: &c$%{shop.sell::%loop-index%}%"
send "&8&m--------------------"
stop
send "&6/shop &7- Open the shop"
send "&6/shop add <buy> <sell> &7- Add the item in your hand"
send "&6/shop remove <ID> &7- Remove a shop item"
send "&6/shop list &7- List shop item IDs"
on inventory click:
if name of event-inventory is "{@shop-title}":
cancel event
if clicked inventory is not event-inventory:
stop
if clicked slot is not between 0 and 44:
stop
set {_id} to {shop.gui.slot::%uuid of player%::%clicked slot%}
if {_id} is not set:
stop
if click type is left mouse button:
set {_price} to {shop.buy::%{_id}%}
if player's balance is less than {_price}:
send "&cYou need &f$%{_price}% &cto buy this item."
stop
remove {_price} from player's balance
set {_item} to {shop.item::%{_id}%}
set amount of {_item} to 1
give {_item} to player
send "&aYou bought &f%type of {_item}% &afor &e$%{_price}%&a."
else if click type is right mouse button:
set {_item} to {shop.item::%{_id}%}
set amount of {_item} to 1
set {_price} to {shop.sell::%{_id}%}
if player does not have {_item}:
send "&cYou do not have this item to sell."
stop
remove {_item} from player
add {_price} to player's balance
send "&aYou sold &f%type of {_item}% &afor &e$%{_price}%&a."
on inventory close:
if name of event-inventory is "{@shop-title}":
delete {shop.gui.slot::%uuid of player%::*}