> For the complete documentation index, see [llms.txt](https://abpstudios.gitbook.io/abp-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abpstudios.gitbook.io/abp-docs/abp-missions/scripting-references/pmm-client-reference/game-rules.md).

# Game Rules

These rules will work permanently for the duration of the mission (it doesn't matter if you did it in the first stage, it will continue until the last one if you don't cancel them).

### **How's work**

The rules are as they describe the word, if the player breaks them, he can select his punishment, from finishing the mission or sending him a message to comply with it. (How to make a counter that if it ends you lose the mission)

## GameRules.VehicleCanNotBeDestroyed()

This function creates a thread that continuously checks if a specified vehicle still exists and has health greater than 0. If the vehicle is destroyed, the `onDestroy` function is called.

```lua
GM().GameRules.VehicleCanNotBeDestroyed(vehicle, onDestroy)
```

**Example**

```lua
local playerVehicle = GetVehiclePedIsIn(PlayerPedId())

GM().GameRules.VehicleCanNotBeDestroyed(playerVehicle, function()
    --- Boom!
    -- This functions acts when vehicle is destroyed.
    GM().EndGame(true, "Vehicle destroyed")
end)
```

## GameRules.PlayerMustBeInArea()

This rule states that the player MUST stay in the area.

## GameRules.PlayerMustBeInVehicle()

This rule states that the player MUST be stabilized in a vehicle and in a defined holding position.

## GameRules.PlayerInVehicleMustRespectSpeedLimit()

This rule is flexible, since it indicates that the player must respect an adequate speed, that is, he must not exceed it. (Taxi? Chase missions?)

## GameRules.CancelRule()

This function is used to cancel or remove a specific rule that has been previously set up using the ruleName. Different rule names correspond to different types of rules that can be canceled.

```lua
GM().GameRules.CancelRule(ruleId, params...)
```

**Example**

```lua
-- Cancel the "PlayerMustBeInArea" rule with the zoneId "missionArea"
GM().GameRules.CancelRule("PlayerMustBeInArea", "missionArea")

-- Cancel the "PlayerMustBeInVehicle" rule for a specific vehicle entity
GM().GameRules.CancelRule("PlayerMustBeInVehicle", vehicle)

-- Cancel the "PlayerInVehicleMustRespectSpeedLimit" rule
GM().GameRules.CancelRule("PlayerInVehicleMustRespectSpeedLimit")
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://abpstudios.gitbook.io/abp-docs/abp-missions/scripting-references/pmm-client-reference/game-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
