fivem
fivem copied to clipboard
fix(gamestate/rdr3): GET_ENTITY_MODEL for objects & animals
This fix will add support of GET_ENTITY_MODEL on objects and animals on rdr3.
Sample Lua code for testing:
CLIENT:
local function requestModel(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(0)
end
end
RegisterCommand('test_sv_get_model', function()
local pCoords = GetEntityCoords(PlayerPedId())
local tests = {}
do
local model = `p_binoculars01x` & 0xFFFFFFFF
requestModel(model)
local object = CreateObjectNoOffset(model, pCoords.x, pCoords.y, pCoords.z, true, false, true, true)
SetModelAsNoLongerNeeded(model)
tests.object = { netId = NetworkGetNetworkIdFromEntity(object), model = model }
end
do
local model = `a_c_alligator_01` & 0xFFFFFFFF
requestModel(model)
local animal = CreatePed(model, pCoords.x, pCoords.y, pCoords.z, 0.0, true, true)
SetRandomOutfitVariation(animal, 1)
tests.animal = { netId = NetworkGetNetworkIdFromEntity(animal), model = model }
end
Wait(1000) -- just in case for server awareness of entities
TriggerServerEvent('testEntitiesModel', tests)
end, false)
SERVER:
local function testEntityModel(test, testId)
local entity = NetworkGetEntityFromNetworkId(test.netId)
local model = GetEntityModel(entity) & 0xFFFFFFFF
local testMsg = 'TEST %s: %s (net id: %u, id: %u, client model: 0x%08X, server model: 0x%08X'
print(testMsg:format(testId, test.model == model and 'PASSED' or 'FAILED', test.netId, entity, test.model, model))
end
RegisterNetEvent('testEntitiesModel', function(tests)
testEntityModel(tests.animal, 'ANIMAL')
testEntityModel(tests.object, 'OBJECT')
end)