Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Natives.CreateVehicle crashes with System.NullReferenceException

Featured Replies

Spoiler

I am creating a towtruck at a defined Vector3 point like this:
Vehicle callCar = new Vehicle("TOWTRUCK2", carSpawnPoint);
That works unreliable, because most of the times, the Towtruck spawns without the Hook-attachment:

 

image.png?width=1308&height=549

On Discord it was suggested that using a Native would result in spawn with the attachment.
(Why it should idk...)
The method i then tried to use was
// CREATE_VEHICLE
int /* Vehicle */ CreateVehicle(uint modelHash, float x, float y, float z, float heading, bool isNetwork, bool netMissionEntity);

Like this:
Vehicle callCar = NativeFunction.Natives.CreateVehicle<int>(
        NativeFunction.Natives.GetHashKey("TOWTRUCK2"),
        carSpawnPoint.X, carSpawnPoint.Y, carSpawnPoint.Z, 0f, false, false);

        
That fails:

==========================================================================================
 Unhandled exception occurred in console command "ForceDuty"
 Exception type: System.NullReferenceException
 Exception message: Object reference not set to an instance of an object.
 Stack trace: at System.Object.GetType()
    at Rage.Native.DynamicNativeFunction.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at CallSite.Target(Closure , CallSite , Object , Object , Single , Single , Single , Single , Boolean , Boolean )
at System.Dynamic.UpdateDelegates.UpdateAndExecute8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)

 

Do i need the actual HASH for Towtruck2, if so -Where can i find that?

OR
Is it not possible to define an object this way
Vehicle callCar = NativeFunction.Natives.CreateVehicle
That 'mix' of API methods..
A solution where the hook-attachment is forced-created, if it is missing, would also work fine

 

 

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

  • 2 weeks later...
  • Author

I am still struggling with this
I has been told to try to force a 'finished build' of the model. That should be done like


             Model MM = new Model("towtruck2");
             MM.LoadAndWait();

             Vehicle callCar = new Vehicle(MM, carSpawnPoint);

 

That still results in a towtruck without hook-attachment

Then back to Natives...
What i have is
             PoolHandle ph = new PoolHandle(
             NativeFunction.Natives.World.GetEntityByHandle(
             NativeFunction.Natives.CreateVehicle<uint>(
             Game.GetHashKey("towtruck2"), carSpawnPoint.X, carSpawnPoint.Y, carSpawnPoint.Z, 1f, false, false)));

It results in an exception
I am dead in the water here

 

 

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

  • Author

Swimming again, but only because i have had help from

@alexguirre on Discord.

The solution also has one of the strangest constructors i ever saw- One with no lefthand in the statement?!
-And usage of a RAGE method

public void LoadAndWait()

I did not knew.
But it is how this method is used in the constructor that is mindbogglingly for me

`new Model("towtruck2").LoadAndWait();`

Constructors instantiate an object. That object is the left-hand-side
Like

`Model m = new Model("towtruck2").LoadAndWait();

`
Eg statement has a *left-hand-side*, and it does NOT work!
`<can not convert void to Rage.Model>`

 

Model m = new Model("towtruck2");
MM.LoadAndWait();


That Builds, but evaluates to 00000000
The left-hand-empty statement evaluate to 0000c302
!
It get even more wooot, because the anonymous statement infront of *RAGE Vehicle*-creation syntax:

new Model("towtruck2").LoadAndWait();
Vehicle callCar = new Vehicle("towtruck2", carSpawnPoint);


Does ALSO spawn a towtruck2 WITH hook-attachment!
So Natives was not even needed. It was only needed to have that *wait-for-the-model-to-load* statement eg
LoadAndWait(); !
Wow..
That is going to be a lifesaver again, i am SURE
Lesson learned: Any issues with Model, make sure it has completely loaded

So what about the Natives
That has a rather complicated statement. It is necessary to use a PoolHandle and a cast to uint, furthermorethe statement with   loadAndWait() and no left-hand-side also need to be used again
  

PoolHandle ph = new PoolHandle(
                                            NativeFunction.Natives.CreateVehicle<uint>(
                                                Game.GetHashKey("towtruck2"),
                                                Game.LocalPlayer.Character.Position,
                                                1f, false, false));

furthermore the statement with loadAndWait() and no left-hand-side also need to be used again.
bOTTOMLINE:
Natives was not needed
Constructors can have no left-hand-side 🙃
 

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.