> For the complete documentation index, see [llms.txt](https://titans-productions.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://titans-productions.gitbook.io/documentation/redm/scripts/farming/development-api/client.md).

# Client

### Events

1. Returns true if player does any kind of action and false when stops doing any kind of action. This triggers only on actions.

```lua
RegisterNetEvent("tp_farming:client:isBusy")
AddEventHandler("tp_farming:client:isBusy", function(isBusy)
    -- todo your action
end)
```

### Exports

1. `@HasAttachedEntityBucket` Why using this export? This export can be used for scripts to prevent breaking the animation and the bucket attachment if the players are breaking it in purpose or when having river scripts and both are interacting to each other.\
   \
   Returns nil if there is no Attached Bucket, otherwise it will return the Entity (Client).

```lua
--- @param attachedEntityBucket - returns a string value
exports.tp_farming:HasAttachedEntityBucket()
```

2. `@IsBusy` Returns true if the player does any action related to anything.

```lua
--- @param isBusy - return a boolean value (true / false)
local isBusy = exports.tp_farming:IsBusy() 
```

### Events

1. The specified event below `tp_farming:client:plantedPlantType` is used mostly by server owners / developers for adding level experience on their scripts once a plant is placed.

```lua

--- @param plantId - returns an integer
--- @param plantType - returns a string
--- @param location - returns a table form
RegisterNetEvent("tp_farming:client:plantedPlantType") -- this is a client event
AddEventHandler("tp_farming:client:plantedPlantType", function(plantId, plantType, location)
    -- todo nothing
end)
```

2. How to use / register specific water wagons from stable script to ours\
   \
   Use the following event on your stable script for registering the wagon properly for receiving or updating the data related to the water capacity. This event is triggered only once and must be triggered when spawning the vehicle. The water capacity must be added on the wagons database and be taken / loaded when spawning the vehicle in order to load it properly through the trigger event.

```lua
--- @param networkId : requires the networked id of the spawned vehicle (wagon)
--- @param model : requires the model name (not hash)
--- @param water_capacity : requires the water capacity from the sql or any place you are able to receive it.
--- @param id : required the id of the vehicle from the sql  or any place you are able to receive it.
TriggerServerEvent("tp_farming:updateWagonByNetworkId", networkId, 'REGISTER', { model, water_capacity, id }) -- client > server
```

This is the code it is used on tpz\_stables for registering a wagon:

<img src="https://github.com/user-attachments/assets/70f4b621-cde1-4abb-b18b-376702b69bc9" alt="image" height="74" width="719">

```lua
if Config.tp_farming.Enabled then

    -- we check before registering if the spawned vehicle is a model that is listed on tp_farming for carrying water capacity.
    for _, _wagon in pairs (Config.tp_farming.WagonModels) do 

        if WagonData.model == _wagon then

            TriggerServerEvent("tp_farming:updateWagonByNetworkId", network, 'REGISTER', { WagonData.model, WagonData.water_capacity, WagonData.id })
            break 
        end

    end

end
```

For more understanding of the code: <https://github.com/TPZ-CORE/tpz\\_stables/blob/main/tpz\\_stables/client/tp-client\\_wagons.lua> (line 579)

After registering properly, the only thing is left is editing `tp_farming/server/tp-server_escrow_allow.lua` file on `UpdateWagonWaterCapacity` function (this is what we also use for tpz\_stables).

```lua
/*
    ~ TIP ~

    In case you don't have a wagon_id, you can check through database the model and get from the source the identifier and character identifier
    and update that wagon

    Example: update wagons set capacity where identifier = identifier and charidentifier = charidentifier and model = model.

    (!) Keep in mind, this is a poor way to do it because this wagon might be from someone else player and not his own - if this is the case, it won't work.
*/

-- @param model    : returns the wagon model name.
-- @param wagon_id : returns the registered wagon id from your stable script, if not registered, it will return as 0.
-- @param capacity : returns the updated capacity of the water.

UpdateWagonWaterCapacity = function(source, model, wagon_id, capacity)
    wagon_id = tonumber(wagon_id)
    exports.ghmattimysql:execute("UPDATE `wagons` SET `water_capacity` = @water_capacity WHERE `id` = @id ", { ['id'] = wagon_id,  ['water_capacity'] = capacity })
end
```
