# Parties

## Party Data

Party data is stored in a GlobalState which can be accessed from any script server or client. Each party is identified via a unique partyId.\
\
A player's current party id can be accessed via their state. If done locally, this can be done via LocalPlayer.state.party. This then can be used to access the party data via the following:

```lua
local partyId = LocalPlayer.state.party
local partyData = GlobalState["Party:" .. partyId]

print(partyData)

-- Output:
--{
--    members = { 1 = true, 2 = true }, --A list of sources that are apart of the party.
--    playerCount = 2, -- The amount of members in the party
--    maxPlayers = 4, -- Max allowed players in the party
--    type = "example", -- Type of the activity set in the creation
--    data = {} -- Data stored by the party
--}
```

If you'd like to access the same data via the server, you an use the state bags again.

```lua
local partyId = Player(source).state.party
```

## createActivityParty

This can be used to create a shareable activity and subsequent party data. Storing information like the host, activity type, members, invites and shared data. Once the activity has been created, the creator or "Host" is given a party radial menu option to invite leave the party.

```lua
-- source: player to remove (not required if called via event)
-- activityName: Name of the activity (shows on invite notifications)
-- activityType: Type of activity, used for script reference if required
-- maxPlayers: Max members allowed within the party (defaults to 4 if not set)
-- initialData: Inital data to be stored wihtin the party, used for script syncing (defaults to {} if not set)

TMC.Functions.TriggerServerEvent("parties:server:createActivityParty", activityName, activityType, maxPlayers, initialData)
```

Below is an example from the sanitation job

```lua
TMC.Functions.TriggerServerEvent('parties:server:createActivityParty', 'Garbage Runs', 'garbage', 4, {
    vehicle = netVeh,
    state = 'starting',
    zone = Config.Garbage.Zones[TMC.Common.TrueRandom(1, #Config.Garbage.Zones)],
    bins = {},
    completedRuns = 0
})
```

## inviteToParty

While this won't be used often due to the radial menu option, it can be handy to forcibly invite members&#x20;

```lua
-- source: player to remove (not required if called via event)
-- targetId: Target to add into the party.

TMC.Functions.TriggerServerEvent("parties:server:inviteToParty", targetId)
```

## removePlayerFromParty

Forcibly remove a player from a party.

```lua
-- source: player to remove (not required if called via event)
-- partyId: Id of party to remove from

TMC.Functions.TriggerServerEvent("parties:server:removePlayerFromParty", partyId)
```

## endActivityParty

End the party activity

```lua
-- source: player linked to the party (not required if called via event)
-- partyId: Id of party to remove from

TMC.Functions.TriggerServerEvent("parties:server:endActivityParty", partyId)
```

## setPartyData

Update data connected to the party's global state.

```lua
-- partyId: party id to apply the data to (not required if called via event)
-- dataKey: key within the party's data strucutre to set the data
-- dataValue: value which will be placed at the dataKey within the party data

TMC.Functions.TriggerServerEvent("parties:server:setPartyData", dataKey, dataValue)
```

## resetPartyData

{% hint style="info" %}
This can only be called via exports
{% endhint %}

Reset a parties data back to data provided.

```lua
-- partyId: party to target
-- initalData: data that should be forceibly updated to

exports.parties:resetPartyData(partyId, initalData)
```

## triggerPartyEvent

Triggers a client event for all players within the party and with supplied arguments

```lua
-- partyId: party to target (not required in server event)
-- event: event name to be triggered
-- arguments...: arguments

TMC.Functions.TriggerServerEvent("parties:server:triggerPartyEvent", event, argumnets...)
```

## triggerPartyNotif

Sends a notification to all the party members

{% hint style="info" %}
Reffer to `TMC.Functions.SimpleNotify` for argument options

This event does not support the duration argument.
{% endhint %}

```lua
-- partyId: party to target (not required in server event)
-- text: content for the notification
-- type: type of notification

TMC.Functions.TriggerServerEvent("parties:server:triggerPartyNotif", text, type)
```

## Dev Commands

### /fakeinvite

If you wish to test the invitation system, you can use this to force the invited status.

### /testparty

If you'd like to force yourself into a test party - default activity name "A test activity".


---

# 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://docs.tmc.bj/v2/other-resources/parties.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.
