Files
AuctionHouse.sk
Code
1 1,010
AuctionHouse.sk
# ============================================================
# AuctionHouse.sk
# A secure, full-featured Auction House for Skript + SkBee
# Place in: plugins/Skript/scripts/
# Reload with: /sk reload AuctionHouse
# Requires: Skript, SkBee
# ============================================================
options:
prefix: &8[&6Auction House&8]&r
max_listings_per_player: 10
default_duration_hours: 24
max_duration_hours: 168
min_price: 1
max_price: 100000000
tax_percent: 5
currency_symbol: $
gui_rows: 6
items_per_page: 45
border_item: BLACK_STAINED_GLASS_PANE
color_primary: &6
color_secondary: &e
color_success: &a
color_error: &c
color_info: &b
color_muted: &7
# ============================================================
# UTILITY FUNCTIONS
# ============================================================
function ah_prefix() :: text:
return "{@prefix} "
function ah_tax(price: number) :: number:
return {_price} * ({@tax_percent} / 100)
function ah_format_number(n: number) :: text:
if {_n} >= 1000000:
set {_v} to {_n} / 1000000
return "%{_v}%M"
else if {_n} >= 1000:
set {_v} to {_n} / 1000
return "%{_v}%K"
return "%{_n}%"
function ah_timestamp_to_text(ts: number) :: text:
set {_remaining} to {_ts} - unix timestamp of now
if {_remaining} <= 0:
return "&cExpired"
set {_hours} to floor({_remaining} / 3600)
set {_minutes} to floor(({_remaining} mod 3600) / 60)
set {_seconds} to floor({_remaining} mod 60)
if {_hours} > 0:
return "&e%{_hours}%h &7%{_minutes}%m &7%{_seconds}%s"
else if {_minutes} > 0:
return "&e%{_minutes}%m &7%{_seconds}%s"
return "&c%{_seconds}%s"
function ah_new_id() :: text:
add 1 to {ah_id_counter}
return "AH-%{ah_id_counter}%"
function ah_count_player_listings(p: offline player) :: integer:
set {_count} to 0
loop {ah_listings::*}:
if {ah_listing_seller::%loop-value%} is {_p}:
if {ah_listing_active::%loop-value%} is true:
add 1 to {_count}
return {_count}
function ah_is_listing_valid(id: text) :: boolean:
if {ah_listing_active::%{_id}%} is not true:
return false
if unix timestamp of now >= {ah_listing_expire::%{_id}%}:
return false
return true
function ah_expire_listing(id: text):
set {ah_listing_active::%{_id}%} to false
set {_seller} to {ah_listing_seller::%{_id}%}
if {_seller} is set:
add {ah_listing_item::%{_id}%} to {ah_returns::%{_seller}%::*}
set {ah_return_reason::%{_seller}%::%loop-index of {ah_returns::%{_seller}%::*}%} to "expired"
function ah_process_expired_listings():
loop {ah_listings::*}:
set {_id} to loop-value
if {ah_listing_active::%{_id}%} is true:
if unix timestamp of now >= {ah_listing_expire::%{_id}%}:
ah_expire_listing({_id})
function ah_play_sound_open(p: player):
play sound "block.chest.open" with volume 0.7 and pitch 1.0 to {_p}
function ah_play_sound_close(p: player):
play sound "block.chest.close" with volume 0.7 and pitch 1.0 to {_p}
function ah_play_sound_click(p: player):
play sound "ui.button.click" with volume 0.5 and pitch 1.2 to {_p}
function ah_play_sound_buy(p: player):
play sound "entity.player.levelup" with volume 0.8 and pitch 1.3 to {_p}
play sound "entity.experience_orb.pickup" with volume 0.6 and pitch 1.5 to {_p}
function ah_play_sound_sell(p: player):
play sound "entity.villager.yes" with volume 0.8 and pitch 1.1 to {_p}
function ah_play_sound_cancel(p: player):
play sound "entity.villager.no" with volume 0.7 and pitch 0.9 to {_p}
function ah_play_sound_error(p: player):
play sound "entity.villager.hurt" with volume 0.8 and pitch 0.8 to {_p}
function ah_play_sound_success(p: player):
play sound "entity.player.levelup" with volume 0.6 and pitch 1.6 to {_p}
function ah_play_sound_page(p: player):
play sound "item.book.page_turn" with volume 0.6 and pitch 1.2 to {_p}
# ============================================================
# LOCK / ANTI-DUPLICATION SYSTEM
# ============================================================
function ah_acquire_lock(p: player) :: boolean:
if {ah_lock::%{_p}%} is true:
return false
set {ah_lock::%{_p}%} to true
return true
function ah_release_lock(p: player):
delete {ah_lock::%{_p}%}
function ah_acquire_listing_lock(id: text) :: boolean:
if {ah_listing_lock::%{_id}%} is true:
return false
set {ah_listing_lock::%{_id}%} to true
return true
function ah_release_listing_lock(id: text):
delete {ah_listing_lock::%{_id}%}
# ============================================================
# GUI BUILDER FUNCTIONS
# ============================================================
function ah_set_border(inv: inventory):
set {_pane} to a black stained glass pane named " "
loop integers from 0 to 8:
set slot loop-number of {_inv} to {_pane}
loop integers from 45 to 53:
set slot loop-number of {_inv} to {_pane}
function ah_build_nav_buttons(inv: inventory, page: integer, max_page: integer):
# Previous page
if {_page} > 1:
set {_prev} to a arrow named "&ePrevious Page" with lore "&7Page %{_page} - 1% of %{_max_page}%"
set slot 45 of {_inv} to {_prev}
else:
set slot 45 of {_inv} to a black stained glass pane named " "
# Page info
set {_info} to a paper named "&6Page %{_page}% &7of &6%{_max_page}%" with lore "&7Click arrows to navigate"
set slot 49 of {_inv} to {_info}
# Next page
if {_page} < {_max_page}:
set {_next} to a arrow named "&eNext Page" with lore "&7Page %{_page} + 1% of %{_max_page}%"
set slot 53 of {_inv} to {_next}
else:
set slot 53 of {_inv} to a black stained glass pane named " "
function ah_build_listing_item(id: text) :: item:
set {_base} to {ah_listing_item::%{_id}%}
if {_base} is not set:
return air
set {_seller} to {ah_listing_seller::%{_id}%}
set {_price} to {ah_listing_price::%{_id}%}
set {_expire} to {ah_listing_expire::%{_id}%}
set {_time_text} to ah_timestamp_to_text({_expire})
set {_price_text} to "&a{@currency_symbol}%ah_format_number({_price})%"
set {_display} to name of {_base}
if {_display} is not set or {_display} is "":
set {_display} to "&f%type of {_base}%"
set {_lore} to lore of {_base}
set {_new_lore::1} to "&8─────────────────"
set {_new_lore::2} to "&7Seller: &e%{_seller}%"
set {_new_lore::3} to "&7Price: %{_price_text}%"
set {_new_lore::4} to "&7Time Left: %{_time_text}%"
set {_new_lore::5} to "&7ID: &8%{_id}%"
set {_new_lore::6} to "&8─────────────────"
set {_new_lore::7} to "&eLeft-Click &7to purchase"
set {_new_lore::8} to "&eRight-Click &7to preview"
loop {_lore::*}:
set {_idx} to size of {_new_lore::*} + 1
set {_new_lore::%{_idx}%} to loop-value
set {_visual} to {_base}
set name of {_visual} to {_display}
set lore of {_visual} to {_new_lore::*}
return {_visual}
# ============================================================