-
Notifications
You must be signed in to change notification settings - Fork 189
EntityZone
An EntityZone is created by invoking the EntityZone:Create() method, and passing in an entity (Ped, Vehicle, etc) and a table of options:
local vehicle = GetVehiclePedIsIn(PlayerPedId())
local entityZone = EntityZone:Create(vehicle, {
name="entity_zone",
debugPoly=false,
})
Reminder: @PolyZone/BoxZone.lua
and @PolyZone/EntityZone.lua
must be included in your __resource.lua or fxmanifest.lua, in that order
Note: EntityZones follow the position and rotation of the entity. EntityZones take all the same options as BoxZones, except minZ
and maxZ
, which are ignored in favor of useZ
, which you can read more about below.
Property | Type | Default | Required | Description |
---|---|---|---|---|
useZ | Boolean | false | false | You can't specify a minZ or maxZ for EntityZones. Instead, they will be automatically calculated if you set this option to true |
It may be useful to know when the entity associated with an EntityZone is damaged or is destroyed/dies, and do something with that info. The onEntityDamaged
helper can provide this information. onEntityDamaged
takes a callback function that is run anytime the entity associated with an EntityZone is damaged, and passes some additional information to the callback. It is used as follows:
entity_zone:onEntityDamaged(function(entityDied, attacker, weaponHash, isMelee)
-- Do stuff here!
-- You could destroy the zone when the entity is destroyed for example:
if entityDied then entity_zone:destroy() end
end)
Note: This is event-based and therefore does not run per-frame or at any regular interval. It will trigger the moment any damage to the entity occurs. This helper can only be used on EntityZones and will trigger an error if used on any other zone.