# :tent: Camp builder
Documentation relating to the kd_campbuilder.

:::: tabs
::: tab BUY
[Buy the script](https://jumpon-studios.com/redm/camp-builder)
:::

::: tab PREVIEW
<iframe width="560" height="315" src="https://www.youtube.com/embed/4tKYbyswJGQ?si=vmhF5oiiYUOn8RJp" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
:::
::::

## 1. Installation
kd_campbuilder works with RedEM:RP and VORP. Be sure you installed one of them before to use this script.

- Drag and drop the resource in your resources folder
  - kd_campbuilder
- Add this ensure in your server.cfg
  - `ensure kd_campbuilder`
- Edit the redemrp_inventory to allow kd_campbuilder to add items dynamically.

In redemrp_inventory > client > cl_main.lua add :
```lua
RegisterNetEvent("redemrp_inventory:UpdateItems")
AddEventHandler("redemrp_inventory:UpdateItems", function(_items)
    Config.Items = _items
end)

```

In redemrp_inventory > server > sv_main add : 
```lua
RegisterServerEvent("redemrp_inventory:CreateCustomItem")
AddEventHandler("redemrp_inventory:CreateCustomItem", function(name, data)
    local source = source
    Config.Items[name] = data
    TriggerClientEvent("redemrp_inventory:UpdateItems", source, Config.Items)
end)

```
- Create the table in database
```sql
CREATE TABLE IF NOT EXISTS `camps` (
  `id` int NOT NULL AUTO_INCREMENT,
  `identifier` varchar(50) NOT NULL,
  `characterid` int NOT NULL,
  `propsetModel` varchar(100) NOT NULL,
  `coordinates` varchar(100) NOT NULL,
  `lastrefresh` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
```
- Congratulation, the Camp builder script is ready to be use !
## 2. Usage
Go to the shop (maker in the map) to buy your camp. You will be able to preview them by pressed E.

To place your camp, use the item in your inventory. A preview of the camp will appears. You can rotate it with the mouse wheel . Press Enter to validate the location. 

A boxes will appears instead of your camp. Wait the countdown to have your camp. 

To remove your camp, use the command `/campunbuild` near than it. A countdown will be display again. Wait the end to take it with the command `/camptake` . The camp will be back in your inventory.

The configuration file is `config.lua` in the resource root. **Do not edit this file directly** as your changes may be lost during updates. Instead, use `overwriteConfig.lua` to store your customizations.

- **`config.lua`** - Default configuration maintained by developers. **Do not modify this file.**
- **`overwriteConfig.lua`** - This is where you place only the values you want to override.

### How to customize the configuration

1. Open `kd_campbuilder/overwriteConfig.lua`
2. Find the value you want to change in `config.lua` (e.g., `Config.language`)
3. Copy only that line into `overwriteConfig.lua`
4. Edit the copied value to your liking

The script loads `config.lua` first, then `overwriteConfig.lua` overwrites only the values you redefine. This ensures your customizations are preserved when updating the script.

`kd_campbuilder/config.lua`

```lua
Config = {}

Config.distanceSpawnPed = 50.0
Config.distanceOpenShop = 3.0
Config.distanceShowCamp = 50.0
Config.distanceShowTimer = 20.0

Config.keyOpenShop = 'INPUT_JUMP'
Config.blip = "blip_region_caravan"
Config.blipName = "Boutique de campement"
Config.menu = {}
Config.menu.title = 'Campement'
Config.menu.align = 'top-left'

Config.durationBuild = 10000
Config.durationUnbuild = 10000

Config.ptfx = {
  swap = {
    dict = "scr_dm_ftb",
    name = "scr_mp_chest_spawn_smoke",
    scale = 2.0
  }
}

Config.boxes = {
  small = {
    model = 'pg_mp_possecamp_tent_trader01x_b',
    sizeVegModifier = 1.0
  },
  medium = {
    model = 'pg_mp_possecamp_tent_trader03x_b',
    sizeVegModifier = 1.0
  },
  big = {
    model = 'pg_ls_soldier2_01x',
    sizeVegModifier = 1.0
  },
}

Config.shops = {
  {
    name = "shop1",
    ped = {
      netID = 0,
      entityID = 0,
      model = "A_M_M_RANCHER_01",
      coords = vector4(2738.53, -927.25, 42.22, 216.48)
    },
    preview = {
      spawn = vector4(2729.02,-930.6,43.24,210.75),
      distance = 5.0,
    }
  },
}

Config.items = {
  ['Camp'] = {
    {label = "Campement 1", item = "camp1", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_canvas_leanto04", sizeVegModifier = 5.0, size = "small", weight = 0.0},
    {label = "Campement 2", item = "camp2", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_plaid_lean01", sizeVegModifier = 5.0, size = "small", weight = 0.0},
    {label = "Campement 3", item = "camp3", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_plaid_lean02", sizeVegModifier = 5.0, size = "small", weight = 0.0},
    {label = "Campement 4", item = "camp4", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_sticks_tall", sizeVegModifier = 5.0, size = "small", weight = 0.0},
    {label = "Campement 5", item = "camp5", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_string_lean", sizeVegModifier = 2.0, size = "small", weight = 0.0},
    {label = "Campement 6", item = "camp6", price = 500, shops = {'shop1'}, propsetModel = "pg_ambcamp01x_tent_string_tarp", sizeVegModifier = 5.0, size = "small", weight = 0.0},
  },
  -- ['New category'] = {
  --   {label = "feu 1", price = 100, shops = {'shop1'}},
  --   {label = "feu 2", price = 200, shops = {'shop2'}}
  -- }
}
```

`kd_campbuilder/lang.lua`

```lua
Lang = {}

Lang['script_title'] = "Camp Builder"
Lang['open_shop'] = "Open the shop"
Lang['preview'] = "Preview"
Lang['close_preview'] = "Close preview"
Lang['buy'] = "Buy"
Lang['not_enough_money'] = "You don't have enough money"
Lang['buy_item_success'] = "Congratulation, you bought one %s"
Lang['rotate'] = "Rotate"
Lang['place'] = "Place"
Lang['cancel'] = "Cancel"
Lang['build_in_progress'] = "In construction"
Lang['unbuild_in_progress'] = "Unbuild"
Lang['too_far'] = "No camp near you"
Lang['not_owner'] = "You are not the owner of this camp"
Lang['not_able_unbuild'] = "You can't unbuild this camp"
Lang['not_take'] = "You can't take this camp"
Lang['close'] = "Close"
```
