GET_ENTITY_FROM_STATE_BAG_NAME
Returns the entity handle for the specified state bag name.
Signature
Entity GET_ENTITY_FROM_STATE_BAG_NAME(char* bagName);Parameters
| Name | Type | Description |
|---|---|---|
bagName | char* | An internal state bag ID from the argument to a state bag change handler. |
Returns Entity — The entity handle or 0 if the state bag name did not refer to an entity, or the entity does not exist.
Description
Returns the entity handle for the specified state bag name. For use with ADD_STATE_BAG_CHANGE_HANDLER.
Usage
local retval = GetEntityFromStateBagName(bagName)
-- always works, by hash
local retval = Citizen.InvokeNative(0x4bdf1867, bagName, Citizen.ResultAsInteger())JavaScript and C#
const retval = GetEntityFromStateBagName(bagName);
// by hash
const retval = Citizen.invokeNative('0x4bdf1867', bagName, Citizen.returnResultAnyway(), Citizen.resultAsInteger());int retval = Function.Call<int>((Hash)0x4bdf1867, bagName);Examples
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)
})AddStateBagChangeHandler("blockTasks", nil, function(bagName, key, value)
local entity = GetEntityFromStateBagName(bagName)
-- Whoops, we don't have a valid entity!
if entity == 0 then return end
-- We don't want to freeze the entity position if the entity collision hasn't loaded yet
while not HasCollisionLoadedAroundEntity(entity) do
-- The entity went out of our scope before the collision loaded
if not DoesEntityExist(entity) then return end
Wait(250)
end
SetEntityInvincible(entity, value)
FreezeEntityPosition(entity, value)
TaskSetBlockingOfNonTemporaryEvents(entity, value)
end)Sources
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.