GetEntityFromStateBagName
Docslocal retval = GetEntityFromStateBagName(bagName)Description
Returns the entity handle for the specified state bag name. For use with ADD_STATE_BAG_CHANGE_HANDLER.
Parameters
| Name | Type | Description |
|---|---|---|
bagName | char* | An internal state bag ID from the argument to a state bag change handler. |
Quick Snippet: Get Entity→ Entity
→ EntityUse this to obtain an entity handle from the player's aim or crosshair.
-- Get the entity the player is aiming at
local ped = PlayerPedId()
local hit, entity = GetEntityPlayerIsFreeAimingAt(PlayerId())
if hit and entity ~= 0 then
print("Entity: " .. entity)
print("Model: " .. GetEntityModel(entity))
print("Type: " .. GetEntityType(entity)) -- 1=Ped, 2=Vehicle, 3=Object
endReturns
EntityReturns an entity handle.
Examples
Official
AddStateBagChangeHandler("blockTasks", null, async (bagName, key, value /* boolean */) => {
let entity = GetEntityFromStateBagName(bagName);
// Whoops, we were don't have a valid entity!
if (entity === 0) return;
// We don't want to freeze the entity position if the entity collision hasn't loaded yet
while (!HasCollisionLoadedAroundEntity(entity)) {
// The entity went out of our scope before the collision loaded
if (!DoesEntityExist(entity)) return;
await Delay(250);
}
SetEntityInvincible(entity, value)
FreezeEntityPosition(entity, value)
TaskSetBlockingOfNonTemporaryEvents(entity, value)
})