# Functions/Events

## server/editable-main.lua

The script relies on a configuration file for the following key settings:

* `Config.framework`: Specifies the framework being used (`"QB"` for QBCore).
* `Config.core`: Specifies the core object for the framework (e.g., `'qb-core'`).
* `Config.gangScript`: Defines the method to determine the player's gang affiliation. Possible values include:
  * `"DATABASE"`
  * `"RCORE"`
  * `"C8RE"`
  * `"AK47"`
  * `"T1GER"`
  * `"GUILLE"`
  * `"OTHER"`

***

### Event: `cutsom:getPlayerGang`

#### Description

This event is triggered to fetch the player's gang information based on the configured `Config.gangScript` method.

#### Methods

**1. Database Method (`"DATABASE"`)**

Fetches the player's gang affiliation from the database.

* **ESX:** Retrieves the identifier using `ESX.GetPlayerFromId`.
* **QBCore:** Retrieves the identifier using `QBCore.Functions.GetIdentifier`.
* **SQL Query:**

  ```sql
  SELECT g.name
  FROM gangs g
  INNER JOIN gangs_member gm ON g.id = gm.gangId
  WHERE gm.playerIdentifiers LIKE @ident
  ```

**2. RCORE Method (`"RCORE"`)**

Fetches the gang affiliation using the `rcore_gangs` export:

```lua
local gangData = exports['rcore_gangs']:GetPlayerGang(src)
```

**3. C8RE Method (`"C8RE"`)**

Fetches the gang affiliation using the `core_gangs` export:

```lua
local organization = exports.core_gangs:getOrganization(src)
```

**4. AK47 Method (`"AK47"`)**

Fetches the gang affiliation from the `ak47_gangmembers` database table:

* **SQL Query:**

  ```sql
  SELECT label
  FROM ak47_gangmembers
  WHERE identifier = @ident
  ```

**5. T1GER Method (`"T1GER"`)**

Fetches the gang affiliation using the `t1ger_gangsystem` export:

```lua
local organization = exports['t1ger_gangsystem']:GetPlayerGang(src)
```

**6. GUILLE Method (`"GUILLE"`)**

Fetches the gang affiliation from the `guille_gangsv2` database table:

* **SQL Query:**

  ```sql
  SELECT gang
  FROM guille_gangsv2
  WHERE JSON_SEARCH(members, 'one', @steam) IS NOT NULL
  ```

**7. Custom Method (`"OTHER"`)**

Allows the client to define a custom approach for fetching gang information. For example:

```lua
TriggerClientEvent('cutsom:sendPlayerGang', src, "ballas")
```

#### Default Case

If the specified method is unrecognized, a default value of `"none"` is sent to the client:

```lua
TriggerClientEvent('cutsom:sendPlayerGang', src, "none")
```

***

### Error Handling

* For database-related errors, the script logs the error and sends a default response to the client.

  ```lua
  print("Database query error: " .. tostring(error))
  TriggerClientEvent('cutsom:sendPlayerGang', src, "none")
  ```
* If no identifier is found, a default value is sent to the client.

***

### Example Usage

Trigger the `cutsom:getPlayerGang` event from the client-side script:

```lua
TriggerServerEvent('cutsom:getPlayerGang')

RegisterNetEvent('cutsom:sendPlayerGang')
AddEventHandler('cutsom:sendPlayerGang', function(gangName)
    print("Player's Gang: " .. gangName)
end)
```

***

### Notes

* Ensure the correct configuration in `Config.gangScript` to match the desired method.
* The database structure and export functions should align with the chosen method.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://enyo-scripts.gitbook.io/documentations/fivem-scripts/ai-gangs/functions-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
