How to parse the result of GetPedNearbyPeds native in lua?

Is there a way to use GetPedNearbyPeds in lua scripts at all?

I parsed the results of GetShopPedComponent just fine like this:

    local blob = string.rep('\0\0\0\0\0\0\0\0', 9 + 16)
    if not Citizen.InvokeNative(0x74C0E2A57EC66760, hash, blob) then
        return nil
    end

    local lockHash = string.unpack('<i4', blob, 1)
    local hash = string.unpack('<i4', blob, 9)
    local locate = string.unpack('<i4', blob, 17)
    local drawable = string.unpack('<i4', blob, 25)
    local texture = string.unpack('<i4', blob, 33)
    local field5 = string.unpack('<i4', blob, 41)
    local component = string.unpack('<i4', blob, 49)
    local field7 = string.unpack('<i4', blob, 57)
    local field8 = string.unpack('<i4', blob, 65)
    local gxt = string.unpack('c64', blob, 73)

    return component, drawable, texture, gxt, field5, field7, field8

But that one was much easier since it was just numbers or strings. GetPedNearbyPeds according to usage example returns a struct containing array size and an array of int64_t (which I think is the ped IDs that I need).

Looking at the documentation of string.unpack, I see no way of getting an int array, so I’m guessing it’s not possible to use the same way.

I got no advise on GetPedNearbyPeds precisely, but GetAllPeds() exists server side that may be a good substitute? For nearby peds people usually use an iterator of FindFirstPed and so on (it’s all over Github)

1 Like