Calculate max velocity of a vehicle

All is in the question.

To introduce the problem, what i’m trying to achive is displaying the max speed in km/h of a TDM Car in a DLabel.

With the help someone gave me in the “Problems that don’t need their own thread”, it seams that vehicles don’t have any maximum velocity. The problem is that some vehicles are blocked to 50 Km/h and some other 100 km/h or even 200 km/h but how can i found this value by calculations ?

In the hope of a quick answer.

I can get the phys env speed using “physenv.GetPerformanceSettings()”, however it’s the world max velocity for objects…

You could read it from the vehicle script file for that vehicle, keep in mind that it is in mph there.

Yes but how ? Garry blocks us from accessing Addons directories, and then how to decode those script files, without using c++ dll ?

You use this extractor:

file.Read can easily read files from addons ( even in .gma )

[editline]13th February 2015[/editline]

The vehicle scripts are in plain .txt, you can either manually parse it or try to use KeyValuesToTable.

Do you know which key do i need to get ? Because i think i found a way to hack those scripts using lua, but i’m not sure.

Anyway, my possible hack will not be able to get multiple values at a time, so i need to be sure which key is what i’m searching for ?

Wait what? What is this “hack” you are using, why dont you just be a normal person and use file.Read to get the information you require. Just use KeyValuesToTable like Robotboy suggested, and if you don’t know what they value is that your looking for is take a second open up one of the vehicle scripts files and look at what the max value key is.

@TheEmp :
Please calm down… You need to know that i’m not a Lua Dev and not at all a Gmod Dev. I know just a bit about Source Engine. When i started to make a roleplay DarkRP server, I seen how terribe the roleplay experiment was. So i decided 3/4 days after the big launch, to delete everything and start from cratch creating my own GameMode, just because i had already touched 3D, 2D, OpenGL, DirectX. With my knowledge, i had (and i still have) many problems with this form of programmation due to the fact my famous types are no longer there, no longer ints, no longer floats, no longer glVertex, no longer matrices, so when i seen that, i was completely ejected. And at the end i took my courage in two hands and made all these libraries into some lua files to re implement many things that were just already there by some functions.
All of that just because i’m not adapted to use already made functions, i always use low level and no libs, only OpenGL or DirectX. So binary is good for me, and when i have not these low level things, i just go realy wrong…
In the hope i haven’t made any offence to you…

Now back to the topic.

KeyValuesToTable, what is this function ? Is this reading this format ?

So anyway i can do that with just string library. Or maybe using byte reading, but it would be a little bit more complicated.
I think i found what is the value i need, “MaxSpeed”. But in which units is this value ? Inches ? KPH ? MPH ?

KeyValuesToTable converts the .txt file to a handy lua table
The value is in MPH

Yes, the vehicle scripts use the KeyValues format so using that will turn it into a table. All you need to do is use PrintTable on the resulting table to find the key and sub-keys you need to go through to get the top speed, or just read the txt… It should be clear enough.

Thank you Acecool the problem is solved now. I can display vehicle speed in a label.

Just one more question with the process of reading scripts : Are scripts same client side and server side ?

If the client has the addon and you haven’t moved the vehicle scripts, the client should be able to open the txt file from the same location because of how GMod handles directories.

Basically, GMod uses a virtual directory system for addons, game-modes etc… so everything essentially uses the base garrysmod/ folder as a template for addons, etc… The files should be either in data/ folder somewhere or scripts/ depending how the addon is set up.

Worse case scenario, you can network the data to the client once ( just the max-speed value when they get into a vehicle; not the entire txt file ) so they can see it although typically a vehicle table should be set up in a shared way so client can know the name, etc…

The problem is that the client must have the max speeds before any vehicle spawn, due to the fact the car buy npc will require them in the huge car table (not the additional car table which is only for light poses, chest poses, max fuel, max health, smokes escapes and passengers).

In most cases, yes, but not necesarily. The client may not even have the vehicle script because they are only needed on the server.

Oh then sh**, i’ll need to send the values to the client. I think i can do something with the vc2_shared file… With an if block maybe…