Jump to content

how to get vehicle speed serverside?


Recommended Posts

i'm making a sistem where i need to get the player's vehicle speed server-side.

Entity::getSpeed() works only on client side.

Any way to do it? I thought about sending it constantly with an event from client to the server, but i'm afraid that some malicious values can be sent with cheats 


Edit: Found out, here is the function i wrote in case someone else needs it

function getVehSpeed(vehicle){
  let velocity = vehicle.velocity;
  return (Math.sqrt((velocity.x * velocity.x) + (velocity.y * velocity.y) + (velocity.z * velocity.z)) * 3.6);

it returns the speed in km/h, for other measurements you can calculate it easly

Edited by Vennox
  • Like 1
Link to comment
Share on other sites

not every speed, just some vehicles in special cases.

i have a farmer job where you have to drive around for 120 seconds at more than 25 km/h and there is a one second interval that checks every player that is doing that job, if his speed is > 25km/h then it decreases the time value (initial 120) with 1.


Link to comment
Share on other sites

There are multiple ways you can do this, some would be:

1. Do the speed calculations client side and return the value to the server, for each player that is doing the job? (In this case, you'd make a call to the client from the server, every second for every player that performs the 'farmer job')

2. Do the whole logic client side? From the server, you just trigger a client event, that starts the 120 seconds timer and continuously tracks player's speed? And when the timer is up, just trigger a server event? 

Not exactly sure what is your context, but if each player that does the job should have their own timer (and not a general timer for everyone, like a race) I'd suggest going with the second part.

I used a similar mechanic for driving license and went with the second solution, everything worked fine.


Edited by Tonytza
Link to comment
Share on other sites

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...