Files
LendShop.sk
Code
1 881
LendShop.sk
# ═══════════════════════════════════════════════════════════════════
# LendShop.sk — Item Lending Marketplace
# ───────────────────────────────────────────────────────────────────
#
# Commands:
# /lend — Open the lending marketplace browser
# /lend list <$/hr> — List the item in your main hand for rent
# /lend view <user> — View all of a player's active/borrowed listings
# /lend lock — (OP) Disable lending for all non-OP players
# /lend unlock — (OP) Re-enable lending
#
# Requirements:
# Skript 2.6+ | Vault + any Economy plugin (EssentialsX, CMI…)
#
# Install : plugins/Skript/scripts/LendShop.sk
# Reload : /sk reload LendShop
#
# ── Variable Reference ────────────────────────────────────────────
#
# {lend::locked} — boolean, global lock
# {lend::nextid} — auto-increment counter
# {lend::listings::*} — list of all listing IDs
# {lend::listing::%id%::item} — stored ItemStack
# {lend::listing::%id%::owner} — owner display name
# {lend::listing::%id%::price} — price/hr (number)
# {lend::listing::%id%::active} — true = available to borrow
# {lend::listing::%id%::borrower} — borrower display name
# {lend::listing::%id%::borrow_until} — unix expiry timestamp
# {lend::listing::%id%::timestamp} — unix creation timestamp
#
# Per-player state (cleaned up on inventory close):
# {lend::gui::%p%} — current GUI tag
# {lend::page::%p%} — browse page number
# {lend::sort::%p%} — sort mode (newest/price_asc/price_desc)
# {lend::search::%p%} — active search filter
# {lend::searching::%p%} — true while awaiting chat input
# {lend::viewtarget::%p%} — player name for view GUI
# {lend::viewpage::%p%} — page number for view GUI
# {lend::borrowid::%p%} — listing ID staged for borrow
# {lend::opening::%p%} — transition flag (prevents stale cleanup)
# {lend::slot::%p%::%n%} — maps GUI slot → listing ID
#
# Pending listing (set by /lend list, consumed by confirm GUI):
# {lend::pending::%p%::item}
# {lend::pending::%p%::price}
# ═══════════════════════════════════════════════════════════════════
options:
prefix: &8[&6Lend&8]&r
# ─────────────────────────────────────────────────────────────────
# INITIALIZATION
# ─────────────────────────────────────────────────────────────────
on script load:
if {lend::nextid} is not set:
set {lend::nextid} to 0
if {lend::locked} is not set:
set {lend::locked} to false
# Restore any listings whose borrow period expired during downtime
loop {lend::listings::*}:
set {_id} to loop-value
if {lend::listing::%{_id}%::active} is false:
if {lend::listing::%{_id}%::borrow_until} is set:
if unix timestamp of now >= {lend::listing::%{_id}%::borrow_until}:
set {lend::listing::%{_id}%::active} to true
delete {lend::listing::%{_id}%::borrower}
delete {lend::listing::%{_id}%::borrow_until}
send "&8[&6Lend&8] &aLendShop loaded." to console
on script unload:
loop all players:
delete {lend::gui::%loop-player%}
delete {lend::opening::%loop-player%}
# ─────────────────────────────────────────────────────────────────
# CHAT — Search query capture
# ─────────────────────────────────────────────────────────────────
on chat:
if {lend::searching::%player%} is true:
cancel event
if message is "cancel":
delete {lend::search::%player%}
send "{@prefix} &7Search filter cleared." to player
else:
set {lend::search::%player%} to message
send "{@prefix} &7Searching for: &f%message%" to player
delete {lend::searching::%player%}
set {lend::page::%player%} to 1
wait 1 tick
lend_openBrowse(player)
# ─────────────────────────────────────────────────────────────────
# INVENTORY — Close cleanup
# ─────────────────────────────────────────────────────────────────
on inventory close:
if {lend::opening::%player%} is not set:
if {lend::gui::%player%} is set:
delete {lend::gui::%player%}
loop 45 times:
delete {lend::slot::%player%::%loop-number - 1%}
# ─────────────────────────────────────────────────────────────────
# INVENTORY — Click dispatcher
# ─────────────────────────────────────────────────────────────────
on inventory click:
if {lend::gui::%player%} is set:
cancel event
set {_raw} to rawslot of event-slot
set {_gui} to {lend::gui::%player%}
if {_gui} is "browse":
lend_browseClick(player, {_raw})
else if {_gui} is "confirm":
lend_confirmClick(player, {_raw})
else if {_gui} is "view":
lend_viewClick(player, {_raw})
else if {_gui} is "hours":
lend_hoursClick(player, {_raw})
# ─────────────────────────────────────────────────────────────────
# COMMAND: /lend
# ─────────────────────────────────────────────────────────────────
command /lend [<text>] [<text>]:
trigger:
set {_a1} to arg-1 ? "open"
set {_a2} to arg-2 ? ""
# ── OP lock / unlock ──────────────────────────────────────
if {_a1} is "lock" or {_a1} is "unlock":
if player is not op:
send "{@prefix} &cYou must be OP to use this command." to player
stop
if {_a1} is "lock":
set {lend::locked} to true
send "{@prefix} &cLending has been &4locked&c." to player
else:
set {lend::locked} to false
send "{@prefix} &aLending has been &2unlocked&a." to player
stop
# ── Global lock gate ──────────────────────────────────────
if {lend::locked} is true:
if player is not op:
send "{@prefix} &cLending is currently disabled by an admin." to player
stop
# ── /lend list <price> ────────────────────────────────────
if {_a1} is "list":
if {_a2} is "":
send "{@prefix} &cUsage: &f/lend list <price per hour>" to player
stop
if player's tool is air:
send "{@prefix} &cYou must hold an item in your main hand to list it." to player
stop
set {_price} to {_a2} parsed as number
if {_price} is not set:
send "{@prefix} &c'%{_a2}%' is not a valid number." to player
stop
if {_price} <= 0:
send "{@prefix} &cPrice per hour must be greater than 0." to player
stop
set {lend::pending::%player%::item} to player's tool
set {lend::pending::%player%::price} to {_price}
lend_openConfirm(player)
stop
# ── /lend view <player> ───────────────────────────────────
if {_a1} is "view":
if {_a2} is "":
send "{@prefix} &cUsage: &f/lend view <player>" to player
stop
set {lend::viewtarget::%player%} to {_a2}
set {lend::viewpage::%player%} to 1
lend_openView(player)
stop
# ── Default — open browse ─────────────────────────────────
if {lend::page::%player%} is not set:
set {lend::page::%player%} to 1
if {lend::sort::%player%} is not set:
set {lend::sort::%player%} to "newest"
lend_openBrowse(player)
# ═══════════════════════════════════════════════════════════════════
# DATA FUNCTIONS
# ═══════════════════════════════════════════════════════════════════
# ── Return filtered + sorted active listing IDs ──────────────────
function lend_getListings(sort: text, search: text, owner: text) :: texts: