Try my survival chest shop skript

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

    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.

redbau

New Member
Feb 3, 2017
6
0
1
44
Hello, I'm looking for feedback and bugs with my shop skript I'm quite proud of, it's my first!

Q4MicIP.gif


Setting up a shop is easy.
1) Place your chest on a claim
2) give it `/containertrust public` and then
3) add a sign like this...
Line 1: $
Line 2: Optional description
Line 3: Price 1-64 diamond, d, diamond block, db, iron, i, gold, g, emerald, e
Line 4: Leave blank to auto-fill your name

Buying is as simple as using the chest:

DZJjbES.gif


And it errors when you have no money:

mGzKbES.gif


Skript dependencies:
- skellett (for inventory clicked item tracking: https://www.skunity.com/expressions?filter=Skellett#Inventoryclickeditem)
- skquery (on inventory click: https://www.skunity.com/events?filter=SkQuery#OnInventoryClick)

Other plugins:
- GriefPrevention (for claims protection so people can't break your chests/signs)

What do you all think? How can this be improved or secured in any way? Would love for people to download it and try it out and post any comments or feedback! Thanks.

View the code here: http://pastebin.com/1rbxdL4x
code_language.skript:
# Simple chest shop
# A chest/sign shop Skript for survival and vanilla friendly servers.
# By redbau
options:
  prefix: &5[&dWilderShop&5]&f
  prefix_sign: &5[&d\$&5]

command /shop:
  permission: sell.sk
  aliases: /$
  trigger:
    message ""
    message "{@prefix} <white>Setup Shop:"
    message "<dark gray>1) <dark aqua>Place a chest on your claim"
    message "<dark gray>2) <dark aqua>Add sign..."
    message "  <dark gray>Line 1: <yellow>$"
    message "  <dark gray>Line 2: <yellow><Optional bold description>"
    message "  <dark gray>Line 3: <yellow><1-64> <diamond|d|diamond block|db|iron|i|ib|gold|g|gb|emerald|e|eb>"
    message "  <dark gray>Line 4: <yellow><Leave empty>"
    message "<dark gray>3) <dark aqua>Give players access: <light green>/containertrust public"
    message "<dark gray>4) You're done, nice work!"
    message ""

on sign change:
  player has permission "sell.sk"
  line 1 of event-block = "[$]" or "$"
  set {_desc} to line 2 of event-block
  set {_s::*} to line 3 of event-block split at " "
  set {_cnt} to {_s::1}
  set {_money} to {_s::2}
  if "%{_money}%" = "<none>":
    message "{@prefix} <red>Invalid currency!"
    set event-block to air
    drop a sign at event-location
    cancel event
    stop
  if "%{_money}%" = "d":
    set {_money} to diamond
  if "%{_money}%" = "db":
    set {_money} to "diamond_block"
  if "%{_money}%" = "iron":
    set {_money} to "iron_ingot"
  if "%{_money}%" = "i":
    set {_money} to "iron_ingot"
  if "%{_money}%" = "ib":
    set {_money} to "iron_block"
  if "%{_money}%" = "g":
    set {_money} to "gold_ingot"
  if "%{_money}%" = "gold":
    set {_money} to "gold_ingot"
  if "%{_money}%" = "gb":
    set {_money} to "gold_block"
  if "%{_money}%" = "e":
    set {_money} to emerald
  if "%{_money}%" = "eb":
    set {_money} to "emerald_block"
  if {_cnt} parsed as integer > 64:
    message "{@prefix} <red>Price should be between 1-64!"
    set event-block to air
    drop a sign at event-location
    cancel event
    stop
  if {_money} parsed as item is not diamond or diamond block or iron ingot or iron block or gold ingot or gold block or emerald or emerald block:
    message "{@prefix} <red>Use a valid currency: diamond|d|diamond block|db|iron|i|ib|gold|g|gb|emerald|e|eb!"
    set event-block to air
    drop a sign at event-location
    cancel event
    stop
  set line 1 of event-block to "{@prefix_sign}"
  replace "blocks" in {_money} with "block" #shorten '64 diamond_blocks' to fit on sign
  set line 2 of event-block to "&5&l%{_desc}%"
  set line 3 of event-block to "%{_cnt}% %{_money}%"
  set line 4 of event-block to "&6%name of player%"
  message "{@prefix} Chest shop created and <green>open for business!"
  message "{@prefix} Selling each item stack for: <green>%{_cnt}% %{_money}%."

on rightclick on a chest or trapped chest: # works with both types of chests
  set {_tmpchest} to location of event-block
  set {chest.%player%} to event-block
  loop blocks in front of {_tmpchest}:
    if type of loop-block is air:
      set {shop.%player%} to false
      stop
    if type of loop-block is wall sign:
      if line 1 of loop-block is "{@prefix_sign}":
        set {chestloc.%player%} to location of loop-block
        set {_s::*} to line 3 of loop-block split at " "
        set {_cnt} to {_s::1}
        set {_money} to {_s::2}
        set {costnum.%player%} to {_s::1} parsed as integer
        set {costitem.%player%} to {_s::2}
        set {shopowner.%player%} to uncolored line 4 of loop-block
        replace "_" in {costitem.%player%} with " " #check proper item name with space
        set {costitem.%player%} to {costitem.%player%} parsed as item
        message "{@prefix} Items inside will cost: &d%{costnum.%player%}% %{costitem.%player%}% &5per stack."
        #if player has permission "shop.sk":
        set {shop.%player%} to true
        stop

on inventory close:
  #player has permission "shop.sk"
  set {shop.%player%} to false

on inventory click:
  #player has permission "shop.sk"
  if {shop.%player%} is true:
    #[todo] fix sometimes null %inventory type% console log warning.
    if inventory type of clicked inventory is "PLAYER":
      if name of player is not "%{shopowner.%player%}%":
        message "{@prefix} Can't place items in someone else's shop!"
        cancel event
    if inventory type of clicked inventory is "CHEST":
      set {_itemslot} to clicked slot
      set {_theitem} to clicked item
      set {_theitem} to {_theitem} parsed as item
      if {_theitem} is not air:
        if name of player is not "%{shopowner.%player%}%":
          # Buy it now
          if player has {costnum.%player%} of {costitem.%player%}:
            # Cancel if non-item (e.g. buying 1 diamond for 1 diamond)
            if {costnum.%player%} of {costitem.%player%} is {_theitem}:
              cancel event
              stop
            # [bug] Using item stack == always true
            if player has enough space for 64 stone:
              remove {costnum.%player%} of {costitem.%player%} from player's inventory
              add {_theitem} to player's inventory
              # Swap item with money
              set slot {_itemslot} of {chest.%player%}'s inventory to {costnum.%player%} of {costitem.%player%}
              log "%player% -> %{_theitem}% [%{costnum.%player%}% %{costitem.%player%}%] from %{shopowner.%player%}%'s shop (%{chestloc.%player%}% in %world%)" to "shop.log"
              message "{@prefix} <dark green>Purchased %{_theitem}% for: <green>%{costnum.%player%}% %{costitem.%player%}%."
              cancel event
            else:
              message "{@prefix} <light red>You don't have enough free inventory space!"
              cancel event
          # Can't afford it!
          else:
            message "{@prefix} &c<dark red>You don't have <red>&4%{costnum.%player%}% %{costitem.%player%}%!"
            cancel event
          stop
        else:
          message "{@prefix} <green>You own this item."
 
Status
Not open for further replies.