Need help understanding Lua/Hashes when trying to code in c#

Good morning/evening. To preface, I did take time before to learn the basics of Lua, and have an ok grasp of the basics, but I don’t know some of the more “advanced” stuff I see in pre-written scripts.

I am trying to learn how to code/script for FiveM in C#, and from what research I’ve already done, it feels like an uphill battle as there’s almost no tutorials/documentation other than the official FiveM scripts that teach you how to spawn a car. I’ve watched a few video’s that ultimately showed how to give all guns. But it feels otherwise like there’s a drought of info for c#.

I decided to start somewhere simple, and try to recode an easy script that was already written in Lua. Point finger which I’ve used before and worked. it was a decent start, and took some time to understand what did what.

But I hit 2 brick walls which just comes from inexperience and was hoping someone could give me a decent explanation. The first is lines 92 to 97 which says:

 local blocked = 0
 local nn = 0

 local coords = GetOffsetFromEntityInWorldCoords(ped, (cosCamHeading * -0.2) - (sinCamHeading * (0.4 * camHeading + 0.3)), (sinCamHeading * -0.2) + (cosCamHeading * (0.4 * camHeading + 0.3)), 0.6)
 local ray = Cast_3dRayPointToPoint(coords.x, coords.y, coords.z - 0.2, coords.x, coords.y, coords.z + 0.2, 0.4, 95, ped, 7);
 nn,blocked,coords,coords = GetRaycastResult(ray)

I understand the first 2 locals, but I don’t understand what’s going on with line 97, cause “GetRaycastResult” wants 5 inputs. Is it taking “(ray)” as the first input, then “nn” as the 2nd, & so forth. I ask cause in c#, it first wants an int (from ray), then a bool, then 2 vector3’s, then another int. Right now I “think” I have it figured out as:

GetShapeTestResult(ray, ref nn, ref coords, ref coords, ref blocked);

But this treats blocked as an int, not a boolean.

Problem #2 is with Hashes.

Line 102 is:

Citizen.InvokeNative(0xB0A6CFD2C69C1088, ped, "isFirstPerson", Citizen.InvokeNative(0xEE778F8C7E1142E2, Citizen.InvokeNative(0x19CAFA3C87F7C2FF)) == 4)

I’ve learned I can use “Function.Call(Hash)hashcode” to use instead of the Citi Invoke Native, but this line just has me all over the place with the second half. I learned the B0A6C… is the hash for “SetTaskMoveNetworkSignalBool()” So I can call that.

But my problem is with the Hash that calls on another hash, cause hash #2 returns Void, which causes errors. with that portion, and I’m not sure how to code it. I stored it in a variable, and it is stored as an enum, and I even tested the code in both a Console.Write, as well as using breakpoints, to see there’a a # being stored in the hash, but my IDE is claiming it is void, and won’t build unless I fix it.

I would greatly appreciate this, as I want to get my feet wet coding in C#, and want to learn from mistakes. I know I could just code in Lua, but I want to climb this hill as a teaching moment.

If you want something else than void with then pass a T (type) Function.Call<bool>() however check first if the native isn’t already in the ‘API’ class

If you have a ref you need to define a variable with that type and pass it

1 Like

Right away, thank you for informing I can call return functions on the “Function.Call” …well, call.

I will look into that tonight, and see if that helps me out with issue #2 I’m having.