# Server Exports

### GetProperty

Returns full data of a property by its ID.

```lua
---@param {propertyId: number | string}: Property ID
---@return {propertyData: table | nil}
local propertyData = exports['vms_housing']:GetProperty(propertyId)
```

***

### GetAllProperties

Returns full list of a properties.

```lua
local properties = exports['vms_housing']:GetAllProperties()
```

***

### GetPlayerProperties

Returns a list of all properties owned / rented by the specified player.

```lua
---@param {identifier: number | string}: Player Server ID or Player Identifier
---@return {properties: table}: Data list of all properties
local properties = exports['vms_housing']:GetPlayerProperties(identifier)
```

<details>

<summary><strong>Example</strong></summary>

```lua
local properties = exports['vms_housing']:GetPlayerProperties(1)

print(json.encode(properties, {indent=true}))
--[[
    {
        "id": 138,
        "name": "Paleto House",
        "description": "",
        "type": "shell",
        "owner_name": "Tony Blunt"
        "owner": "char3:11000014c8ce27b",
        "region": "Paleto Bay",
        "address": "Procopio Dr",
        "last_enter": 1751993299,
        "unpaidBills": 0,
        "bills": [
            {
                "details": "{\"electricityUsage\":0,\"rateInfo\":{\"electricity\":0.0115,\"internet\":80.0,\"water\":0.5},\"internet\":80,\"electricity\":0,\"waterUsage\":0,\"water\":0.0}",
                "type": "services",
                "paid": false,
                "period": "07:2025",
                "id": 334,
                "house_id": 138,
                "total": 80
            }
        ],
        "permissions": [],
        "keys": "[\"138-9008CEA257\",\"138-9361DPW426\"]",
        "sale": {
            "active": false,
            "defaultActive": true,
            "defaultPrice": 1500000,
            "price": 1500000
        },
        "rental": {
            "active": false,
            "defaultActive": false,
            "defaultPrice": 0,
            "price": 0
        },
        "metadata": {
            "exit": {
                "w": 47.32084655761719,
                "x": -213.5472,
                "y": 6396.1655,
                "z": 32.1852
            },
            "lightState": false,
            "enter": {
                "x": -213.4049,
                "y": 6395.9585,
                "z": 33.7235
            },
            "allowFurnitureInside": true,
            "deliveryType": "outside",
            "lastCadastralPeriod": "07:2025",
            "zone": {
                "maxZ": 41.33707237243652,
                "area": 1148,
                "minZ": 25.33707237243652,
                "points": [
                    {
                        "y": 6362.8569,
                        "x": -192.8159
                    },
                    {
                        "y": 6378.2285,
                        "x": -177.2231
                    },
                    {
                        "y": 6388.0571,
                        "x": -186.8981
                    },
                    {
                        "y": 6389.7969,
                        "x": -185.0591
                    },
                    {
                        "y": 6408.2832,
                        "x": -204.0579
                    },
                    {
                        "y": 6415.0508,
                        "x": -207.3751
                    },
                    {
                        "y": 6415.5547,
                        "x": -207.3833
                    },
                    {
                        "y": 6398.7544,
                        "x": -227.5731
                    }
                ]
            },
            "upgrades": {
                "furnitureLimit": "1"
            },
            "locked": false,
            "allowFurnitureOutside": true,
            "garage": {
                "w": 46.99999618530273,
                "x": -197.7123,
                "y": 6397.5713,
                "z": 30.8626
            },
            "delivery": {
                "w": 130.0,
                "x": -216.7046,
                "y": 6394.7998,
                "z": 32.0852
            },
            "shell": "envi_shell_02_empty"
        },
        "creator": "char3:11000014c8ce27b",
        "furniture": [
            {
                "position": {
                    "pitch": 0.0,
                    "y": -3.47876214981079,
                    "z": 502.9772644042969,
                    "yaw": 0.0,
                    "x": -2.18221616744995,
                    "roll": -0.0,
                    "environment": "inside"
                },
                "stored": 0,
                "model": "prop_wall_light_06a",
                "id": 640,
                "metadata": [],
                "house_id": 138
            },
        ],
    },
]]
```

</details>

***

### GetPlayerCurrentProperty

Returns the ID of the property the player is currently inside (or `nil`).

```lua
---@param {src: number}: Player Server ID
---@return {propertyId: string}
local propertyId = exports['vms_housing']:GetPlayerCurrentProperty(src)
```

***

### IsPlayerInProperty

Returns `true` if the player is inside any property.

```lua
---@param {src: number}: Player Server ID
---@param {propertyId: number | string}
---@return {isInProperty: boolean}
local isInProperty = exports['vms_housing']:IsPlayerInProperty(src, propertyId)
```

***

### HasKeys

Returns `true` if the player has keys to the specified property.

```lua
---@param {src: number}: Player Server ID
---@param {identifier: string}: Player Identifier (e.g. 'char1:1100113jadckz')
---@param {propertyId: number | string}
---@param {keyId: string} (Optional)
---@return {hasKeys: boolean}
local hasKeys = exports['vms_housing']:HasKeys(src, identifier, propertyId, keyId)
```

***

### GenerateKeySerialNumber

Generates a unique serial number for a key for the given property.

```lua
---@param {propertyId: number | string}
---@return {serialNumber: boolean}
local serialNumber = exports['vms_housing']:GenerateKeySerialNumber(propertyId)
```

***

### HasPermissions

Returns `true` if the player has the specified permission for a property.

```lua
---@param {propertyId: number | string}
---@param {identifier: string}: Player Identifier (e.g. 'char1:1100113jadckz')
---@param {permission: string}
---@return {hasPermissions: boolean}
local hasPermissions = exports['vms_housing']:HasPermissions(propertyId, identifier, permission)
```

<details>

<summary>Explanation</summary>

List of available permissions:

* garage
* furniture
* billPayments
* keysManage
* upgradesManage
* marketplaceManage
* sell
* automaticSell
* rent
* rentersManage

</details>

***

### HasAnyPermission

Returns `true` if the player has any kind of permission for that property.

```lua
---@param {propertyId: number | string}
---@param {identifier: string}: Player Identifier (e.g. 'char1:1100113jadckz')
---@return {hasAnyPermissions: boolean}
local hasAnyPermissions = exports['vms_housing']:HasAnyPermission(propertyId, identifier)
```

***

### EnterProperty

Enter the property (used for admin tools or dev cleanup).

```lua
---@param {src: number}: Player Server ID
---@param {propertyId: number | string}
exports['vms_housing']:EnterProperty(src, propertyId)
```

***

### GiveProperty

Give the property to a player or company

```lua
---@param {identifier: number | string}: Player Server ID / Identifier or CitizenID / Agency Name
---@param {propertyId: number | string}: Property ID
exports['vms_housing']:GiveProperty(identifier, propertyId)
```

***

### DeleteProperty

Deletes the property (used for admin tools or dev cleanup).

```lua
---@param {propertyId: number | string}: Property ID
exports['vms_housing']:DeleteProperty(propertyId)
```

***

### CreateDirtAtCoords

Creating dirt for the house.

You can use this in your eating / drinking system when a player eats, they may leave a stain or crumbs.

```lua
---@param {propertyId: number | string}: Property ID
---@param {model: string}: Dirt object model from VMS Housing files
---@param {position: vector3}
---@param {heading: number}
exports['vms_housing']:CreateDirtAtCoords(propertyId, model, position, heading)
```

<details>

<summary>Dirt Models</summary>

<kbd>vms\_blood1</kbd>\ <kbd>vms\_blood1small</kbd>\ <kbd>vms\_blood2</kbd>\ <kbd>vms\_blood2small</kbd>\ <kbd>vms\_dirtfootsteps</kbd>\ <kbd>vms\_coffeestain1</kbd>\ <kbd>vms\_coffeestain2</kbd>\ <kbd>vms\_crumbs1</kbd>\ <kbd>vms\_crumbs2</kbd>\ <kbd>vms\_dirtmud1</kbd>\ <kbd>vms\_dirtmud2</kbd>\ <kbd>vms\_dirtmud3</kbd>\ <kbd>vms\_dirtmud4</kbd>\ <kbd>vms\_ketchupspill</kbd>\ <kbd>vms\_liquidspill1</kbd>\ <kbd>vms\_liquidspill2</kbd>\ <kbd>vms\_liquidspill3</kbd>\ <kbd>vms\_liquidspill4</kbd>\ <kbd>vms\_mustardspill</kbd>\ <kbd>vms\_oilspill1</kbd>\ <kbd>vms\_oilspill2</kbd>\ <kbd>vms\_sodaspill1</kbd>\ <kbd>vms\_winestain1</kbd>

</details>

<details>

<summary><strong>Example</strong></summary>

```lua
local myPed = GetPlayerPed(src)
local myCoords = GetEntityCoords(myPed)
local heading = GetEntityHeading(myPed)

local propertyId = exports['vms_housing']:GetPlayerCurrentProperty(src)
if not propertyId then
    return
end

local model = 'vms_crumbs1'
local position = vector3(myCoords.x, myCoords.y, myCoords.z - 0.99) -- Setting foot coordinates

exports['vms_housing']:CreateDirtAtCoords(propertyId, model, position, heading)
```

</details>

***

### DropPlayerFromProperty

Kick a player out of the property immediately without screen fade-in/fade-out

```lua
---@param {src: number}: Player Server ID
exports['vms_housing']:DropPlayerFromProperty(src)
```

***

### WipeProperty

Resets or partially clears a property depending on ownership state.

```lua
---@param {propertyId: number | string}: Property ID
---@param {removeOwnership: boolean}: If true, owner/renter may be removed depending on logic
---@param {identifier: string | nil}: Identifier / CitizenID / Agency Name
exports['vms_housing']:WipeProperty(propertyId, removeOwnership, identifier)
```

<details>

<summary>Explanation</summary>

This function may perform either a **partial reset** or a **full reset** depending on the ownership relationship.

* If `identifier` is **nil**, full reset is allowed (admin/system usage).
* If `identifier` belongs to the **owner** and there is no renter = full reset.
* If `identifier` belongs to the **owner** and renter exists = only owner is removed.
* If `identifier` belongs to the **renter** and no owner exists = full reset.
* If `identifier` belongs to the **renter** and owner exists = only renter is removed.

**Full Reset**

A full reset restores the property to its **default configuration defined in Housing Creator before being purchased by a player**.

Full reset includes:

* All furniture removed (database + memory)
* All property bills removed
* Unpaid bills counters cleared
* Keys cleared
* Permissions cleared
* Grass state cleared
* Metadata reset (locked state, lights, upgrades, dirt, alarm phone number, doors locked)
* Last enter timestamp removed
* Sale price restored to default value
* Rental price restored to default value
* Sale/rental active state restored to default (property returns to market if configured so)

</details>

***

### ResetPlayerProperties

Resets all properties associated with a given identifier.

{% hint style="info" %}
This function is primarily intended for character lifecycle management, such as Character Kill (CK), permanent character deletion, or player bans with asset removal.

It ensures that all properties linked to the character are safely restored to their default Housing Creator configuration.
{% endhint %}

```lua
---@param {identifier: string}: Identifier / CitizenID / Agency Name
exports['vms_housing']:ResetPlayerProperties(identifier)
```

<details>

<summary>Explanation</summary>

* Finds all properties owned or rented by the provided identifier.
* Internally calls `WipeProperty` for each property.
* Ownership logic is handled automatically.

</details>

***

### AddStarterApartment

Gives a player a predefined starter apartment (e.g. at character creation).

```lua
---@param {identifier: string}: Player Identifier (e.g. 'char1:1100113jadckz')
exports['vms_housing']:AddStarterApartment(identifier)
```

<details>

<summary>Explanation</summary>

Read the [How to use Starter Apartments](https://docs.vames-store.com/assets/vms_housing/guides/how-to-use-starter-apartments) guide if you want to know how to properly implement this feature on your server.

</details>

***

### TeleportToStartingApartment

Teleport the player directly to the property.

{% hint style="info" %}
It works only once, after the Starting Apartment has previously been granted.\
[**Example Integration**](https://docs.vames-store.com/assets/vms_housing/guides/how-to-use-starter-apartments)
{% endhint %}

```lua
---@param {src: number}: Player Server ID
exports['vms_housing']:TeleportToStartingApartment(src)
```

***

### RegisterHook

```lua
--- ### Available Hook Names:
--- OnPropertyCreate - Fired when a new property is created.
--- OnPropertyEdit - Fired when a property is edited.
--- OnPropertyDelete - Fired when a property is deleted.
--- OnPermissionUpdate - Fired when property permissions are updated.
--- OnOwnerChange - Fired when the owner of the property changes.
--- OnRenterChange - Fired when the renter of the property changes.

---@param name string The hook name (see list above)
---@param cb fun(data: table) Callback function triggered when the hook fires
exports['vms_housing']:RegisterHook(name, function(data)
    print(json.encode(data, {indent = true}))
end)
```
