Trade Module
In your wally.toml file, add this to your dependencies:
You have two solutions to import this module, depending if you wish to import the Controller or the Service on your own, or if you let the module give you the right code.
Configuration
A file called TradeModule.config.lua is to be created in ReplicatedStorage/Shared/Configs.
Explanation:
TradePromptCallback: This function is called whenever the player receive a trade request. If this callback returns true, the process continues, else, it is considered declined.
TradeAcceptedCallback: A function that's called whenever a trade is accepted.
TradeDeclinedCallback: A function that's called whenever a trade is declined.
Usage
Events
OnTradeRequest: Triggers when the player sends a trade request.
OnTradeRequestAccepted: Triggers when the player accepts a trade request.
OnTradeRequestDeclined: Triggers when the player declines a trade request.
OnTradeRequestCancelled: Trigger when a trade request is cancelled (Player leaving mid-trade for example).
OnTradeRequestCompleted: Triggers when the trade is valid and completed.
Methods
Client Side
Explanation
targetPlayer: The player to send the trade request to.
Client Side
For more modularity, in order to accept a request, your own callback function must be implemented into the config file.
TradePromptCallback will be automatically called whenever a trade request is received, and will continue the trade process if it returns "true".
Client Side
Explanation
sourcePlayer: The player to decline the trade request of.
Server Side
Explanation
sourcePlayer: One of the player of the trade.
targetPlayer: The other player of the trade.
Server Side
Explanation
trade: The trade you're attempting to add items to. (Obtained from TradeService:GetTrade)
player: The player that will receive the items.
item: The name of the item you're adding.
Server Side
To be called whenever you're sure items are all valid!
Explanation
sourcePlayer: One of the player of the trade.
targetPlayer: The other player of the trade.
Server Side
To be called whenever the trade is 100% complete!
Explanation
player1: One of the player of the trade.
player2: The other player of the trade.