# Adding a New Corner

## Adding a New Corner

This guide will walk you through modifying the configuration file to add a new corner. Follow the steps below to update your configuration and test your changes in-game.

***

### Prerequisites

* **Access to the File:** Ensure you have access to the file at `rm_illegalcorners/cfg.lua`.
* **Basic Understanding:** Familiarity with editing Lua files and using your script’s commands in-game.

***

### 1. Open the Configuration File

Locate and open the file:

```lua
rm_illegalcorners/cfg.lua
```

### 2. Understand the Configuration Tables

The configuration file contains two primary sections: the **Items Table** and the **Corners Table**.

#### Items Table

This table defines the items that can be selled at any corner. For example:

```lua
cfg.items = {
    ['bandage'] = {
        label = 'Bandage',
        unitPrice = { 1, 10 }, -- A random price between 1 and 10 will be selected.
        qty = { 1, 15 },       -- A random quantity between 1 and 15 will be selected.
        -- image = 'bandage.png', -- Defaults to 'itemname.png' if no image is provided.
    },
}
```

#### Corners Table

This table specifies the corner locations and the items available at each corner. Each corner includes a `zoneData` property that defines its active area.

### 3. Add Your New Corner

To add a new corner, simply append a new configuration object to the `cfg.corners` table. Below are examples for each zone type.

#### Example: Sphere Zone

```lua
{
    name = 'drug_corner',
    label = 'Drugs Corner',
    zoneData = {
        coords = vec3(201.62, -1020.74, 29.0),
        radius = 250,  -- Defines the active area as a sphere.
        -- debug = true, -- Uncomment to enable debugging.
    },
    items = { 'bandage' },
}
```

#### Example: Box Zone

```lua
{
    name = 'new_corner_box',
    label = 'New Corner Box',
    zoneData = {
        coords = vec3(100.0, 200.0, 300.0), -- Center coordinates of the box.
        size = vec3(100.0, 100.0, 50.0),      -- Dimensions of the box.
        -- debug = true, -- Uncomment to enable debugging.
    },
    items = { 'bandage' },
}
```

#### Example: Polygon Zone

```lua
{
    name = 'new_corner_poly',
    label = 'New Corner Polygon',
    zoneData = {
        points = {
            vec3(150.0, 250.0, 300.0),
            vec3(160.0, 260.0, 300.0),
            vec3(155.0, 270.0, 300.0),
        },
        thickness = 5,  -- Defines the thickness of the polygon zone.
        -- debug = true, -- Uncomment to enable debugging.
    },
    items = { 'bandage' },
}
```

Your final configuration might look like this:

```lua
cfg.disableCorners = false -- If set to true, items will appear on random peds with no location restrictions.

cfg.corners = {
    -- Sphere Zone Example
    {
        name = 'drug_corner',
        label = 'Drugs Corner',
        zoneData = {
            coords = vec3(201.62, -1020.74, 29.0),
            radius = 250,
            -- debug = true,
        },
        items = { 'bandage' },
    },
    -- Box Zone Example
    {
        name = 'new_corner_box',
        label = 'New Corner Box',
        zoneData = {
            coords = vec3(100.0, 200.0, 300.0),
            size = vec3(100.0, 100.0, 50.0),
            -- debug = true,
        },
        items = { 'bandage' },
    },
    -- Polygon Zone Example
    {
        name = 'new_corner_poly',
        label = 'New Corner Polygon',
        zoneData = {
            points = {
                vec3(150.0, 250.0, 300.0),
                vec3(160.0, 260.0, 300.0),
                vec3(155.0, 270.0, 300.0),
            },
            thickness = 5,
            -- debug = true,
        },
        items = { 'bandage' },
    },
}
```

### 4. Save and Restart

* **Save the File:** Save your changes to `cfg.lua`.
* **Restart the Script:** Restart your script or resource to load the new configuration.

### 5. Test Your New Corner

1. **Launch the Game:** Start the game and connect to your server.
2. **Navigate to Your Corner:** Head to the coordinates you specified for your new corner.
3. **Start Interaction:** Once you're in the zone, open the chat or console and type:

   ```
   /takecorner
   ```

### 6. Troubleshooting

* **Incorrect Zone Data:**\
  Verify that you are using the correct properties for each zone type:
  * **Polygon:** Use `points` and `thickness`.
  * **Box:** Use `coords` and `size`.
  * **Sphere:** Use `coords` and `radius`.
* **Coordinate Errors:**\
  Check that all coordinates, sizes, and radius values are correct.
* **Item Key Mistakes:**\
  Confirm that every item referenced in the `items` array exists in `cfg.items`.
* **Script Not Reloading:**\
  Ensure you have properly restarted the resource after making changes.

### Conclusion

By following these steps, you have successfully added a new corner using the updated zone configurations. Customize the items, zone types, and coordinates as needed to create a dynamic and flexible experience with your script.

Happy Scripting!
