Access memory in LUA to get vehicle RPM

Hi everyone,

I’m developing a speedometer (see below screenshot), I thought there was a native to get vehicle engine RPM, but no it doesn’t exist.
I then found that you should read the value directly in RAM, like ScriptHookDotNet (https://github.com/crosire/scripthookvdotnet/blob/dev_v3/source/scripting/Vehicle.cs#L775).
I haven’t found a way to do the same thing in lua, does anyone have a clue ?

Thank you !

hello , i did few gauge for the car aswell , and i got the same problem then you. with the CitizenFX.dll they made a function for getting the RPM but unfortunatly this one is not working (at least for me) , i hope they gonna fix it if they have the time for.

You could just determine the distance between xyz coords and measure speed the way a person would normally do it 0.0

First of all, thank you for your answers !

I suspected the solution would not be in LUA … I had hoped someone knew how to access the RAM in lua to reproduce the ScriptHook .NET function … Now hope someone can fix the CitizenFX.dll function :slight_smile:

I think you did not quite understand my problem (or I misunderstood your answer). I get to get the vehicle speed (the right gauge) with the GetEntitySpeed function in LUA and convert it to mph or km/h. I am trying to get the RPM of the engine (the left gauge) and optionally the vehicle current gear.

we are not try to get the speed of the car but the RPM , unfortunatly the RPM is not directly linked with the movement of a car and plus every car got different kind of engine and torque so your idea is not working

maybe it’s cause they don’t use all the version (i know nothing about game version so…) but from what i saw in the fivem code of dll is :

public float CurrentRPM
		{
			get
			{
				if (MemoryAddress == IntPtr.Zero)
				{
					return 0.0f;
				}

				int offset = Game.Version >= GameVersion.v1_0_372_2_Steam ? 0x7D4 : 0x7C4;
				offset = Game.Version > GameVersion.v1_0_877_1_Steam ? 0x7F4 : offset;

				return MemoryAccess.ReadFloat(MemoryAddress + offset);
			}
			set
			{
				if (MemoryAddress == IntPtr.Zero)
				{
					return;
				}

				int offset = Game.Version >= GameVersion.v1_0_372_2_Steam ? 0x7D4 : 0x7C4;
				offset = Game.Version > GameVersion.v1_0_877_1_Steam ? 0x7F4 : offset;

				MemoryAccess.WriteFloat(MemoryAddress + offset, value);
			}
		}

and from scripthook :

public float CurrentRPM
		{
			get
			{
				if (MemoryAddress == IntPtr.Zero)
				{
					return 0.0f;
				}

				int offset = Game.Version >= GameVersion.v1_0_372_2_Steam ? 0x7D4 : 0x7C4;
				offset = Game.Version >= GameVersion.v1_0_877_1_Steam ? 0x7F4 : offset;
				offset = Game.Version >= GameVersion.v1_0_944_2_Steam ? 0x814 : offset;
				offset = Game.Version >= GameVersion.v1_0_1103_2_Steam ? 0x824 : offset;

				return MemoryAccess.ReadFloat(MemoryAddress + offset);
			}
			set
			{
				if (MemoryAddress == IntPtr.Zero)
				{
					return;
				}

				int offset = Game.Version >= GameVersion.v1_0_372_2_Steam ? 0x7D4 : 0x7C4;
				offset = Game.Version >= GameVersion.v1_0_877_1_Steam ? 0x7F4 : offset;
				offset = Game.Version >= GameVersion.v1_0_944_2_Steam ? 0x814 : offset;
				offset = Game.Version >= GameVersion.v1_0_1103_2_Steam ? 0x824 : offset;

				MemoryAccess.WriteFloat(MemoryAddress + offset, value);
			}
}

is this two version out of date or it should be needed in the code ?

offset = Game.Version >= GameVersion.v1_0_944_2_Steam ? 0x814 : offset;
offset = Game.Version >= GameVersion.v1_0_1103_2_Steam ? 0x824 : offset;

As you can see in this commit the offsets were corrected for the game version FiveM uses.
In fact, Vehicle.CurrentRPM works just fine, as you can see in the following video. (It returns a float between 0 and 1)
https://streamable.com/c3y33

1 Like

a float between 0-1 omg i’m so stupid , i even didn’t check the return ,i execpted a return with the true value lol , thanks man , u make my day i’m gonna fix it directly :wink:

You made my day, I’m trying this tonight :smiley: Thank you !