Hooks

SD-Shops provides a comprehensive hook system that allows you to integrate with other resources and extend functionality. Hooks are triggered at specific events and pass relevant data to your callback functions.

Overview

There are two types of hooks:

  • Client Hooks - Triggered on the client-side for UI events, sounds, animations, and visual feedback

  • Server Hooks - Triggered on the server-side for logging, database operations, and cross-resource integrations

Registration

Client-Side Registration

-- From another resource
exports['sd-shops']:registerClientHook('hookName', function(data)
    -- Your logic here
end)

-- Returns a handlerId that can be used to unregister
local handlerId = exports['sd-shops']:registerClientHook('onShopOpened', function(data)
    print('Shop opened: ' .. data.shopName)
end)

-- Unregister when no longer needed
exports['sd-shops']:unregisterClientHook('onShopOpened', handlerId)

Server-Side Registration

Internal Registration

You can also register hooks directly within the client/hooks.lua or server/hooks.lua files:

Multiple Handlers

You can register multiple handlers for the same hook. All handlers will be called when the hook triggers:

Error Handling

Hooks are executed within pcall to prevent errors in one handler from affecting others. Errors are logged to the console with the hook name and handler ID.


Client Hooks

Hook
Description

onShopOpened

Player opens a shop UI

onShopClosed

Player closes a shop UI

onShopAccessDenied

Shop access denied (banned)

onPurchaseCompleted

Purchase completed successfully

onPurchaseFailed

Purchase failed

onCouponApplied

Coupon applied to cart

onCouponValidationFailed

Coupon validation failed

onLoyaltyRewardClaimed

Loyalty reward claimed

onGiftPurchaseCompleted

Gift purchase completed

onGiftReceived

Gift received by player


Server Hooks

Hook
Description

onCustomerPurchase

Customer completes a purchase

onCustomerPurchaseForPlayer

Customer buys items for another player

onShopPurchased

Player purchases shop ownership

onShopOwnershipTransferred

Shop ownership transferred

onShopSold

Shop sold back to system

onEmployeeHired

Employee hired

onEmployeeFired

Employee fired

onEmployeePermissionsUpdated

Employee permissions changed

onStockOrdered

Stock order placed

onStockOrderCollected

Stock order collected

onStockTransferredToShop

Stock transferred to shop

onStockWithdrawnFromShop

Stock withdrawn from shop

onSocietyDeposit

Money deposited to society

onSocietyWithdrawal

Money withdrawn from society

onLoyaltyPointsEarned

Customer earns loyalty points

onLoyaltyRewardRedeemed

Loyalty reward redeemed

onCouponCreated

Coupon created

onCouponUsed

Coupon used in purchase

onCouponDeleted

Coupon deleted

onProductAdded

Product added to shop

onProductUpdated

Product details updated

onProductRemoved

Product removed from shop

onSaleCreated

Sale/promotion created

onSaleStatusChanged

Sale status toggled

onSaleDeleted

Sale deleted

onCustomerBanned

Customer banned from shop

onCustomerUnbanned

Customer unbanned

onUpgradePurchased

Shop upgrade purchased

onShopSettingsSaved

Shop settings saved

onLoyaltySettingsSaved

Loyalty settings saved

Last updated