onShopClosed
Purpose
Triggered when a player closes a shop's UI. Use this hook to play sounds, track time spent in shops, or perform cleanup actions.
When It Triggers
Player presses escape or clicks the close button
Player walks away from the shop while UI is open
UI is forcefully closed by the system
Parameters
Parameter
Type
Description
data.shopId
string
Unique shop identifier
data.shopType
string
Type of shop
data.shopName
string
Display name of the shop
data.timeSpentInShop
number
Milliseconds spent with UI open
data.itemsViewed
number
Number of unique items viewed
data.cartItemCount
number
Items in cart when closed (0 if purchased)
data.didPurchase
boolean
Whether a purchase was made
Example
exports['sd-shops']:registerClientHook('onShopClosed', function(data)
-- Play exit sound
PlaySoundFrontend(-1, 'CANCEL', 'HUD_FREEMODE_SOUNDSET', true)
-- Track time in shop for analytics
local seconds = math.floor(data.timeSpentInShop / 1000)
print(('[SHOP] Player spent %d seconds in %s, viewed %d items'):format(
seconds, data.shopName, data.itemsViewed
))
-- Warn about abandoned cart
if data.cartItemCount > 0 and not data.didPurchase then
print(('[SHOP] Player left %d items in cart'):format(data.cartItemCount))
end
end)Last updated