Closed Alexr03 closed 6 months ago
Can't you use the actual named native now, rather than invoking? GetShapeTestResultIncludingMaterial
.
Otherwise pretty sure you'd need to pass pointer-args.
Thanks @thelindat, indeed if you want to return any pointer values from a raw Citizen.InvokeNative
call, you should pass pointer catching arguments. Here's an example:
local retval, hit, endCoords, surfaceNormal, materialHash, entityHit = Citizen.InvokeNative(GetHashKey("GET_SHAPE_TEST_RESULT_INCLUDING_MATERIAL") & 0xFFFFFFFF, shapeTest,
Citizen.PointerValueInt(), Citizen.PointerValueVector(), Citizen.PointerValueVector(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.ReturnResultAnyway())
Let me know if this code will work for you.
Ah perfect, yes the code above works, I had tried something similar but I was using ResultAs...()
instead of PointerValue...()
😭.
I did try with a named native before, and just tried again to make sure I wasn't going mad, the named native doesn't seem to work, its nil and doesn't resolve to a function.
I seem to be getting the following hash returned as the material everywhere: -1775485061. I'm trying to get the ground material and I've messed around with the coords and using offsets and other shapetests, the method I use, which works on FiveM is just returning that same hash everywhere in RedM. Does the native work differently here? Is there a different method of grabbing the ground material that I should be using?
@Alexr03 The declaration for this native is currently only available on Canary.
@Sojobo if your code works in FiveM, it doesn't mean it's going to work on RedM without any changes. This is a perfect example of that. -1775485061
is a hash of the "DEFAULT" material name, but Red Dead Redemption 2 now expects material names to have a suffix containing their internal index. For example, "DEFAULT" becomes "DEFAULT_0", "PROP_ROCK" becomes "PROP_ROCK_207", and so on.
I'm attaching a small script for you guys to test it out: https://pastebin.com/eqJk0Zhp
Thanks for the example code there @Disquse - I've tested it out and it actually showcases my issue pretty well, it looks like most of the world is actually just default material, the solution for my use-case is probably just checking to make sure that it is default and nothing else. I'm trying to do a farming script and I don't want players putting crops on roofs or other places that don't make sense. Looks like roads and buildings all have something other than default while fields are all default though so yeah, checking for default probably works for me, thanks again!
What happened?
When attempting to use the
GET_SHAPE_TEST_RESULT_INCLUDING_MATERIAL
native that was introduced in https://github.com/citizenfx/fivem/pull/1495 an error is thrown.Expected result
Shape test result returns normal data along with material hash
Reproduction steps
This should return the shape test result of the ground in front of you.
local retval, hit, endCoords, surfaceNormal, materialHash, entityHit = Citizen.InvokeNative(0x4301E10C, shapeTest)
print('GET_SHAPE_TEST_RESULT_INCLUDING_MATERIAL', retval, hit, endCoords, surfaceNormal, materialHash, entityHit)