# :package: Movable chest
Documentation relating to the kd_coffre-deplacable.

:::: tabs
::: tab BUY
[Buy the script](https://jumpon-studios.com/fivem/movable-chest)
:::

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

## 1. Installation

kd_coffre-deplacable is a standalone script. So you don't need a specific framework to use it. It's also mean it works with all framework (Esx, QBCore, VRP, DRP, …).

- Drag and drop the resource in your resources folder
  - kd_coffre-deplacable
- Add this 4 ensures in your server.cfg
  - `ensure kd_coffre-deplacable`
- Run this SQL command on your database
```sql
CREATE TABLE IF NOT EXISTS `coffre_deplacable` (
  `autoinc_coffre` int NOT NULL AUTO_INCREMENT,
  `coords` text NOT NULL,
  `code` int NOT NULL,
  PRIMARY KEY (`autoinc_coffre`),
  KEY `autoinc_coffre` (`autoinc_coffre`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
```
- Congratulation, the Movable chest script is ready to be use !

## 2. Usage
Put the chest on the ground with the client event
```lua
TriggerEvent('AddChest')

```
Use the decoder device with the client event
```lua
TriggerEvent('DecodeChest')

```

## 3. Config.lua
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_coffre-deplacable/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_coffre-deplacable/config.lua`

```lua
------------ Command to test the script
------------ Remove for production

RegisterCommand('DecodeChest', function()
  TriggerEvent("Digicode:AffDecoder")
end)

RegisterCommand('AddChest', function()
  TriggerEvent("CoffreMove:Poser")
end)

---------------------------------

-----------------------------
-- PARAMETERS
-----------------------------

--Model of the box
ModelCaisse = GetHashKey('prop_box_wood05a')

--Size of zone to detect the chest
ZoneDetection = 0.2
--Distance to spawn the chest
distanceSpawn = 50

-- Function when the chest is closed
function CloseChest(ChestId)
  print('Chest closed')
end

-- Function when the chest is open
function OpenChest(ChestId)
  print('Chest opened '..ChestId)
end

-- Function when decoder is dead
function DeadDecoder()
  --Remove the current decoder Item
  --Five the dead decoder Item
end

-- Function when chest is placed
function LooseChest()
end
```

`kd_coffre-deplacable/lang.lua`

```lua
Lang = {}

Lang['target_message'] = "Target the chest with ~INPUT_AIM~";
Lang['hold_message'] = "Hold ~INPUT_AIM~ and press ~INPUT_CONTEXT~ to open it";
Lang['close_message'] = "Press ~INPUT_CONTEXT~ to close";
Lang['enter_code'] = "Release ~INPUT_AIM~ to enter the code";
Lang['decode_message'] = "Target the chest with ~INPUT_AIM~ ~n~Press ~INPUT_CELLPHONE_CANCEL~ to cancel";
Lang['error_decode'] = "The decoder has overheated";
Lang['code_found'] = "Here is the code : ~h~";
Lang['cancel_decode'] = "Press ~INPUT_CELLPHONE_CANCEL~ to store the decoder";
Lang['end_placement'] = "End of chest placement";
Lang['validate'] = "~g~Validate the position"
Lang['cancel'] = "~r~Cancel"
Lang['cancel_placement'] = "Cancelled placement"
Lang['enter_password'] = "Enter the password";
Lang['wrong_password'] = "Wrong password";
Lang['good_password'] = "Valid password";
Lang['Loading_object'] = "Loading object";
Lang['Rotate_object'] = "Rotate";
Lang['Validate_object'] = "Validate";
Lang['Cancel_object'] = "Cancel";
```
