Good evening,
thank you very much for the quick answer, @nta!
I have not been idle in the meantime. First of all, my assumption that the chair I meant was not an original game prop was wrong. I just didn’t find its hash on pages listing available props. (gta-objects, gtahash)
Also, I noted the answer that it depends on whether a prop is a static object or an entity. So I did some tests.
For this, I used the following objects that were already present in an MLO:
-1608185467 = apa_mp_h_stn_chairstrip_07
1546354612 = v_ret_ps_chair
-470815620 = bkr_prop_biker_boardchair01
As already mentioned, we use qtarget. This resource provides function to get the objects in the player’s crosshairs with a raycast, the raycast() function.
The following is the code for the raycast() function:
local RaycastCamera = function(flag)
local cam = GetGameplayCamCoord()
local direction = GetGameplayCamRot()
direction = vec2(math.rad(direction.x), math.rad(direction.z))
local num = math.abs(math.cos(direction.x))
direction = vec3((-math.sin(direction.y) * num), (math.cos(direction.y) * num), math.sin(direction.x))
local destination = vec3(cam.x + direction.x * 30, cam.y + direction.y * 30, cam.z + direction.z * 30)
local rayHandle = StartShapeTestLosProbe(cam, destination, flag or -1, playerPed or PlayerPedId(), 0)
while true do
Wait(2)
local result, _, endCoords, _, materialHash, entityHit = GetShapeTestResultIncludingMaterial(rayHandle)
if result ~= 1 then
local entityType
if entityHit then entityType = GetEntityType(entityHit) end
return flag, endCoords, entityHit, entityType or 0
end
end
end
exports("raycast", RaycastCamera)
The complete code of qtarget can be found under the following link: GitHub - overextended/qtarget: Use ox_target instead.
For testing I used an ID-Gun, which uses the raycast() function and lists some data from the received entity.
Here is the code of the ID-Gun:
Citizen.CreateThread(function()
while true do
local pause = 0
if infoOn then
local player = PlayerPedId()
if IsPlayerFreeAiming(PlayerId()) then
local _,_,entity,_ = exports.qtarget:raycast()
local coords = GetEntityCoords(entity)
local heading = GetEntityHeading(entity)
local model = GetEntityModel(entity)
coordsText = coords
headingText = heading
modelText = model
entityText = entity
typeText = GetEntityType(entity)
nentityText = NetworkGetNetworkIdFromEntity(entity)
ownerText = NetworkGetEntityOwner(entity)
SendNUIMessage({
coords = model
})
end
DrawInfos("\nHash: " .. modelText .. "\nID: " .. entityText .. "\nNID: " .. nentityText .. "\nOwner: " .. ownerText .. "\nType: " .. typeText)
end
Citizen.Wait(pause)
end
end)
It’s important to note here that ID-Gun normally relied on GetEntityPlayerIsFreeAimingAt() to display the entity data for the entity the player is looking at. However, during the development process we decided to use the qtarget-raycast function for the ID-Gun, because GetEntityPlayerIsFreeAimingAt() did not return any entity data for some chairs and tables, after which, according to your answer, @nta, they are estimated to be static objects.
Here are the interior objects tested, with their definitions in the interior-ytype file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CMapTypes>
<extensions/>
<archetypes>
<Item type="CMloArchetypeDef">
<lodDist value="150.00000000"/>
<flags value="0"/>
<specialAttribute value="0"/>
<bbMin x="0.00000000" y="0.00000000" z="0.00000000"/>
<bbMax x="0.00000000" y="0.00000000" z="0.00000000"/>
<bsCentre x="0.00000000" y="0.00000000" z="0.00000000"/>
<bsRadius value="150.00000000"/>
<hdTextureDist value="50.00000000"/>
<name>int_taxi</name>
<textureDictionary/>
<clipDictionary/>
<drawableDictionary/>
<physicsDictionary>int_taxi</physicsDictionary>
<assetType>ASSET_TYPE_ASSETLESS</assetType>
<assetName>int_taxi</assetName>
<extensions/>
<mloFlags value="0"/>
<entities>
<Item type="CEntityDef">
<archetypeName>apa_mp_h_stn_chairstrip_07</archetypeName>
<flags value="32"/>
<guid value="0"/>
<position x="-1.43076900" y="16.23474000" z="-0.49271000"/>
<rotation x="0.00000000" y="0.00000000" z="-0.99998070" w="-0.00621864"/>
<scaleXY value="1.00000000"/>
<scaleZ value="1.00000000"/>
<parentIndex value="-1"/>
<lodDist value="500.00000000"/>
<childLodDist value="500.00000000"/>
<lodLevel>LODTYPES_DEPTH_HD</lodLevel>
<numChildren value="0"/>
<priorityLevel>PRI_REQUIRED</priorityLevel>
<extensions/>
<ambientOcclusionMultiplier value="255"/>
<artificialAmbientOcclusion value="255"/>
<tintValue value="0"/>
</Item>
<Item type="CEntityDef">
<archetypeName>v_ret_ps_chair</archetypeName>
<flags value="32"/>
<guid value="0"/>
<position x="-6.41844300" y="20.87214000" z="-0.49271000"/>
<rotation x="0.00000000" y="0.00000000" z="-0.98152120" w="0.19135360"/>
<scaleXY value="1.00000000"/>
<scaleZ value="1.00000000"/>
<parentIndex value="-1"/>
<lodDist value="500.00000000"/>
<childLodDist value="500.00000000"/>
<lodLevel>LODTYPES_DEPTH_HD</lodLevel>
<numChildren value="0"/>
<priorityLevel>PRI_REQUIRED</priorityLevel>
<extensions/>
<ambientOcclusionMultiplier value="255"/>
<artificialAmbientOcclusion value="255"/>
<tintValue value="0"/>
</Item>
<Item type="CEntityDef">
<archetypeName>bkr_prop_biker_boardchair01</archetypeName>
<flags value="32"/>
<guid value="0"/>
<position x="-0.29756710" y="26.37279000" z="0.11143000"/>
<rotation x="0.00000000" y="0.00000000" z="0.58834650" w="0.80860900"/>
<scaleXY value="1.00000000"/>
<scaleZ value="1.00000000"/>
<parentIndex value="-1"/>
<lodDist value="500.00000000"/>
<childLodDist value="500.00000000"/>
<lodLevel>LODTYPES_DEPTH_HD</lodLevel>
<numChildren value="0"/>
<priorityLevel>PRI_REQUIRED</priorityLevel>
<extensions/>
<ambientOcclusionMultiplier value="255"/>
<artificialAmbientOcclusion value="255"/>
<tintValue value="0"/>
</Item>
</entities>
<entitySets/>
<timeCycleModifiers/>
</Item>
</archetypes>
<name>int_taxi</name>
<dependencies/>
<compositeEntityTypes/>
</CMapTypes>
According to the XML-file now the pictures of the ID-gun outputs:

(Type 0 and therefor a static object?)

(Type 0 and therefor a static object?)

(Type 3 and therefor an entity?)
Why is it so important to me to get back entities with an entity type>0 for these chairs? qtarget checks if the type of an entity is>0 to avoid accidentally executing GetEntityModel() on a house or a house interior, which would crash the resource. And since qtarget needs to check which EntityModel is present to display appropriate interaction options, it is important for me to get this to run.
The following is an error that occurred because GetEntityModel was executed on an interior:
The most important question that arises at the end is what distinguishes an entity and a static object, and how to determine whether an object is an entity or a static object. Does this require definition in an MLO file, or setting specific metadata to objects in the game files?
If setting these values is not possible, which natives are recommended to achieve my goal?
Thank you very much and have a nice day!