# HRComserv

## Dependencies

* [HRLib](https://github.com/HRScripts/HRLib)
* [oxmysql](https://overextended.dev/oxmysql)
* [illenium-appearance](https://docs.illenium.dev/free-resources/illenium-appearance/intro/)/[skinchanger](https://github.com/esx-framework/esx_core/tree/main/\[core]/skinchanger)

## Installation

* Download and install all the [dependencies](#dependencies)
* Download [HRComserv](https://github.com/HRScripts/HRComserv)
* Move the dependencies and HRComserv to your resources folder
* Configure HRComserv from it's config.lua file
* Write this in your server.cfg file:\
  `start HRLib`\
  `start oxmysql`\
  `start HRComserv`
* Restart your server

## Preview

{% embed url="<https://www.youtube.com/watch?ab_channel=HRScriptsDevelopment&v=4hq8T-GZvPo>" %}

```lua
config.language = 'en'

config.tasksDuration = {
    hammerFix = 5000,
    sweeping = 5000,
    digging = 5000
}

config.taskButton = 'E'

config.restorePlayerItems = true

config.comservLocations = {
    {
        spawnCoords = vector3(1772.3788, 3797.0134, 33.9043),
        allowedDistance = 15.0,
        tasks = {
            {
                coords = vector4(1777.6198, 3795.4888, 33.9795, 600.0),
                type = 'hammerFix'
            },
            {
                coords = vector4(1777.0300, 3799.5671, 34.5231, 298.9253),
                type = 'sweeping'
            },
            {
                coords = vector4(1768.1304, 3805.5369, 34.1334, 48.5324),
                type = 'digging'
            }
        }
    },
    {
        spawnCoords = vector3(165.4393, -989.9612, 30.0857),
        allowedDistance = 25.0,
        tasks = {
            {
                coords = vector4(156.7134, -1007.0770, 29.5411, 160.8827),
                type = 'hammerFix'
            },
            {
                coords = vector4(163.5233, -1006.0145, 29.3967, 249.2508),
                type = 'sweeping'
            },
            {
                coords = vector4(178.7770, -997.6605, 29.2918, 251.4863),
                type = 'digging'
            }
        }
    }
}

config.comservClothes = { -- Each field's value is the cloth number
	tshirt_1 = 0,
	tshirt_2 = 0,
	torso_1 = 0,
	torso_2 = 0,
	decals_1 = 0,
	decals_2 = 0,
	arms = 0,
	pants_1 = 0,
	pants_2 = 0,
	shoes_1 = 0,
	shoes_2 = 0
}

config.disableInventory = true

config.tasksMarker = {
    type = 21,
    colour = {
        red = 255,
        green = 255,
        blue = 255
    },
    alpha = 255
}

config.finishComservPosition = vector3(422.9242, -979.4069, 30.7094)

config.restorePlayerItems = true -- Choose to restore the player's items/weapons after finishing it's tasks
```

## Features

Two commands used by the server's staff:\
/comserv \[id] \[tasksCount]\
/stopComserv \[id]

Random locations for doing tasks

Three types of tasks: hammering, sweeping and digging

Optimization

Clothes change, Items removal, Set inventory to busy

## Еxternal connections

### Server Exports

```lua
exports.HRComserv:comservPlayer(playerId, tasksCount)
```

```lua
exports.HRComserv:stopPlayerComserv(playerId)
```

### Player State Bag

```lua
-- Server side
local playerState = Player(playerId).state.hasComservTasks

-- ClientSide

local playerState = LocalPlayer.state.hasComservTasks
```

the player state bag "hasComservTasks" contains the following fields:

* tasksCount (integer): The count of remaining tasks
* skin (string): json encoded table of player's outfit
* playerItems (table\[]): an array full of player's items
* alreadyHave (boolean): a value that shows if the player joined the server but already have tasks to do and left before finishing them
