> For the complete documentation index, see [llms.txt](https://dwdev.gitbook.io/dwdevelopment/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dwdev.gitbook.io/dwdevelopment/mechanic-shops.md).

# Mechanic Shops

This script is not a mechanic script. You will need to setup a runtime mechanic creator. We have made a snippet for jg-mechanic already.

## Setting up jg-mechanic

1. Navigate to your jg-mechanic folder and create a folder named dw\_custom
2. Under dw\_custom, create a client.lua and a server.lua file
3. Copy the following into client.lua

```lua
CreateThread(function()
    local cachedShops = lib.callback.await("jg-mechanic:getAddedShops", false)
    for name, data in pairs(cachedShops) do 
        Config.MechanicLocations[name] = data
    end
    createMechanicZonesAndBlips()
end)

RegisterNetEvent("jg-mechanic:addNewShop", function(name, data)
    Config.MechanicLocations[name] = data
    createMechanicZonesAndBlips()
end)
```

4. Copy the following into server.lua

```lua
local cachedShops = {}

function AddMechanicShop(name, data)
    Config.MechanicLocations[name] = data
    local row = MySQL.single.await('SELECT * FROM `mechanic_data` WHERE `name` = ? LIMIT 1', {
        name
    })
    if not row then 
        MySQL.insert.await('INSERT INTO `mechanic_data` (name, label) VALUES (?, ?)', {
            name, data.locations[1].name or name
        })
    end
    TriggerClientEvent("jg-mechanic:client:refresh-mechanic-zones-and-blips", -1)
    TriggerClientEvent("jg-mechanic:addNewShop", -1, name, data)
    print("added mech shop " .. name)
    cachedShops[name] = data
end
exports("AddMechanicShop", AddMechanicShop)

lib.callback.register("jg-mechanic:getAddedShops", function(source)
    return cachedShops
end)
```

5. Update fxmanifest.lua to add&#x20;

   ```lua
    
    client_script "dw_custom/client.lua"
    server_script "dw_custom/server.lua"
   ```

This completes integration with jg-mechanic!

## I don't use jg-mechanic, what do I do?

If you read the above guide, you'll notice it's only really doing 2 things

1. Updating the config.lua on the server and broadcasting this change to all clients through an event, while storing updates in a cachedShops table
2. Updating the config.lua on the client when the event is received, or when the script starts through a callback retrieving the server data.

* jg-mechanic does require special updates to the database, but most scripts won't require this.

So, if you want to implement this yourself, you need to do the following:

#### Creating a payload

1. Navigate to dw\_businesscreator/bridge/server.lua CreateMechanicShop function
2. The payload contained within data is available for you there, modify it to fit the payload expected by your mechanic script.
3. Setup the export as&#x20;

   ```lua
           exports["yourmechanicscript"]:AddMechanicShop(businessName, data)
   ```

#### Creating the export

1. Follow steps 1, 2 and 5 from the jg-mechanic guide.
2. In the server.lua file, copy the following structure

```lua
local cachedShops = {}

function AddMechanicShop(name, data)
    Config.CHANGEME[name] = data
    TriggerClientEvent(GetCurrentResourceName() .. ":addNewShop", -1, name, data)
    print("added mech shop " .. name)
    cachedShops[name] = data
end
exports("AddMechanicShop", AddMechanicShop)

lib.callback.register(GetCurrentResourceName() .. ":getAddedShops", function(source)
    return cachedShops
end)
```

3. In the client.lua file, copy the following structure

```lua
CreateThread(function()
    local cachedShops = lib.callback.await(GetCurrentResourceName() .. ":getAddedShops", false)
    for name, data in pairs(cachedShops) do 
        Config.CHANGEME[name] = data
    end
end)

RegisterNetEvent(GetCurrentResourceName() .. ":addNewShop", function(name, data)
    Config.CHANGEME[name] = data
end)
```

Literally all you need to do here(most of the time) is change Config.CHANGEME to the actual config table name

Boom. Mechanic integration completed. Hopefully?

## That didn't work

If that didn't work, your mechanic script requires a bit more love. You can open a ticket either on the dwdevelopment Discord or the Mechanic Script Discord (hopefully they help?), and you should receive support.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dwdev.gitbook.io/dwdevelopment/mechanic-shops.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
