Jump to content

Getting vehicle RPM Help


Recommended Posts

Hello, I was thinking of making a tachometer which would show RPM of the car.. probably with slider.. but im not pretty sure how I could make it. I wanted to ask if I could make a code to read when the car is accelerating, or decelerating, or make it read the gears and the speed... maybe you could give me ideas/help me with it? thanks

Link to comment
  
local axeleration=0 
local lastSpeed=0 
local vehicle 
  
function getSpeed(veh) 
  local x,y,z=getElementVelocity(veh) 
  return (x^2+y^2+z^2)^0.5*161 
end 
  
function getAxeleration(veh) 
  if getElementType(veh)~="vehicle" then return end 
  vehicle=veh 
  return axeleration 
end 
  
setTimer(function() 
  local speed=getSpeed(vehicle) 
  axeleration=speed-lastSpeed 
  lastSpeed=speed 
end,1000,0) 
  
  

getAxeleration(veh) returns axeleration in km/h in last 1second.

Link to comment

yes it will be nice an RPM whit gears but its hard to make if you see the cars had a feedback trying to simulate the gear changeing ( else you can use the acceleration and set up on speeds like gear 1 0-20km/h if you got 20km it show gear 2 and RPM start again form 0 and increase again and you need to make it rewerse to decrease and start form 5000-6000 rpm down when the car is slowing down its just my opinion )

Link to comment

Hmm, It seems that the timer has problem...

Edit: I found the problem, getSpeed wasnt working properly, so i did it like new vehic = getPedOccupiedVehicle(getLocalPlayer()) and then getSpeed(vehic) and works now.. also i made it like math.floor(axeleration) so now its not as float, althought i dont know if its better like that...

anyway, i will work soon on it, and i will give you results.. if anyone has any idea about it, i would like to hear it!

Link to comment

hm i tryed that code you got 0 bk the axeleration is not incarse or discard if you delet in first line the

local axeleration=0 then it will return nil ( i think the script don't detect that the vehicle is moving ) (if you like my opinion that to use the speed and form speed the gears and ... then i will help you i am a beginer in lua :D but i have some experience in C++ pm me if you whant )

(sorry my english :mrgreen: )

Link to comment

Hmmm I got some problems... well, I made a debug system, it shows a message every time the acceleration changes. But here is the problem, the car when its close to top speed, the acceleration goes to minus, so, as i tested now with a speedometer, changed to rpm meter, it shows the rpm increases, and while im full accelerating, suddenly it shows that the car goes slower... so probably I need to do it somehow else, i just need some ideas...

Link to comment

use the speed of car not the acceleration

for rpm use this on every 30km change gear 0-30 30- 60 60-90 90-120 ....

and this for 0-30 km/h rpm

if speed <= 30  then 
gear = 1 
rp = speed 
rpm = rp * 250 
  

this for 60-90km/h

  
if speed >=60   
rp=speed-50 
rpm=rp*123 
  

this is for 120-150 km/h

  
if speed >= 120 
rp=speed-110 
rpm=rp*125 
  

if you give me a yahoo or skype id i will help you whit the left rpm if you calculate on 0-30km/h rpm start at 0 and gos up to 5000

on gear 2,3,4,5,6,7 its start on 1200 +/- rpm and gose up to 5000 +/- rpm

and use on 0-30 if..... and after whit elseif ex:

  
if speed <= 30  then 
gear = 1 
rp = speed 
rpm = rp * 250 
elseif speed >=30 ... 
  
elseif>=60 
  
and at final use a timer and then when you slow down its chek speed is <=30 not the check speed is >=30 not then check  speed is >=60  .... and need to work if not say me and i try to make in another way thx  
  

( if the script is ready pls upload it to comunity or send me i help you :D and i will keep helping you if you ask )

and at the final the script will return speed , gear ,rpm

Edited by Guest
Link to comment

I got skype:

Skype: djst3rios

Well, With acceleration also can work out, but i think your idea is much better, because as car is reaching top speed the its not accelerating that fast, so it will not work properly, and you need more calculations etc. But the problem is that I suck at maths, but if you could help me it would be really useful. Thanks for the idea also.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...