Custom Logs

This guide is for custom logs that can be triggered from external scripts, please be aware that medium knowledge is required for this, if you don't have idea of what are you doing or have 0 experience in coding please hire a dev, I don't provide any assistance for this other than this guide.

  • Add the custom log in config/_config.lua inside the Config.Logs table, there's an example there, let's gonna use it:

value: needs to be an unique string value, you can't have multiple logs with the same value.

label: this is how the business boss will se it in his settings tab.

description: a short description so the boss can know what this does.

jobs: set this to false if you want all jobs can access it or set a table with jobs like the image above.

  • Go to server/editable/logs.lua and add a new function inside functions table:

Important: Every index key needs to match your log value and the function to trigger needs to be unique, for this example the function is named customLogs.

  • Go to the end of the file and create the new function, this function will receive 4 parameters:

webhook: This is the webhook the business boss added to receive this type of notifications.

source: Is the player who's triggering the log and is optional, is included just in case you need it for X reason.

job: The job you want to receive the notification. data: Is a table with all extra data that you want to send/receive in your log function.

  • For this example we are gonna simulate that we are triggering the export from av_tuning, when someone already paid for the modifications, so we are gonna add the export in the server file and function where we want to send the log, in this case for av_tuning we are adding it in server/framework/_framework.lua > ProcessPayment:

  • As you can see in the screenshot we are using the following code:

local data = {
    title = shop, -- the title for the webhook, we are using the shop name
    employeeName = exports['av_laptop']:getName(src), -- I want to get the employee name
    employeeIdentifier = exports['av_laptop']:getIdentifier(src), -- employee identifier
    customerIdentifier = exports['av_laptop']:getIdentifier(customer), -- customer identifier just in case
    total = total, -- the total paid for the modifications
    -- I could add more data here but for my example this is enough, u can add as many info as u want
}
-- Now we trigger the export 
-- exports['av_business']:sendLog(logName, source, jobName, data)
exports['av_business']:sendLog("custom_log", src, job.name, data)
  • The export needs the following args:

logName: The log value from Config.Logs table

source: The player source that is triggering the log or u can set nil if you want

jobName: The job to send the log

data: A table with all the data u want to send to your log function

  • Now back in av_business/server/editable/logs.lua we are gonna edit our custom function and format the description table using the info sent from our export, for me it will look like this:

  • As you can see we are using the content of data to create the fields that I want, Employee Name, Employee Identifier, Customer Identifier and Total, depending on your data content create the needed fields.

  • Now your log is ready to be used, the business owner needs to add his webhook in the Settings tab of the Business app to start receiving its notifications.

  • This is the webhook notification after the customer pays for the modifications

  • Important: If you feel like I'm missing something or a step isn't well explained DON'T OPEN A TICKET, use the support channel. Please only use the Discord ticket system for bug reports.

Last updated