fivem icon indicating copy to clipboard operation
fivem copied to clipboard

fix(gamestate/rdr3): GET_ENTITY_MODEL for objects & animals

Open Korioz opened this issue 2 years ago • 3 comments

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)

Korioz avatar Jun 10 '23 15:06 Korioz