Quantcast

Jump to content

» «
Photo

Getting Vehicle Engine RPM

6 replies to this topic
ClareXoBearrx3R9
  • ClareXoBearrx3R9

    'su' isn't the f*cking same as 'sudo'.

  • Members
  • Joined: 13 Aug 2010
  • United-States

#1

Posted 16 January 2015 - 10:33 PM

Hello everyone,

 

Does anyone know of a method to get the engine RPM of a vehicle? I'd like to work on a tachometer but it seems that no natives exist for such a function. I'm a C and C++ programmer, so hopefully some combination of methods within the ScriptHook SDK that would work exist.

 

I looked around and found some GetVehicleRPM() in the .NET SDK that appears to access data from the memory but I'm not familiar with .NET.

 

Thanks in advance :)


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#2

Posted 17 January 2015 - 03:23 AM Edited by InfamousSabre, 17 January 2015 - 03:23 AM.

Looks like you'll need to access the data from memory then. Since the .Net ScriptHook does it, and its source is available, I'd check the .Net ScriptHook's source code.


ClareXoBearrx3R9
  • ClareXoBearrx3R9

    'su' isn't the f*cking same as 'sudo'.

  • Members
  • Joined: 13 Aug 2010
  • United-States

#3

Posted 17 January 2015 - 04:46 AM

Was trying to avoid having to do that but it seems that what's necessary. Thanks!


spadger
  • spadger

    Player Hater

  • Members
  • Joined: 28 Jun 2012

#4

Posted 19 January 2015 - 04:40 PM Edited by spadger, 19 January 2015 - 04:47 PM.

Hello everyone,

 

Does anyone know of a method to get the engine RPM of a vehicle? I'd like to work on a tachometer but it seems that no natives exist for such a function. I'm a C and C++ programmer, so hopefully some combination of methods within the ScriptHook SDK that would work exist.

 

I looked around and found some GetVehicleRPM() in the .NET SDK that appears to access data from the memory but I'm not familiar with .NET.

 

Thanks in advance :)

extern float GET_VEHICLE_ENGINE_REVS(int vehicle);

Works on new natives only, so PC version ;)

Here's what i use for a simple displayer using scocl to compile.

if ( DOES_VEHICLE_EXIST(G_MYVEH) )
{
	static float speed = 0.0f;
	static uint delay = 0;
	GET_GAME_TIMER(&gtimer);
	if ( delay < gtimer )
	{
		delay = gtimer + 333;
		GET_CAR_SPEED(G_MYVEH, &speed);
		speed *= 2.94f;
	}

	int revs = 0;
	float frevs = GET_VEHICLE_ENGINE_REVS(G_MYVEH);
	frevs *= 10.0f;
	revs = (int) frevs;

	register float x = 0.08f;
	register int i;
	for ( i = 0; i < revs; ++i )
	{
		if ( i > 8 ) SetFont( 255, 0, 0 );
		else if ( i > 6 ) SetFont( 255, 213, 0 );
		else SetFont( 0, 255, 0 );

		DISPLAY_TEXT_WITH_LITERAL_STRING(x, 0.68f, "STRING", ">");
		x += 0.008f;
	}

	SetFont( 33, 148, 219 );
	DISPLAY_TEXT_WITH_LITERAL_STRING(0.08f, 0.70f, "STRING", "Gear:");
	SetFont( 219, 104, 33 );
	DISPLAY_TEXT_WITH_NUMBER(0.135f, 0.70f, "NUMBER", GET_VEHICLE_GEAR(G_MYVEH));

	SetFont( 33, 148, 219 );
	DISPLAY_TEXT_WITH_LITERAL_STRING(0.08f, 0.72f, "STRING", "Mph:");
	SetFont( 219, 104, 33 );
	DISPLAY_TEXT_WITH_NUMBER(0.135f, 0.72f, "NUMBER", (int) speed);

	DRAW_CURVED_WINDOW(0.0752f, 0.679f, 0.089f, 0.0645f, 255);
}

NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Best Script or Plugin 2016 [SkyGfx] [Contribution]
    Best Conversion 2014 [ViIV for GTANY]
    Most Knowledgeable [Tech] 2013
    Best Map 2013 [ViceCityStories PC Edition]
    Contribution Award [Mods]

#5

Posted 19 January 2015 - 05:15 PM

Works on new natives only, so PC version ;)

?!

it's a DLC2 function, should work fine on consoles if you just use the non-altered hash (i.e. the reproducible one) for it, though they might only be enabled when setup2 indicates episode 2
  • leftas likes this

ClareXoBearrx3R9
  • ClareXoBearrx3R9

    'su' isn't the f*cking same as 'sudo'.

  • Members
  • Joined: 13 Aug 2010
  • United-States

#6

Posted 19 January 2015 - 07:22 PM

Hello everyone,
 
Does anyone know of a method to get the engine RPM of a vehicle? I'd like to work on a tachometer but it seems that no natives exist for such a function. I'm a C and C++ programmer, so hopefully some combination of methods within the ScriptHook SDK that would work exist.
 
I looked around and found some GetVehicleRPM() in the .NET SDK that appears to access data from the memory but I'm not familiar with .NET.
 
Thanks in advance :)


extern float GET_VEHICLE_ENGINE_REVS(int vehicle);
Works on new natives only, so PC version ;)
Here's what i use for a simple displayer using scocl to compile.
if ( DOES_VEHICLE_EXIST(G_MYVEH) )
{
	static float speed = 0.0f;
	static uint delay = 0;
	GET_GAME_TIMER(&gtimer);
	if ( delay < gtimer )
	{
		delay = gtimer + 333;
		GET_CAR_SPEED(G_MYVEH, &speed);
		speed *= 2.94f;
	}

	int revs = 0;
	float frevs = GET_VEHICLE_ENGINE_REVS(G_MYVEH);
	frevs *= 10.0f;
	revs = (int) frevs;

	register float x = 0.08f;
	register int i;
	for ( i = 0; i < revs; ++i )
	{
		if ( i > 8 ) SetFont( 255, 0, 0 );
		else if ( i > 6 ) SetFont( 255, 213, 0 );
		else SetFont( 0, 255, 0 );

		DISPLAY_TEXT_WITH_LITERAL_STRING(x, 0.68f, "STRING", ">");
		x += 0.008f;
	}

	SetFont( 33, 148, 219 );
	DISPLAY_TEXT_WITH_LITERAL_STRING(0.08f, 0.70f, "STRING", "Gear:");
	SetFont( 219, 104, 33 );
	DISPLAY_TEXT_WITH_NUMBER(0.135f, 0.70f, "NUMBER", GET_VEHICLE_GEAR(G_MYVEH));

	SetFont( 33, 148, 219 );
	DISPLAY_TEXT_WITH_LITERAL_STRING(0.08f, 0.72f, "STRING", "Mph:");
	SetFont( 219, 104, 33 );
	DISPLAY_TEXT_WITH_NUMBER(0.135f, 0.72f, "NUMBER", (int) speed);

	DRAW_CURVED_WINDOW(0.0752f, 0.679f, 0.089f, 0.0645f, 255);
}


Wow - thanks!!! I'll definitely give that a try! :D

On a sidenote, I did find that native previously but was disappointed to find that it was only in TBoGT. Regardless, I'll give it a shot; again!

NorthHustler
  • NorthHustler

    Money Over B*tches

  • Members
  • Joined: 21 Nov 2017
  • United-States

#7

Posted 09 December 2017 - 09:13 PM

Er, what value would GET_VEHICLE_ENGINE_REVS output, if the car revs are, say, 2000? Is there a Rockstar version of the revs? I'm creating a script, and I was going to use if (VehicleRevs < 2000) etc. but... Would the revs be that high? Would it output just 2?

 

Any help would be greatly appreciated. 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users