materialHash returns 0

Hey, as I said in the title, when I call this function GetShapeTestResultIncludingMaterial() the value for materialHash returns 0
the code can be seen bellow, would anyone know why this would be the case and would know how to fix this?

local ped = GetPlayerPed(source)
GetGroundHash(ped)

function GetGroundHash(ped)
    print(ped)
    local posped = GetEntityCoords(ped)
    local num = StartShapeTestCapsule(posped.x,posped.y,posped.z+4,posped.x,posped.y,posped.z-2.0, 2, 1, ped, 7)
    print(num)
    local arg1, arg2, arg3, arg4, arg5, arg6 = GetShapeTestResultIncludingMaterial(num)
    print(arg5)
end

From the native reference:

When used with an asynchronous shape test, this native should be looped until returning 0 or 2, after which the handle is invalidated.

local ped = GetPlayerPed(source)
GetGroundHash(ped)

function GetGroundHash(ped)
    print(ped)
    local posped = GetEntityCoords(ped)
    local num = StartShapeTestCapsule(posped.x,posped.y,posped.z+4,posped.x,posped.y,posped.z-2.0, 2, 1, ped, 7)
    print(num)
    local arg1, arg2, arg3, arg4, arg5, arg6
    while (arg1 ~= 0 and arg1 ~= 2) do
        arg1, arg2, arg3, arg4, arg5, arg6 = GetShapeTestResultIncludingMaterial(num)
    end
    print(arg5)
end

I think this is a step in the right direction however arg1 won’t ever have 2 values right? So the while loop needs to have OR instead of AND?

Also it still returns zero, I think it the handle is invalid

0 if the handle is invalid, 1 if the shape test is still pending, or 2 if the shape test has completed, and the handle should be invalidated.

But that seems to be unlikely since thats the one thing it returns value for as shown in the screen

image

Yea, my bad. Should have been an or or just while (arg1 == 1) do. Also I forgot a Wait(0) in the loop.

When I added the code bit I didn’t really pay attention to what you were doing above the function. You are using GetPlayerPed(source). Are you sure you are accessing the correct player ped and not something else? Use PlayerPedId() instead if you want the current clients player ped.

Also I personally never used the capsule test. Have you tried it with the normal LoS one? (StartShapeTestLosProbe - FiveM Natives @ Cfx.re Docs)

1 Like

PlayerPedId for sure did something.
I also changed the code to this

function GetGroundHash(ped)
    print(ped)
    local posped = GetEntityCoords(ped)
    local num = StartExpensiveSynchronousShapeTestLosProbe(posped.x,posped.y,posped.z+4,posped.x,posped.y,posped.z-2.0, 1, ped, 7)
    print(num)

    local arg1, arg2, arg3, arg4, arg5, arg6 = GetShapeTestResultIncludingMaterial(num)
    print(arg5)
end

And now I am getting the value
image

Do you by any chance know if there is a list of materialhashes I could select the ones I want from?

I also use this function in my scripts as I actually need the inline result (my script doesn’t allow waiting for the ShapeTest to complete as it would break some parts). It takes more performance though. If you can avoid using it, I suggest doing so.

I do not know of a list. I know you can find one using OpenIV that basically has a list for their respective collisions (e.g. metal on concrete etc). But not the one you are looking for. At least I couldn’t find one.

We started making one but scrapped it pretty fast as it turns out that some things share the same material. E.g. we were at the beach and got the material hash for sand and then just went from there. Aaaaand turns out a metal door had the same hash. This happened for a few other things as well and then we just scrapped the entire thing.

1 Like

I will look into it, well thanks for the help.

1 Like