Jump to content
Sign in to follow this  

Integrating natives in ScriptHookDotNet


As well as the hundreds if not thousands of constructors, functions, etc. the LCPDFR API & ScriptHookDotNet resource provide; there are still some functions not integrated available through the use of natives, the same thing basically applies to LSPDFR though this is not directly targeted towards that game.

Calling a native through ScriptHookDotNet is as simple as using a function however the parameters are not checked since the natives aren't defined and are a string(it's a void constructor).


This allows us to work with native functions and drops to the following sub-functions:


Which then divides to the following:


Obviously the function one is the only one we care about for this tutorial which divides into those four functions. The top two are the next ones of concern. The top one, namely "Call", simply calls the function with the given parameters while the other one handles the returns of the type provided. The first "call" one would look like this in C#:

You can also for some natives get a return and therefore there is another syntax that handles returns of all types. As seen above there is a call<> function which works very similarily and calls the function however this one handles returns. If we want to check if the player's anim group is already cuffed we can do:

GTA.Native.Function.Call("SET_ANIM_GROUP_FOR_CHAR", LPlayer.LocalPlayer.Ped.GPed, "move_m@h_cuffed");
As you can probably guess this sets the walking style of the player to the cuffed one(assuming it's loaded into memory) using the function SET_ANIM_GROUP_FOR_CHAR with the parameters of the player's character and the string of the library. Again, the parameters are a void-type and aren't checked by the compiler obviously, so be careful you provide the correct parameters.
string result = GTA.Native.Function.Call<string>("GET_ANIM_GROUP_FROM_CHAR", Player.Character);
                        GTA.Native.Function.Call("SET_ANIM_GROUP_FOR_CHAR", Player.Character, "move_player");
                        Game.DisplayText("Walkstyle reverted.");
                        GTA.Native.Function.Call("SET_ANIM_GROUP_FOR_CHAR", Player.Character, "move_m@h_cuffed");
                        Game.DisplayText("Walkstyle changed.");

This will toggle the cuffed walkstyle with a walkstyle message at the left-top of the screen.

Sign in to follow this  

User Feedback

Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now