Jump to content

"Timer" for each vehicle


Recommended Posts

Hello!

I would like to create a script in which your vehicle's tyre would burst randomly, so I can do things like you will have to change tyres, etc. but I don't know what would be the most efficient way to do this, since I will have to do it server side to sync it, I don't think setTimer is a good choice, therefore there would be lots of timers which is not really good I guess. Or is it okay to use timers? If so, how should I use them, when to create and kill them, etc. Any suggestions or help in connection with that? Has anybody made something similar like this?

Link to comment
  • Discord Moderators

You're right that it's a bad idea to have all the timers on the server side. Instead you place the timers client side, on the client who is driving the vehicle, and you trigger a server event to change the wheel states when it's time. One approach could be to use onClientVehicleDamage on the clientside to monitor for damage. This event has a parameter tyreID which shows what wheel specifically took damage. From there you could make it burst randomly or below a certain damage value. Another approach could be to monitor for how long the local player is driving the vehicle, and burst the tyres after a certain distance.

Link to comment

@Zango I like your second idea better, but I also like parts of the first one. I will try to mix these two, my idea is to create a timer after a certain distance, and then burst the tyres, the timer would have a random time generated by the script if the driver goes above the given distance, and then reset the distance counter after the tyre was burst, so the whole thing starts from the beginning with a newly generated timer with a random time. Thanks!

One more question, which is better in your opinion?

- to use the setTimer function

- to use onClientRender and getTickCount?

Right now I find the second one easier and better, but I don't know, I really want to prevent lags and fps drops.

Edited by Dzsozi
Link to comment
  • Discord Moderators

Unless it's absolutely necessary to recalculate something every frame, I don't recommend doing things onClientRender but rather in a timer and only draw and update things using onClientRender. You can do a lot of stuff every frame, and this script alone certainly wont impact performance, but with more and more scripts using that practice it eventually adds up and you get poor performance. 

I would use a timer with a few seconds interval or even more, and calculate the distance from the current position of the vehicle to the previous position. You could then store the distance in a table or you could save it to the vehicle's element data, so that if a new player becomes the driver, the tyre wear values are synchronised.

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