Zones
Areas on the map with enter and leave events.
A zone is a circle on the ground - a depot, a race checkpoint, a speed zone. Players driving in or out trigger playerEnterZone and playerLeaveZone. Positions are checked about once a second.
const depot = mp.zones.create({ name: "Depot", center: { x: 2815, y: 35, z: -7408 }, radius: 80 })
mp.events.on("playerEnterZone", (player, zone) => {
if (zone === depot) mp.chat.send(player, "Welcome to the depot - /repair is free here")
})
mp.events.on("playerLeaveZone", (player, zone) => {
if (zone === depot) mp.chat.send(player, "Drive safe!")
})/pos in the chat shows your own position - handy to find coordinates.
Options
center: the middle ({ x, y, z }, metres as inplayer.position).radius: metres on the ground.height(optional): metres aroundcenter.y, for bridges and multi-level places. Without it, height does not matter.name(optional): for your own use and the log.
Using zones
depot.players // players inside right now
depot.contains(position) // is a position inside?
depot.radius = 120 // move or resize at any time
depot.center = { x: 0, y: 0, z: 0 }
depot.remove() // players inside get playerLeaveZone
mp.zones.all() // every zone of the gamemode
mp.zones.at(player.position!) // the zones a position is inA player who leaves the server also gets playerLeaveZone for every zone they were in.