# Missions

The script only includes a dummy mission used for testing where you can see the code to learn how it works.

* Missions config is located in **server/editable/missions.lua** to prevent any player from dumping the files and see the info.
* Config.Missions is the table with all available missions, the one included is just a test mission that only triggers the server event **'av\_gangs:testmission'** and nothing else.

## Adding Missions

* Use the following export server side to add a new mission:

```lua
local mission = {
    name = "test_robbery", -- an unique identifier, keep it simple
    label = "Test Robbery", -- shown in app as mission title
    price = 2500, -- number or false
    difficulty = 1, -- from 0 to 5
    cops = 0, -- min cops online to start mission
    level = 0, -- min gang level required
    image = "https://r2.fivemanage.com/QmVAYSlqeAlD4IxVbdvu5/laundromat.png",
    description = "A short description for your heist",
    isClient = false, -- true it will trigger "event" client side, false will trigger it server side
    event = "av_gangs:testmission", -- server event to trigger or false to use onTrigger function
    autoStarted = true, -- set the mission status to "started" as soon as it's activated
    canStart = function(playerId, gang)
      -- run your own server check and return true to allow player to start mission
      -- this function runs before any removeMoney or cops check
      return true
    end,
    onTrigger = function(playerId, gang) -- This is triggered server side and only available if event = false
      -- You can use this to trigger an export or event
      -- EXAMPLE
      --[[
        exports['my_heist_script']:StartHeist(playerId)
      ]]--
    end,
}
exports['av_gangs']:registerMission(mission)
```

* The following event will make the mission available/unavailable for everyone:

```lua
-- mission:string = the mission identifier
-- started:boolean = true or false, true will make it available
TriggerEvent('av_gangs:updateMission', "test_robbery", true)
```

<figure><img src="https://1688068901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9bCwnajAqpi3Viykb5Wi%2Fuploads%2FNwZzgaIMnOzUOUmcm6za%2Fimage.png?alt=media&#x26;token=d46e066a-67b4-4730-8f83-727857149ae1" alt=""><figcaption></figcaption></figure>

### Mission Crew

> You can enable this feature in `av_gangs/config/crew.lua > Config.UseCrew`
>
> There's a little panel where you can create a group (requires **av\_groups**), this panel only generates the group + handle invites, for a complete control of the group please check [groups](https://docs.av-scripts.com/laptop-pack-v3/groups "mention") page for a list of available exports you can use on your own resources.

* If using the **av\_gangs crew** make sure to always set **'av\_gangs'** as your resource in the **av\_groups exports**, example retrieving all crew members:

```lua
-- This will return a table with all crew members
local playerId = 1 -- player server id
local resourceName = 'av_gangs' -- resource name the group belongs to
local playerGroup = exports['av_groups']:getPlayerGroup(playerId, resourceName)
```
