[Release] Car Stats - View car statistics with a simple command

I decided I’d do a bit of lua work so I coded up a simple command that sends stats about the car/vehicle you’re in to your chat.
Feedback is welcome and encouraged.

Displays:

  • Name (not spawn name) of the car
  • Max speed in MPH
  • Acceleration rate
  • Number of gears
  • Capacity

preview
Enjoy, everyone!
Usage: /carstats when you’re in a vehicle

carstats.zip (1.0 KB)

12 Likes

This is actually pretty cool! Nice release. :slight_smile:

Very unique…


+1

yes this is very unique and pretty neat! I will definitely put this in my upcoming community! This is useful info! Thanks Setro!

how to convert max speed to KMH?

1 Like

If you can code just a litle you will find out very easy :wink:

This looks very cool, definitely going to suggest this to my community. Let us know if you update it with more content!

Do you know that you are not able to get real maxspeed and gears?

What do you mean I’m not able to get the real max speed and gears? These are the natives for the vehicle, they’re not fake.

Sure. Replace the contents of the server.lua with this:

RegisterNetEvent('carstats');
AddEventHandler('carstats', function()
local ped = PlayerPedId()
	if IsPedInAnyVehicle(ped, false) then
		local veh = GetVehiclePedIsIn(ped, false)
		local model = GetEntityModel(veh, false)
		local hash = GetHashKey(model)
		TriggerEvent('chatMessage', "", {255, 0, 0}, "^3Name (not spawn name):^7 ".. GetDisplayNameFromVehicleModel(model))
		TriggerEvent('chatMessage', "", {255, 0, 0}, "^3Max speed (MPH):^7 ".. round(GetVehicleMaxSpeed(model) * 3.6,1))
		TriggerEvent('chatMessage', "", {255, 0, 0}, "^3Acceleration rate:^7 ".. round(GetVehicleModelAcceleration(model),1))
		TriggerEvent('chatMessage', "", {255, 0, 0}, "^3Number of gears:^7 ".. GetVehicleHighGear(veh))
		TriggerEvent('chatMessage', "", {255, 0, 0}, "^3Capacity:^7 ".. GetVehicleMaxNumberOfPassengers(veh) + 1)
	end
end)

--snippet borrowed from http://lua-users.org/wiki/SimpleRound
function round(num, numDecimalPlaces)
  local mult = 100^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end

I’m coding it based off of what the numbers I found on sources say. If it seems off let me know and I’ll look further.

1 Like

I don’t see a way to find that info out, sorry.

Thanks man!
Awesome Script!
+1

its all good


Great release!

Maybe in the future try adding the spawn name that way we can blacklist the vehicles we don’t know the spawn names too and are too lazy to look it up… lol…

Anyways, Great job!

Does this still work? I installed it, hopped in a car and typed /carstats but nothing appeared in the chat window. Any ideas?

+1 working fine :] Good job

Is the speed math off? seems lower on addon cars, says gtr goes 197 but it goes like 240

Maximum speed is affected by everything from acceleration to certain suspension settings in the handlings file, this simply pulls what the maximum top speed “should be” from fInitialDriveMaxFlatVel and setting this variable to a certain value does not guarantee the vehicle will reach this speed.

hmm its strange because it says all cars go slower than they actually do, do you know if there would be a way to pull the stat for trunk space from something like esx_trunk to put it in the stats?

looks good !